From: karim on
hi ,
the following code has been successfully compiled and executed in vc6.0,and
it has also compiled in vc8.0 but causing problem runtime.
can anybody help me please.........
pNext is of type LPTSTR;
BYTE bVal = 0;
if(_stscanf(pNext,TEXT("%x "), &bVal)==1)

error: Runtime check Failure #2 stack around the variable 'bVal' was
corrupted.

-karimulla.
From: ajk on
On Fri, 29 Jun 2007 03:16:02 -0700, karim
<karim(a)discussions.microsoft.com> wrote:

>hi ,
>the following code has been successfully compiled and executed in vc6.0,and
>it has also compiled in vc8.0 but causing problem runtime.
>can anybody help me please.........
>pNext is of type LPTSTR;
>BYTE bVal = 0;
> if(_stscanf(pNext,TEXT("%x "), &bVal)==1)
>
>error: Runtime check Failure #2 stack around the variable 'bVal' was
>corrupted.
>
>-karimulla.

try coding that using fgets() instead and in the future avoid any
scanf as the plague. scanf is a function that shouldn't be used in
modern programs, there are so many other methods to parse a string
which are much safer.



From: SvenC on
Hi,

"karim" <karim(a)discussions.microsoft.com> wrote in message
news:3C04F758-6C5D-4865-9536-18F5A235CEF0(a)microsoft.com...
> hi ,
> the following code has been successfully compiled and executed in
> vc6.0,and
> it has also compiled in vc8.0 but causing problem runtime.
> can anybody help me please.........
> pNext is of type LPTSTR;
> BYTE bVal = 0;
> if(_stscanf(pNext,TEXT("%x "), &bVal)==1)

%x is asking for 32 bit and you are providing 8 bit (a BYTE), so not only
bVal is written to but memory directly around also.

use this:

BYTE bVal = 0;
int i;
if((_stscanf(pNext,TEXT("%x "), &i) == 1)
bVal = (BYTE)i;

--
SvenC

From: karim on
hi,


"ajk" wrote:

> On Fri, 29 Jun 2007 03:16:02 -0700, karim
> <karim(a)discussions.microsoft.com> wrote:
>
> >hi ,
> >the following code has been successfully compiled and executed in vc6.0,and
> >it has also compiled in vc8.0 but causing problem runtime.
> >can anybody help me please.........
> >pNext is of type LPTSTR;
> >BYTE bVal = 0;
> > if(_stscanf(pNext,TEXT("%x "), &bVal)==1)
> >
> >error: Runtime check Failure #2 stack around the variable 'bVal' was
> >corrupted.
> >
> >-karimulla.
>
> try coding that using fgets() instead and in the future avoid any
> scanf as the plague. scanf is a function that shouldn't be used in
> modern programs, there are so many other methods to parse a string
> which are much safer.
the issuue here is that i am using a BYTE pointer and the method you
suggested take FILE * and right now i don't have option to change it to File
* as it was used in many places in the project. can you suggest way to
correct it using the same method.

-karimulla.
>
>
From: ajk on
On Fri, 29 Jun 2007 06:08:03 -0700, karim
<karim(a)discussions.microsoft.com> wrote:

>the issuue here is that i am using a BYTE pointer and the method you
>suggested take FILE * and right now i don't have option to change it to File
>* as it was used in many places in the project. can you suggest way to
>correct it using the same method.
>
>-karimulla.

maybe you can show us how _stnscanf looks like, cause it is not a
standard function that I know of.