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:
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 ofstd::ofstream
below:std::ofstream file(log_filename.c_str(), ...);