Fix incorrect uses of feof() (#957)

Using feof() as the while loop condition for detecting the end of the file is incorrect.
This commit is contained in:
Fysiks 2021-08-07 10:28:35 -05:00 committed by GitHub
parent 6c9c37eb45
commit 5b1b844184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 19 deletions

View File

@ -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

View File

@ -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

View File

@ -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 )
{

View File

@ -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;
}

View File

@ -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));

View File

@ -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;