From: Bruno Haible Date: Mon, 11 May 2026 22:54:57 +0000 (+0200) Subject: setlocale: Use countof. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=96ca1e164b02c5defbcdbb274febb4f55461e577;p=thirdparty%2Fgnulib.git setlocale: Use countof. * lib/setlocale.c: Include . (setlocale_unixlike, get_main_locale_with_same_language, get_main_locale_with_same_territory, setlocale_improved): Use countof. * modules/setlocale (Depends-on): Add stdcountof-h. --- diff --git a/ChangeLog b/ChangeLog index 5e31f790bf..8bf9697303 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2026-05-11 Bruno Haible + + setlocale: Use countof. + * lib/setlocale.c: Include . + (setlocale_unixlike, get_main_locale_with_same_language, + get_main_locale_with_same_territory, setlocale_improved): Use countof. + * modules/setlocale (Depends-on): Add stdcountof-h. + 2026-05-11 Bruno Haible gettext-h: Ensure no warnings with --disable-nls and -Wformat=2. diff --git a/lib/setlocale.c b/lib/setlocale.c index 022105050f..d40e1e2efd 100644 --- a/lib/setlocale.c +++ b/lib/setlocale.c @@ -29,6 +29,7 @@ /* Specification. */ #include +#include #include #include #include @@ -735,10 +736,7 @@ setlocale_unixlike (int category, const char *locale) { range_t range; - search (language_table, - sizeof (language_table) / sizeof (language_table[0]), - llCC_buf, - &range); + search (language_table, countof (language_table), llCC_buf, &range); for (size_t i = range.lo; i < range.hi; i++) { @@ -782,17 +780,13 @@ setlocale_unixlike (int category, const char *locale) and CC_buf in country_table. */ range_t language_range; - search (language_table, - sizeof (language_table) / sizeof (language_table[0]), - ll_buf, + search (language_table, countof (language_table), ll_buf, &language_range); if (language_range.lo < language_range.hi) { range_t country_range; - search (country_table, - sizeof (country_table) / sizeof (country_table[0]), - CC_buf, + search (country_table, countof (country_table), CC_buf, &country_range); if (country_range.lo < country_range.hi) for (size_t i = language_range.lo; i < language_range.hi; i++) @@ -1162,7 +1156,7 @@ get_main_locale_with_same_language (const char *locale) { # define table locales_with_principal_territory /* The table is sorted. Perform a binary search. */ - size_t hi = sizeof (table) / sizeof (table[0]); + size_t hi = countof (table); size_t lo = 0; while (lo < hi) { @@ -1391,7 +1385,7 @@ get_main_locale_with_same_territory (const char *locale) { # define table locales_with_principal_language /* The table is sorted. Perform a binary search. */ - size_t hi = sizeof (table) / sizeof (table[0]); + size_t hi = countof (table); size_t lo = 0; while (lo < hi) { @@ -1483,7 +1477,7 @@ setlocale_improved (int category, const char *locale) goto fail; # endif - for (; i < sizeof (categories) / sizeof (categories[0]); i++) + for (; i < countof (categories); i++) { int cat = categories[i]; const char *name = diff --git a/modules/setlocale b/modules/setlocale index 75c2297387..aff365ac95 100644 --- a/modules/setlocale +++ b/modules/setlocale @@ -7,6 +7,7 @@ m4/setlocale.m4 Depends-on: locale-h +stdcountof-h streq setlocale-fixes [test $NEED_SETLOCALE_IMPROVED = 1] localename [test $NEED_SETLOCALE_IMPROVED = 1]