• Advertisement
Sign in to follow this  

Help!

This topic is 3033 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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<Length; i++) strcstring = str.GetAt(i); DataLength = Length / 2; for (i = 0; i<DataLength; i++) { cstr[0] = strcstring[2*i]; cstr[1] = strcstring[2*i+1]; sscanf( cstr, "%02x", &hexval ); ucBuffer=hexval; } *ulBufferLen = DataLength; }

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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<Length; i++)
        strcstring = str.GetAt(i);

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

    for ( int i = 0; i<DataLength; 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<UCHAR>(hexval);
    }

    *ulBufferLen = DataLength;
}


  • Sign in to follow this  

    • Advertisement