relative / turboactivate-emulator

Emulator for wyDay's LimeLM TurboActivate library (drop-in replacement)
14 stars 2 forks source link

log_write makes use of inaccessible pointer to a c-string #4

Closed Firedan1176 closed 1 year ago

Firedan1176 commented 1 year ago

The function log_write() uses a lambda function to concatenate a filename into a temporary std::string, and returns a pointer to a null-terminated c string. However the scope is lost immediately on the return and the returned pointer is no longer valid, resulting in undefined behavior:

https://github.com/relative/turboactivate-emulator/blob/41837acc161d649e1e0d982d107f829e62cbd0cf/src/functions.cpp#L73-L81

The call to .c_str() should be moved to the constructor of std::ofstream below:

std::ofstream file(log_filename.c_str(), ...);

relative commented 1 year ago

thank you, merged your pr