I tried to convert a hex-encoded string into a const char* buffer containing the decoded string.
For that I have a function (string hex_decode(string hex_input)
) that takes the string and decodes it.
After testing the function by itself a couple of times, I tried the following call:
const char* hex_decoded_c_str = hex_decode(input).c_str();
and saw that it returned complete gibberish! In an effort to debug the problem, I broke it up into two statements, like so:
string hex_decoded_string = hex_decode(input);
const char* hex_decoded_c_str = hex_decoded_string.c_str();
This time it worked perfectly!
I am so confused, does anyone know what could cause something like this?