A
char
is just that, a character. A
single character.
conversely, when things take a
char*
as a parameter (in this case, itoa), they usually want an
array of characters to form a string.
What's happening is itoa is trying to write
several characters to chTemp (since it's pointed to by chPoint), but chTemp is only 1 char long, so the other data is spilling over and corrupting the stack.
The way to solve this would be to make chTemp a buffer, instead of a single char:
1 2 3 4 5 6 7 8 9
|
char chTemp[64]; // now it can hold 64 characters (hopefully that's enough)
//char* chPoint = chTemp; // this is superfluous...
// you don't need chPoint at all, you can just use chTemp
//...
itoa(protocol.get_integer_value(18),chTemp,10); // now chTemp is large enough to hold the whole string
// you're giving it. So no more buffer overflow. (hopefully, anyway, with these kinds of functions there's no way to
// know for sure, which is why they should be avoided)
| |
An alternative and much safer way is to use stringstreams. Then it's virtually impossible to overflow your buffer:
1 2 3 4 5 6
|
stringstream str;
//...
str << protocol.get_integer_value(18);
RegSetValueEx(configKey,"ConfRoom",NULL,REG_SZ,(const BYTE *)str.str().c_str(),dwSize);
| |
You might also have issues involving the dwSize member, but I really don't have a clue as I'm not familiar at all with this registry nonsense.