In GNU gettext I see this compilation warning:

strerror_r.c:450:35: warning: 'Unknown error ' directive output truncated 
writing 14 bytes into a region of size 2 [-Wformat-truncation=]

This patch silences it.


2024-12-03  Bruno Haible  <br...@clisp.org>

        strerror_r-posix: Silence gcc 14 warning.
        * lib/strerror_r.c (strerror_r): Silence -Wformat-truncation warning.

diff --git a/lib/strerror_r.c b/lib/strerror_r.c
index 87fc114262..b52bd2c0ae 100644
--- a/lib/strerror_r.c
+++ b/lib/strerror_r.c
@@ -443,6 +443,13 @@ strerror_r (int errnum, char *buf, size_t buflen)
 
     if (ret == EINVAL && !*buf)
       {
+        /* gcc 14 produces a
+           "warning: 'Unknown error ' directive output truncated
+            writing 14 bytes into a region of size 2"
+           Thanks for the warning, but here the truncation is intentional.  */
+#if _GL_GNUC_PREREQ (7, 1)
+# pragma GCC diagnostic ignored "-Wformat-truncation"
+#endif
 #if defined __HAIKU__
         /* For consistency with perror().  */
         snprintf (buf, buflen, "Unknown Application Error (%d)", errnum);




Reply via email to