From 5b1b844184dda295b20149cf7f50047b58fd8181 Mon Sep 17 00:00:00 2001 From: Fysiks Date: Sat, 7 Aug 2021 10:28:35 -0500 Subject: [PATCH] Fix incorrect uses of feof() (#957) Using feof() as the while loop condition for detecting the end of the file is incorrect. --- plugins/admin.sma | 4 +--- plugins/cmdmenu.sma | 4 +--- plugins/cstrike/miscstats.sma | 6 ++---- plugins/cstrike/restmenu.sma | 6 ++++-- plugins/mapchooser.sma | 5 +---- plugins/mapsmenu.sma | 4 +--- 6 files changed, 10 insertions(+), 19 deletions(-) diff --git a/plugins/admin.sma b/plugins/admin.sma index 1021fcc7..56a6862c 100755 --- a/plugins/admin.sma +++ b/plugins/admin.sma @@ -364,10 +364,8 @@ loadSettings(szFilename[]) new AuthData[44]; new Password[32]; - while (!feof(File)) + while (fgets(File, Text, charsmax(Text))) { - fgets(File, Text, charsmax(Text)); - trim(Text); // comment diff --git a/plugins/cmdmenu.sma b/plugins/cmdmenu.sma index 5a01aa69..e2b75ffd 100755 --- a/plugins/cmdmenu.sma +++ b/plugins/cmdmenu.sma @@ -124,10 +124,8 @@ public plugin_precache( ) new fieldNums = 0; new const voxIdent[] = "vox", fvoxIdent[] = "fvox", barneyIdent[] = "barney", hgruntIdent[] = "hgrunt"; - while ( line < MAX_CMDS && ! feof( fp ) ) // Loop till MAX_CMDS or EOF + while ( line < MAX_CMDS && fgets( fp, szText, charsmax(szText) ) ) // Loop till MAX_CMDS or no more file data { - fgets( fp, szText, charsmax(szText) ); // Store line content - /* Strips newline */ new len = strlen( szText ); if ( len != 0 && szText[len-1] == '^n' ) // len != 0 because if the last line of the file is empty, there's no newline diff --git a/plugins/cstrike/miscstats.sma b/plugins/cstrike/miscstats.sma index 4107e44f..5cb80ca7 100755 --- a/plugins/cstrike/miscstats.sma +++ b/plugins/cstrike/miscstats.sma @@ -236,9 +236,8 @@ public plugin_precache() if( fp ) { new xvarname[32], xvarid - while( !feof(fp) ) + while( fgets(fp, buffer, charsmax(buffer)) ) { - fgets(fp, buffer, charsmax(buffer)) trim(buffer) if( buffer[0] != ';' ) { @@ -257,9 +256,8 @@ public plugin_precache() if( fp ) { new szSoundKey[32], szSoundFile[SOUNDFILE_PATH_MAXLEN] - while( !feof(fp) ) + while( fgets(fp, buffer, charsmax(buffer)) ) { - fgets(fp, buffer, charsmax(buffer)) trim(buffer) if( buffer[0] != ';' && parse(buffer, szSoundKey, charsmax(szSoundKey), szSoundFile, charsmax(szSoundFile)) == 2 ) { diff --git a/plugins/cstrike/restmenu.sma b/plugins/cstrike/restmenu.sma index 0544e76f..05a7d3c7 100755 --- a/plugins/cstrike/restmenu.sma +++ b/plugins/cstrike/restmenu.sma @@ -594,9 +594,11 @@ bool:loadSettings(const filename[]) arrayset(RestrictedBotEquipAmmos, '0', charsmax(RestrictedBotEquipAmmos)); arrayset(RestrictedBotWeapons, '0', charsmax(RestrictedBotWeapons)); - while (!feof(fp)) + while (fgets(fp, lineRead, charsmax(lineRead))) { - if (fgets(fp, lineRead, charsmax(lineRead)) - trim(lineRead) <= 0) + trim(lineRead) + + if (!lineRead[0]) { continue; } diff --git a/plugins/mapchooser.sma b/plugins/mapchooser.sma index 55c988b9..0f712c44 100755 --- a/plugins/mapchooser.sma +++ b/plugins/mapchooser.sma @@ -249,13 +249,10 @@ loadSettings(filename[]) new fp=fopen(filename,"r"); - while (!feof(fp)) + while (fgets(fp, buff, charsmax(buff))) { - buff[0]='^0'; szText[0]='^0'; - fgets(fp, buff, charsmax(buff)); - parse(buff, szText, charsmax(szText)); diff --git a/plugins/mapsmenu.sma b/plugins/mapsmenu.sma index 22236855..c6d609c6 100755 --- a/plugins/mapsmenu.sma +++ b/plugins/mapsmenu.sma @@ -549,10 +549,8 @@ load_settings(filename[]) new text[256]; new tempMap[32]; - while (!feof(fp)) + while (fgets(fp, text, charsmax(text))) { - fgets(fp, text, charsmax(text)); - if (text[0] == ';') { continue;