Untitled

posted in DruinkJournal
Published October 27, 2008
Advertisement
I've been tasked with some tools work at work, and I've come across a few juicy code snippets I'd like to share.

There's so many things wrong with these that I can't even be bothered listing what they are.

First, a simple memory leak:
for(...){   blUtilFindFilesResult  * textureBatchFile = new blUtilFindFilesResult( source , target );   textureDirSet.insert( *textureBatchFile );}


Next, an "interesting" way to skip over the "." and ".." directories returned by FindNextFile:
hFindFile = FindFirstFile(inputDirFilename.c_str(), &fileData);char * test;if (!(hFindFile == INVALID_HANDLE_VALUE)) {   test = fileData.cFileName;   FindNextFile( hFindFile, &fileData);   while ( FindNextFile( hFindFile, &fileData) != 0)    {	       test =fileData.cFileName ;      inputFileList.append(" ");      inputFileList.append(test);   }}


And finally:
static char * getDirName( const char * _pInputName, char * _pDirName ){		size_t fileNameLength = strlen(_pInputName);	char * filename = ( char* )malloc(fileNameLength+10);	strcpy( filename , _pInputName);	int dirLength;	for( int i = fileNameLength; i > 0; i-- )	{		if( filename == '\\' )		{			 filename = '*';<br>			  filename = '\<span class="cpp-number">0</span>';<br>			  dirLength = i+<span class="cpp-number">1</span>;<br>			<span class="cpp-keyword">break</span>;<br>		}<br>	}<br>	_pDirName = (<span class="cpp-keyword">char</span> * )malloc( dirLength + <span class="cpp-number">20</span> );<br>	strcpy( _pDirName , filename);<br>	_pDirName[dirLength] ='\<span class="cpp-number">0</span>';<br><br>	<span class="cpp-keyword">return</span> _pDirName;<br><br>}<br><br></pre></div><!–ENDSCRIPT–>Oh god.<br><br>Back to getting rid of the crap…<div>


</div>
Previous Entry Untitled
Next Entry Untitled
0 likes 2 comments

Comments

ukdeveloper
If you find something exceptionally disgusting, see if you can get it submitted to The Daily WTF :P
October 27, 2008 09:53 AM
Evil Steve
Quote:Original post by ukdeveloper
If you find something exceptionally disgusting, see if you can get it submitted to The Daily WTF :P
Already done [wink]
October 27, 2008 11:55 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement