[SDL] SDL mix_LoadMus - Needs a const?

Jonathan Dearborn grimfang4 at gmail.com
Sat Mar 30 12:30:19 PDT 2013


There's a lot of code missing that would be helpful.  What jumps out to me
is the comparison "==" with a string literal.  In C, use (strcmp(str1,
str2) == 0).  If you are using C++, then definitely use C++. ;)

Jonny D


On Sat, Mar 30, 2013 at 3:07 PM, Nathaniel J Fries <nfries88 at yahoo.com>wrote:

> **
> if the the string zeile is modified between when you set Current.music and
> when Mix_LoadMUS is called (which it looks like it would be, based on the
> fact that you're loading it with getline in a loop), its quite possible
> that the memory used to hold its C string has either been modified or been
> freed, which would make Current.music point either to invalid memory (your
> program should crash) or to the wrong memory contents (loading the file
> would fail).
>
> Pro-tip: If you're using C++, just use std::string and std::stringstream
> for all string manipulation. What you're doing can be done quite easily
> with std::string::find and std::string::substr. Dealing with strings with
> the C functions is tedious, and if you're not familiar with low-level
> memory operations, often results in unexpected behavior. Retaining a
> pointer or reference to anything on allocated on the stack is also a bad
> idea.
>
>
> ------------------------------
>
> Nate Fries
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20130330/4fb06975/attachment-0009.htm>


More information about the SDL mailing list