]> granicus.if.org Git - fortune-mod/commitdiff
Silence compile-time or run-time warnings.
authorShlomi Fish <shlomif@shlomifish.org>
Wed, 15 Dec 2021 19:19:58 +0000 (21:19 +0200)
committerShlomi Fish <shlomif@shlomifish.org>
Wed, 15 Dec 2021 19:19:58 +0000 (21:19 +0200)
See:

* https://duckduckgo.com/?q=warnings+programming&atb=v140-1&ia=web

They are a distraction at best and may indicate other issues.

fortune-mod/fortune/fortune.c

index 32a8ed9bff58e22b3ce2d208f8d2166fc429d51c..5ce377228026cbf4c79aff87d060e2697b343cd6 100644 (file)
@@ -547,6 +547,7 @@ static int open4read(const char *const path)
  * add_file:
  *      Add a file to the file list.
  */
+#define GCC_SNPRINTF_MARGIN 10
 static int add_file(int percent, const char *file, const char *dir,
     FILEDESC **head, FILEDESC **tail, FILEDESC *parent)
 {
@@ -562,7 +563,8 @@ static int add_file(int percent, const char *file, const char *dir,
     }
     else
     {
-        const size_t do_len = (strlen(dir) + strlen(file) + 2);
+        const size_t do_len =
+            (strlen(dir) + strlen(file) + (2 + GCC_SNPRINTF_MARGIN));
         path = do_malloc(do_len + 1);
         snprintf(path, do_len, "%s/%s", dir, file);
     }
@@ -1821,7 +1823,7 @@ int main(int argc, char *argv[])
         ctype = "ISO-8859-1";
     }
 #endif
-    const size_t do_len = strlen(ctype) + 7 + 1;
+    const size_t do_len = strlen(ctype) + (7 + 1 + GCC_SNPRINTF_MARGIN);
     char *crequest = do_malloc(do_len + 1);
     snprintf(crequest, do_len, "UTF-8..%s", ctype);
     recode_scan_request(request, crequest);