Skip to main content
GameDev.net gamedev.net
🔒 Locked

Help!

Started by Adrian99420 Nov 3, 2009 at 9:38 PM 3 replies 1.1k views
Original Post
Adrian99420
Adrian99420
Hi all, urgent help needed. I faced error of "stack around the variable "hexxal" was corrupted. Any suggestion? UCHAR ucMifareKey[6] = {0}; ULONG ulMifareKeyLen = 0; m_strAuthentKey = "FFFFFFFFFFFF"; CStringToUchar(m_strAuthentKey,ucMifareKey,&ulMifareKeyLen); void CContactlessDemoVCDlg::CStringToUchar(CString str, UCHAR *ucBuffer, ULONG *ulBufferLen) { int Length = 0; int DataLength = 0; char cstr[] =""; char strcstring[512] =""; byte hexval=0x00; int i = 0; Length = str.GetLength(); for (i = 0; i = str.GetAt(i); DataLength = Length / 2; for (i = 0; i=hexval; } *ulBufferLen = DataLength; }
alvaro
alvaro
sscanf with a format specifier of "%02x" will read in an int, but you gave it a pointer to a single byte. You can try making hexval an int. If what you are reading is in range, that should work fine.
Adrian99420
Adrian99420
Hi alvaro,

Thanks for the reply, but when i changed the hexval to int, here comes the error of "Stack around the variable 'cstr' was corrupted". Any advice?
fastcall22
fastcall22
UCHAR ucMifareKey[6] = {0};
ULONG ulMifareKeyLen = 0;
m_strAuthentKey = "FFFFFFFFFFFF";
CStringToUchar(m_strAuthentKey,ucMifareKey,&ulMifareKeyLen);

void CContactlessDemoVCDlg::CStringToUchar( const CString& str, UCHAR *ucBuffer, ULONG *ulBufferLen)
{
int Length = 0;
int DataLength = 0;
char cstr[3] = {}; ""; // Previous code allocates only one char for cstr
char strcstring[512] =""; // Not needed
byte int hexval=0; 0x00;
int i = 0; // Moved

Length = str.GetLength();
for (i = 0; i
strcstring = str.GetAt(i);

assert( str.GetLength() % 2 == 0 );
DataLength = Length str.GetLength() / 2;

for ( int i = 0; i {
cstr[0] = str[2*i]; strcstring[2*i]; // CString provides an operator[]
cstr[1] = str[2*i+1]; strcstring[2*i+1]; // Buffer overrun here, if str.GetLength() is odd
sscanf( cstr, "%02x", &hexval );
ucBuffer= static_cast(hexval);
}

*ulBufferLen = DataLength;
}


[Edited by - _fastcall on November 4, 2009 12:43:25 AM]
Adrian99420
Adrian99420
Hi all,

I got the things work. Thanks for the help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.