Game Development Community

Crash bug on a warning print in explosion.cpp

by Tim Newell · in Torque 3D Professional · 10/05/2012 (12:37 pm) · 3 replies

I don't have stuff setup for MIT torque to post this on github but wanted to document it here.

In the Engine function
DefineEngineFunction(calcExplosionCoverage, F32, (Point3F pos, S32 id, U32 covMask),(Point3F(0.0f,0.0f,0.0f), NULL, NULL),

The line:
Con::warnf(ConsoleLogEntry::General, "calcExplosionCoverage: couldn't find object: %s", id);

should be %d not %s. %s causes the engine to crash.


#1
02/13/2013 (2:01 am)
obviously that is a coding error.
but crash only for this little typo!!!!!!

there could be many more typo like this.
rather than finding out those better , if we can make the compiler report a error or warning for this type of type.
can we?
#2
02/13/2013 (6:31 am)
It should not crash. This exact semantic works fine in other places and it should just print the number as a string. Though if you're hitting that you're already having an issue....

Good catch.
#3
02/27/2013 (3:33 pm)
This has been fixed in Pull Request 184 on the development branch. Here is the closed issue: github.com/GarageGames/Torque3D/issues/82

@ahsan and Richard:
The problem is that the underlying sprintf() (or more accurately, _vsnprintf()) used by Con::warnf() was treating an integer as a char* string. There is no automatic conversion in C++. This means that the system will keep reading memory until it reaches a NULL character, likely causing it to traverse memory it shouldn't have. This ends in a crash.

This isn't specific to T3D but is a problem with using these types of C++ functions.

- Dave