Game Development Community

TGEA 1.7.1 recurseDumpPath buf too small

by Michael Gingerich · in Torque Game Engine Advanced · 10/10/2008 (5:25 am) · 1 replies

RecurseDumpPath buf is too small if you have a short path which contains a long filename.


This is the buffer:

TempAlloc< char > buf( lenFullPath + dStrlen( pattern ) + 2 );

This is the line where the buf could be too small:

convertUTF16toUTF8( findData.cFileName, buf, buf.size );

Example path: "C:\temp", pattern "*"

If C:\temp contained a filename with more than 10 characters in length, buf would not be large enough to convert it.

#1
11/06/2008 (5:13 am)
My bad. Reusing 'buf' sort of is an optimization but then 'dStrlen( pattern )' is nonsense.

Replace with:

TempAlloc< char > fullPath( dStrlen( path ) * 3 + MAX_PATH * 3 + 1 );
   Platform::makeFullPathName( path, fullPath, fullPath.size );

   // [rene, 04/05/2008] Had some weird crashes with dSprintf.  That's why the complicated
   //    manual concatenation is here.

   U32 lenFullPath = dStrlen( fullPath );
   TempAlloc< char > buf( lenFullPath + MAX_PATH * 3 + 2 );

Should add plenty of headroom under normal circumstances.