chiark / gitweb /
makeindex: check return of fgets
authorMatthew Vernon <matthew@debian.org>
Fri, 7 Nov 2025 11:34:45 +0000 (11:34 +0000)
committerMatthew Vernon <matthew@debian.org>
Fri, 7 Nov 2025 14:35:30 +0000 (14:35 +0000)
Not doing so was flagged by newer build tooling:

makeindex.c:127:9: error: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]

makeindex.c

index abcb26b9f1a04eadb7a52f2998d75cdc9d270b68..eca05a8b1264fa2b341fc8d1575e0db7081ca6b1 100644 (file)
@@ -124,7 +124,12 @@ int main(int argc,char **argv)
        printf( "%ld, ", offset );
 
        /* Determine offset of next line */
-       fgets( textbuff, TBSIZE, fp);
+       if (fgets( textbuff, TBSIZE, fp) == NULL) {
+         if (ferror(fp)) {
+               perror("fgets when determining line offset");
+               return 1;
+             }
+         }
        offset += strlen(textbuff);
        cur_line++;
     }