Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Help!
Post New Topic  Post Reply 
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[i] = 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[i]=hexval;

}

*ulBufferLen = DataLength;

}



 User Rating: 982   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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.

 User Rating: 1555   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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?

 User Rating: 982   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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[i] = 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[i]= static_cast<UCHAR>(hexval);
    }

    *ulBufferLen = DataLength;
}


 User Rating: 1303   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Hi all,

I got the things work. Thanks for the help.

 User Rating: 982   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: