Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-Time Check Failure #2 - Stack around the variable 'cz' was corrupt 1

Status
Not open for further replies.

d00ape

Programmer
Apr 2, 2003
171
SE
What my this runtime error mean? Or what could it mean…

I had a working app. Compiled in VS 6.0 but now when I compile it in VS .NET this error happens.
 
could you please post the lines where you get this error?

Ion Filipski
1c.bmp
 
float x, y, z;
VARIANT Point;
VariantInit( &Point );
Point.vt = VT_ARRAY;

// m_pEngine is some kind of COM-object
HRESULT res2 = m_pEngine->get_TouchPoint( &Point );

char cx[5] = {'\0'};
char cy[5] = {'\0'};
char cz[5] = {'\0'};

tagSAFEARRAY *pArr = Point.parray;
float *f = (float*)pArr->pvData;

f++;
x = *f;
sprintf( cx, "%.3f", *f );
f++; f++;
z = *f;
sprintf( cz, "%.3f", *f );
f++; f++; f++;
y = *f;
sprintf( cy, "%.3f", *f );

// Already breaked...
 
it means you have allocated too few characters.
Look, the minimal %.3f means:
first character: one digit 1+
second character: . 1+
next three characters: decimals 3
as you can see there are already five characters. The sixth is '\0' and also will be put by the function sprintf. So after filling cx, the next character is taken from cz. It means the stack around cz is corruped. So, you should allocate more than five characters. I advise you to put at least 16 characters for each variable:

char cx[16] = {'\0'};
char cy[16] = {'\0'};
char cz[16] = {'\0'};
......


Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top