Here is the code which converts a hex string to byte array, it works fine but when the loop goes end and the complier reaches to the end of function it throws this error:
“Stack around the variable ‘uChar’ was corrupted”
void Cfsp::stringToHex(unsigned char hexArray[], LPCTSTR string)
{
int stringLength=strlen(string);
int j=0;
unsigned char uChar = 0;
for (int x = 0; x < stringLength; x+=2)
{
sscanf_s(&string[x], "%02x", &uChar);
hexArray[j] = uChar;
j++;
}
}
Here is where I initiate the array and call the function.
unsigned char Key[16];
stringToHex( Key,"2f145a8b11d33217");
I know when stringToHex would convert the given string (16 chars length) to byte array it only fills 8 Bytes(as char). I just wanted to make a reserved area in the buffer.
The reason you get corruption is because you send
sscanf_sanunsigned char *where it expectsint *