Game Development Community

Beta3: Tile Editor stack corruption

by Cary Brisebois · in Torque Game Builder · 05/18/2006 (3:34 pm) · 2 replies

In t2dVector.cc:

//-----------------------------------------------------------------------------
// Normalise Rectangle (two 2D Vectors) with relation to each other.
//-----------------------------------------------------------------------------
ConsoleFunction( t2dRectNormalise, const char*, 3, 3, "(t2dVector v1$, t2dVector v2$) - Returns normalise rectangle of v1 and v2.")
{
// Check Parameters.
if ( t2dSceneObject::getStringElementCount(argv[1]) < 2 || t2dSceneObject::getStringElementCount(argv[2]) < 2 )
{
Con::warnf("t2dRectNormalise() - Invalid number of parameters!");
return NULL;
}

// Input Vectors.
t2dVector v1(0,0), v2(0,0);
// Scan-in vectors.
dSscanf(argv[1],"%f %f", &v1.mX, &v1.mY);
dSscanf(argv[2],"%f %f", &v2.mX, &v2.mY);
// Do Vector Operation.
t2dVector topLeft( (v1.mX <= v2.mX) ? v1.mX : v2.mX, (v1.mY <= v2.mY) ? v1.mY : v2.mY );
t2dVector bottomRight( (v1.mX > v2.mX) ? v1.mX : v2.mX, (v1.mY > v2.mY) ? v1.mY : v2.mY );

// Create Returnable Buffer.
char* pBuffer = Con::getReturnBuffer(32);
// Format Buffer.
dSprintf(pBuffer, 32, "%f %f %f %f", topLeft.mX, topLeft.mY, bottomRight.mX, bottomRight.mY);
// Return Velocity.
return pBuffer;
}

The size of the buffer is 32, but in the case I encountered the number of bytes written was 39 - "24.453125 19.686163 24.453125 19.686163"

#1
05/18/2006 (9:42 pm)
Yeah - is it missing a precision on this statement? I guess it could still overrun if the values are large enough. Donnow. Melv will know :-)

dSprintf(pBuffer, 32, "%f %f %f %f", topLeft.mX, topLeft.mY, bottomRight.mX, bottomRight.mY);
change to ?
dSprintf(pBuffer, 32, "%.4f %.4f %.4f %.4f", topLeft.mX, topLeft.mY, bottomRight.mX, bottomRight.mY);
#2
05/19/2006 (8:26 am)
I'd make the buffer bigger and keep the precision. 64 bytes is fine, IMO.