[SDL] SDL mix_LoadMus - Needs a const?

Nathaniel J Fries nfries88 at yahoo.com
Sat Mar 30 12:07:45 PDT 2013

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20130330/0f423908/attachment-0009.htm>

More information about the SDL mailing list