With gcc 14 (Ubuntu 24.04) I see a compilation warning:

  bcp47.c:379:12: warning: infinite loop [CWE-835] [-Wanalyzer-infinite-loop]

At first glance, indeed, it looks like a human mistake. So, let me clarify
the code, both for the human reader and for GCC, by verifying an invariant.


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

        bcp47: Silence a gcc 14 -Wanalyzer-infinite-loop warning.
        * lib/bcp47.c: Include <stdlib.h>.
        (bcp47_to_xpg): Verify an invariant through an abort().

diff --git a/lib/bcp47.c b/lib/bcp47.c
index 96f7aad8ce..09f60f1eec 100644
--- a/lib/bcp47.c
+++ b/lib/bcp47.c
@@ -21,6 +21,7 @@
 /* Specification.  */
 #include "bcp47.h"
 
+#include <stdlib.h>
 #include <string.h>
 
 #include "c-ctype.h"
@@ -421,6 +422,8 @@ bcp47_to_xpg (char *xpg, const char *bcp47, const char 
*codeset)
                   }
               }
           }
+        else
+          abort ();
       }
   }
 




Reply via email to