Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    557
  • comments
    1237
  • views
    422924

Untitled

Sign in to follow this  
Evil Steve

126 views

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[i +1] = '*';
filename[i +2] = '\0';
dirLength = i+1;
break;
}
}
_pDirName = (char * )malloc( dirLength + 20 );
strcpy( _pDirName , filename);
_pDirName[dirLength] ='\0';

return _pDirName;

}

Oh god.

Back to getting rid of the crap...
Sign in to follow this  


2 Comments


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!