]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
intl: Fix an ISO C undefined behaviour.
authorBruno Haible <bruno@clisp.org>
Tue, 5 May 2026 18:23:13 +0000 (20:23 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 5 May 2026 18:23:13 +0000 (20:23 +0200)
ISO C 23 § 6.5.3.3.(7) and § 6.7.7.4.(14) and § 6.2.7 forbid invoking
a function pointer after having cast it to an incompatible function type.

* gettext-runtime/intl/localealias.c (alias_compare): Change type of parameters
to 'const void *'.
(_nl_expand_alias, read_alias_file): Don't cast the alias_compare function
pointer.

gettext-runtime/intl/localealias.c

index 7e0d4e7b56bab13bccb248ef038aef0a15b9658f..ddd9b8bda8d96f387c57ff850ea5909e80ed692b 100644 (file)
@@ -176,8 +176,7 @@ static size_t maxmap;
 /* Prototypes for local functions.  */
 static size_t read_alias_file (const char *fname, int fname_len);
 static int extend_alias_table (void);
-static int alias_compare (const struct alias_map *map1,
-                         const struct alias_map *map2);
+static int alias_compare (const void *, const void *);
 
 #endif
 
@@ -206,9 +205,7 @@ _nl_expand_alias (const char *name)
       if (nmap > 0)
        retval = (struct alias_map *) bsearch (&item, map, nmap,
                                               sizeof (struct alias_map),
-                                              (int (*) (const void *,
-                                                        const void *)
-                                               ) alias_compare);
+                                              alias_compare);
       else
        retval = NULL;
 
@@ -423,8 +420,7 @@ read_alias_file (const char *fname, int fname_len)
   fclose (fp);
 
   if (added > 0)
-    qsort (map, nmap, sizeof (struct alias_map),
-          (int (*) (const void *, const void *)) alias_compare);
+    qsort (map, nmap, sizeof (struct alias_map), alias_compare);
 
   return added;
 }
@@ -450,8 +446,10 @@ extend_alias_table (void)
 
 
 static int
-alias_compare (const struct alias_map *map1, const struct alias_map *map2)
+alias_compare (const void *arg1, const void *arg2)
 {
+  const struct alias_map *map1 = (const struct alias_map *) arg1;
+  const struct alias_map *map2 = (const struct alias_map *) arg2;
   return strcasecmp (map1->alias, map2->alias);
 }