]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: assist clang to suppress warning
authorVictor Julien <vjulien@oisf.net>
Thu, 8 May 2025 08:51:29 +0000 (10:51 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 9 May 2025 05:50:41 +0000 (07:50 +0200)
  CC       detect-engine-loader.o
In file included from /usr/include/stdio.h:970,
                 from suricata-common.h:77,
                 from detect-engine-loader.c:24:
In function 'fgets',
    inlined from 'DetectLoadSigFile' at detect-engine-loader.c:139:11:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:313:12: warning: argument 2 value -1 is negative [-Wstringop-overflow=]
  313 |     return __fgets_alias (__s, __n, __stream);
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/features.h:523,
                 from /usr/include/dirent.h:25,
                 from suricata-common.h:73:
/usr/include/x86_64-linux-gnu/bits/stdio2-decl.h: In function 'DetectLoadSigFile':
/usr/include/x86_64-linux-gnu/bits/stdio2-decl.h:96:14: note: in a call to function '__fgets_alias' declared with attribute 'access (write_only, 1, 2)'
   96 | extern char *__REDIRECT (__fgets_alias,
      |              ^~~~~~~~~~

src/detect-engine-loader.c

index c51f17ce80170f85762e932e7d5152374c607da7..9384aa541558010b9f7b1fb14f4d731101ac1b3b 100644 (file)
@@ -136,7 +136,14 @@ static int DetectLoadSigFile(DetectEngineCtx *de_ctx, const char *sig_file, int
         return -1;
     }
 
-    while (fgets(line + offset, (int)(sizeof(line) - offset), fp) != NULL) {
+    while (1) {
+        /* help clang to understand offset can't get > sizeof(line), so the argument to
+         * fgets can't get negative. */
+        BUG_ON(offset >= sizeof(line));
+        char *res = fgets(line + offset, (int)(sizeof(line) - offset), fp);
+        if (res == NULL)
+            break;
+
         lineno++;
         size_t len = strlen(line);