Skip to content

Commit dcec451

Browse files
committed
refactor: add explicit comparison to strcmp/stricmp results (bugprone-suspicious-string-compare)
1 parent e6c28a4 commit dcec451

File tree

11 files changed

+39
-39
lines changed

11 files changed

+39
-39
lines changed

Core/GameEngine/Source/GameNetwork/GameSpy/Thread/PeerThread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,7 @@ void PeerThreadClass::handleQMMatch(PEER peer, Int mapIndex, Int seed,
18421842
Int i=0;
18431843
for (; i<MAX_SLOTS; ++i)
18441844
{
1845-
if (playerName[i] && stricmp(playerName[i], m_loginName.c_str()))
1845+
if (playerName[i] && stricmp(playerName[i], m_loginName.c_str()) != 0)
18461846
{
18471847
peerMessagePlayer( peer, playerName[i], "We're matched!", NormalMessage );
18481848
}
@@ -2845,9 +2845,9 @@ static void listingGamesCallback(PEER peer, PEERBool success, const char * name,
28452845
DEBUG_LOG(("Game name is '%s'", name));
28462846
const char *newname = SBServerGetStringValue(server, "gamename", (char *)name);
28472847
#if RTS_GENERALS
2848-
if (strcmp(newname, "ccgenerals"))
2848+
if (strcmp(newname, "ccgenerals") != 0)
28492849
#elif RTS_ZEROHOUR
2850-
if (strcmp(newname, "ccgenzh"))
2850+
if (strcmp(newname, "ccgenzh") != 0)
28512851
#endif
28522852
name = newname;
28532853
DEBUG_LOG(("Game name is now '%s'", name));

Core/GameEngineDevice/Source/StdDevice/Common/StdLocalFileSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void StdLocalFileSystem::getFileListInDirectory(const AsciiString& currentDirect
241241
while (!done) {
242242
std::string filenameStr = iter->path().filename().string();
243243
if (!iter->is_directory() && iter->path().extension() == searchExt &&
244-
(strcmp(filenameStr.c_str(), ".") && strcmp(filenameStr.c_str(), ".."))) {
244+
(strcmp(filenameStr.c_str(), ".") != 0 && strcmp(filenameStr.c_str(), ".."))) {
245245
// if we haven't already, add this filename to the list.
246246
// a stl set should only allow one copy of each filename
247247
AsciiString newFilename = iter->path().string().c_str();
@@ -268,7 +268,7 @@ void StdLocalFileSystem::getFileListInDirectory(const AsciiString& currentDirect
268268
while (!done) {
269269
std::string filenameStr = iter->path().filename().string();
270270
if(iter->is_directory() &&
271-
(strcmp(filenameStr.c_str(), ".") && strcmp(filenameStr.c_str(), ".."))) {
271+
(strcmp(filenameStr.c_str(), ".") != 0 && strcmp(filenameStr.c_str(), ".."))) {
272272
AsciiString tempsearchstr(filenameStr.c_str());
273273

274274
// recursively add files in subdirectories if required.

Core/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void Win32LocalFileSystem::getFileListInDirectory(const AsciiString& currentDire
139139

140140
while (!done) {
141141
if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
142-
(strcmp(findData.cFileName, ".") && strcmp(findData.cFileName, ".."))) {
142+
(strcmp(findData.cFileName, ".") != 0 && strcmp(findData.cFileName, ".."))) {
143143
// if we haven't already, add this filename to the list.
144144
// a stl set should only allow one copy of each filename
145145
AsciiString newFilename;
@@ -165,7 +165,7 @@ void Win32LocalFileSystem::getFileListInDirectory(const AsciiString& currentDire
165165

166166
while (!done) {
167167
if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
168-
(strcmp(findData.cFileName, ".") && strcmp(findData.cFileName, ".."))) {
168+
(strcmp(findData.cFileName, ".") != 0 && strcmp(findData.cFileName, ".."))) {
169169

170170
AsciiString tempsearchstr;
171171
tempsearchstr.concat(currentDirectory);

Core/Libraries/Source/WWVegas/WWDownload/Download.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ HRESULT CDownload::DownloadFile(LPCSTR server, LPCSTR username, LPCSTR password,
4747
// If we're still connected, make sure we're on the right server
4848
if (m_Status == DOWNLOADSTATUS_FINDINGFILE)
4949
{
50-
if ((strcmp(m_Server, server)) || (strcmp(m_Login, username)))
50+
if ((strcmp(m_Server, server) != 0) || (strcmp(m_Login, username)))
5151
{
5252
// Damn, a server switch. Close conn & fix state
5353
m_Ftp->DisconnectFromServer();

Core/Libraries/Source/WWVegas/WWLib/ini.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ bool INIClass::Put_String(char const * section, char const * entry, char const *
16371637
*/
16381638
INIEntry * entryptr = secptr->Find_Entry(entry);
16391639
if (entryptr != NULL) {
1640-
if (strcmp(entryptr->Entry, entry)) {
1640+
if (strcmp(entryptr->Entry, entry) != 0) {
16411641
DuplicateCRCError("INIClass::Put_String", section, entry);
16421642
} else {
16431643
#if 0

Core/Libraries/Source/debug/debug_debug.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ Debug& Debug::LogBegin(const char *fileOrGroup)
526526
// we're doing all this extra work so that DLOGs can be spread across
527527
// multiple calls
528528
if (Instance.curType==DebugIOInterface::StringType::Log&&
529-
strcmp(Instance.curSource,Instance.curFrameEntry->fileOrGroup))
529+
strcmp(Instance.curSource,Instance.curFrameEntry->fileOrGroup) != 0)
530530
Instance.FlushOutput();
531531

532532
if (Instance.curType!=DebugIOInterface::StringType::Log)
@@ -1563,18 +1563,18 @@ void Debug::ExecCommand(const char *cmdstart, const char *cmdend)
15631563
// search for a matching command handler
15641564
for (CmdInterfaceListEntry *cur=firstCmdGroup;cur;cur=cur->next)
15651565
{
1566-
if (strcmp(curCommandGroup,cur->group))
1566+
if (strcmp(curCommandGroup,cur->group) != 0)
15671567
continue;
15681568

15691569
bool doneCommand=cur->cmdif->Execute(*this,p,mode,numParts-1,parts+1);
1570-
if (doneCommand&&(strcmp(p,"help")||numParts>1))
1570+
if (doneCommand&&(strcmp(p,"help") != 0||numParts>1))
15711571
break;
15721572
}
15731573

15741574
// display error message if command not found, break away
15751575
if (!cur&&mode==DebugCmdInterface::CommandMode::Normal)
15761576
{
1577-
if (strcmp(p,"help"))
1577+
if (strcmp(p,"help") != 0)
15781578
operator<<("Unknown command");
15791579
else if (numParts>1)
15801580
operator<<("Unknown command, help not available");

Core/Tools/ImagePacker/Source/ImagePacker.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ void ImagePacker::addImagesInDirectory( char *dir )
385385

386386
// if this is a file count it
387387
if( !(item.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
388-
strcmp( item.cFileName, "." ) &&
389-
strcmp( item.cFileName, ".." ) )
388+
strcmp( item.cFileName, "." ) != 0 &&
389+
strcmp( item.cFileName, ".." ) != 0 )
390390
{
391391

392392
len = strlen( item.cFileName );
@@ -410,8 +410,8 @@ void ImagePacker::addImagesInDirectory( char *dir )
410410

411411
// if this is a file count it
412412
if( !(item.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
413-
strcmp( item.cFileName, "." ) &&
414-
strcmp( item.cFileName, ".." ) )
413+
strcmp( item.cFileName, "." ) != 0 &&
414+
strcmp( item.cFileName, ".." ) != 0 )
415415
{
416416

417417
len = strlen( item.cFileName );
@@ -473,8 +473,8 @@ Bool ImagePacker::checkOutputDirectory( void )
473473

474474
// if this is a file count it
475475
if( !(item.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
476-
strcmp( item.cFileName, "." ) &&
477-
strcmp( item.cFileName, ".." ) )
476+
strcmp( item.cFileName, "." ) != 0 &&
477+
strcmp( item.cFileName, ".." ) != 0 )
478478
fileCount++;
479479

480480
// find the rest of the files
@@ -483,8 +483,8 @@ Bool ImagePacker::checkOutputDirectory( void )
483483

484484
// if this is a file count it
485485
if( !(item.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
486-
strcmp( item.cFileName, "." ) &&
487-
strcmp( item.cFileName, ".." ) )
486+
strcmp( item.cFileName, "." ) != 0 &&
487+
strcmp( item.cFileName, ".." ) != 0 )
488488
fileCount++;
489489

490490
}
@@ -526,8 +526,8 @@ Bool ImagePacker::checkOutputDirectory( void )
526526

527527
// if this is a file count it
528528
if( !(item.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
529-
strcmp( item.cFileName, "." ) &&
530-
strcmp( item.cFileName, ".." ) )
529+
strcmp( item.cFileName, "." ) != 0 &&
530+
strcmp( item.cFileName, ".." ) != 0 )
531531
DeleteFile( item.cFileName );
532532

533533
// find the rest of the files
@@ -536,8 +536,8 @@ Bool ImagePacker::checkOutputDirectory( void )
536536

537537
// if this is a file count it
538538
if( !(item.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
539-
strcmp( item.cFileName, "." ) &&
540-
strcmp( item.cFileName, ".." ) )
539+
strcmp( item.cFileName, "." ) != 0 &&
540+
strcmp( item.cFileName, ".." ) != 0 )
541541
DeleteFile( item.cFileName );
542542

543543
}
@@ -687,8 +687,8 @@ void ImagePacker::addDirectory( char *path, Bool subDirs )
687687

688688
// if this is a file count it
689689
if( !(item.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
690-
strcmp( item.cFileName, "." ) &&
691-
strcmp( item.cFileName, ".." ) )
690+
strcmp( item.cFileName, "." ) != 0 &&
691+
strcmp( item.cFileName, ".." ) != 0 )
692692
{
693693

694694
len = strlen( item.cFileName );
@@ -707,8 +707,8 @@ void ImagePacker::addDirectory( char *path, Bool subDirs )
707707

708708
// if this is a file count it
709709
if( !(item.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
710-
strcmp( item.cFileName, "." ) &&
711-
strcmp( item.cFileName, ".." ) )
710+
strcmp( item.cFileName, "." ) != 0 &&
711+
strcmp( item.cFileName, ".." ) != 0 )
712712
{
713713

714714
len = strlen( item.cFileName );
@@ -743,8 +743,8 @@ void ImagePacker::addDirectory( char *path, Bool subDirs )
743743

744744
// if this is a file count it
745745
if( (item.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
746-
strcmp( item.cFileName, "." ) &&
747-
strcmp( item.cFileName, ".." ) )
746+
strcmp( item.cFileName, "." ) != 0 &&
747+
strcmp( item.cFileName, ".." ) != 0 )
748748
{
749749

750750
sprintf( subDir, "%s%s\\", path, item.cFileName );
@@ -758,8 +758,8 @@ void ImagePacker::addDirectory( char *path, Bool subDirs )
758758

759759
// if this is a file count it
760760
if( (item.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
761-
strcmp( item.cFileName, "." ) &&
762-
strcmp( item.cFileName, ".." ) )
761+
strcmp( item.cFileName, "." ) != 0 &&
762+
strcmp( item.cFileName, ".." ) != 0 )
763763
{
764764

765765
sprintf( subDir, "%s%s\\", path, item.cFileName );

Generals/Code/GameEngine/Source/Common/Recorder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ Bool RecorderClass::readReplayHeader(ReplayHeader& header)
892892
// Read the GENREP header.
893893
char genrep[sizeof(s_genrep) - 1] = {0};
894894
m_file->read( &genrep, sizeof(s_genrep) - 1 );
895-
if ( strncmp(genrep, s_genrep, sizeof(s_genrep) - 1 ) ) {
895+
if ( strncmp(genrep, s_genrep, sizeof(s_genrep) - 1 ) != 0 ) {
896896
DEBUG_LOG(("RecorderClass::readReplayHeader - replay file did not have GENREP at the start."));
897897
m_file->close();
898898
m_file = NULL;

Generals/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static void parseBitString( const char *inBuffer, UnsignedInt *bits, ConstCharPt
233233
// do not modify the inBuffer argument
234234
strlcpy(buffer, inBuffer, ARRAY_SIZE(buffer));
235235

236-
if( strncmp( buffer, "NULL", 4 ) )
236+
if( strncmp( buffer, "NULL", 4 ) != 0 )
237237
{
238238
for( tok = strtok( buffer, "+" ); tok; tok = strtok( NULL, "+" ) )
239239
{
@@ -1314,7 +1314,7 @@ static Bool parseDrawData( const char *token, WinInstanceData *instData,
13141314
first = FALSE;
13151315

13161316
c = strtok( NULL, seps ); // value
1317-
if( strcmp( c, "NoImage" ) )
1317+
if( strcmp( c, "NoImage" ) != 0 )
13181318
drawData->image = TheMappedImageCollection->findImageByName( AsciiString( c ) );
13191319
else
13201320
drawData->image = NULL;

GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ Bool RecorderClass::readReplayHeader(ReplayHeader& header)
894894
// Read the GENREP header.
895895
char genrep[sizeof(s_genrep) - 1] = {0};
896896
m_file->read( &genrep, sizeof(s_genrep) - 1 );
897-
if ( strncmp(genrep, s_genrep, sizeof(s_genrep) - 1 ) ) {
897+
if ( strncmp(genrep, s_genrep, sizeof(s_genrep) - 1 ) != 0 ) {
898898
DEBUG_LOG(("RecorderClass::readReplayHeader - replay file did not have GENREP at the start."));
899899
m_file->close();
900900
m_file = NULL;

0 commit comments

Comments
 (0)