]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
dfa, propername-lite, quotearg: prefer mbszero
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 5 Sep 2025 22:18:31 +0000 (15:18 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 5 Sep 2025 22:19:19 +0000 (15:19 -0700)
Problem reported by Collin Funk in:
https://lists.gnu.org/r/bug-gnulib/2025-09/msg00063.html
* lib/dfa.c (mbszero) [GAWK]: Omit unnecessary parens.
* lib/localeinfo.c (mbszero) [GAWK]: New macro, copied from dfa.c.
(is_using_utf8, init_localeinfo): Use it.
* lib/propername-lite.c (proper_name_lite):
* lib/quotearg.c (gettext_quote):
Prefer mbszero to initializing the entire mbstate_t.

ChangeLog
lib/dfa.c
lib/localeinfo.c
lib/propername-lite.c
lib/quotearg.c

index d5fde9e134a2241c8407996f2f12e3f124400d96..3ec2fff3ecf7a93f9d7805415d13e7a11905ea9e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2025-09-05  Paul Eggert  <eggert@cs.ucla.edu>
 
+       dfa, propername-lite, quotearg: prefer mbszero
+       Problem reported by Collin Funk in:
+       https://lists.gnu.org/r/bug-gnulib/2025-09/msg00063.html
+       * lib/dfa.c (mbszero) [GAWK]: Omit unnecessary parens.
+       * lib/localeinfo.c (mbszero) [GAWK]: New macro, copied from dfa.c.
+       (is_using_utf8, init_localeinfo): Use it.
+       * lib/propername-lite.c (proper_name_lite):
+       * lib/quotearg.c (gettext_quote):
+       Prefer mbszero to initializing the entire mbstate_t.
+
        unlocked-io: also deal with fileno
        This shouldn’t affect performance on glibc, where fileno and
        fileno_unlocked are aliases under the theory that no locking is needed.
index 6180c434515d797e6d15aec25ec93487084dd1dd..284f10da3fbf112b7a1adf3a7c00dc08a43bc3f5 100644 (file)
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -50,7 +50,7 @@
 # define c32tob wctob
 # define c32isprint iswprint
 # define c32isspace iswspace
-# define mbszero(p) memset ((p), 0, sizeof (mbstate_t))
+# define mbszero(p) memset (p, 0, sizeof (mbstate_t))
 #else
 /* Use ISO C 11 + gnulib API.  */
 # include <uchar.h>
index a4396d463cf662ab7482bf98597f85f0d7f92f55..ff38e525ea896bb4414d87a5f735c02373d8154e 100644 (file)
@@ -32,6 +32,7 @@
 # define mbrtoc32 mbrtowc
 # define c32tolower towlower
 # define c32toupper towupper
+# define mbszero(p) memset (p, 0, sizeof (mbstate_t))
 #else
 /* Use ISO C 11 + gnulib API.  */
 # include <uchar.h>
@@ -46,7 +47,7 @@ static bool
 is_using_utf8 (void)
 {
   char32_t wc;
-  mbstate_t mbs = {0};
+  mbstate_t mbs; mbszero (&mbs);
   return mbrtoc32 (&wc, "\xc4\x80", 2, &mbs) == 2 && wc == 0x100;
 }
 
@@ -102,7 +103,7 @@ init_localeinfo (struct localeinfo *localeinfo)
     {
       char c = i;
       unsigned char uc = i;
-      mbstate_t s = {0};
+      mbstate_t s; mbszero (&s);
       char32_t wc;
       size_t len = mbrtoc32 (&wc, &c, 1, &s);
       localeinfo->sbclen[uc] = len <= 1 ? 1 : - (int) - len;
index d465548238232570d3239247e0a808e9ff51c90d..0834a2a6ea97b1076883c45405255efa15c9a6d1 100644 (file)
@@ -45,8 +45,8 @@ proper_name_lite (char const *name_ascii, _GL_UNUSED char const *name_utf8)
   /* If DF BF decodes to 07FF, assume it is UTF-8.  */
   static char const utf07FF[] = { 0xDF, 0xBF };
   char32_t w;
-  mbstate_t mbstate = {0,};
-  if (mbrtoc32 (&w, utf07FF, 2, &mbstate) == 2 && w == 0x07FF)
+  mbstate_t mbs; mbszero (&mbs);
+  if (mbrtoc32 (&w, utf07FF, 2, &mbs) == 2 && w == 0x07FF)
     return name_utf8;
 #endif
 
index 91a2afd7334b22080e8f3a5f95670feca2ed3f2d..24f5e182214f0157b2c219604f93c526ad91cb1a 100644 (file)
@@ -229,8 +229,8 @@ gettext_quote (char const *msgid, enum quoting_style s)
      has other dependencies.  */
   static char const quote[][4] = { "\xe2\x80\x98", "\xe2\x80\x99" };
   char32_t w;
-  mbstate_t mbstate = {0,};
-  if (mbrtoc32 (&w, quote[0], 3, &mbstate) == 3 && w == 0x2018)
+  mbstate_t mbs; mbszero (&mbs);
+  if (mbrtoc32 (&w, quote[0], 3, &mbs) == 3 && w == 0x2018)
     return quote[msgid[0] == '\''];
 
   return (s == clocale_quoting_style ? "\"" : "'");
@@ -606,8 +606,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
               }
             else
               {
-                mbstate_t mbstate;
-                mbszero (&mbstate);
+                mbstate_t mbs; mbszero (&mbs);
 
                 m = 0;
                 printable = true;
@@ -618,7 +617,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
                   {
                     char32_t w;
                     size_t bytes = mbrtoc32 (&w, &arg[i + m],
-                                             argsize - (i + m), &mbstate);
+                                             argsize - (i + m), &mbs);
                     if (bytes == 0)
                       break;
                     else if (bytes == (size_t) -1)
@@ -661,7 +660,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
                         m += bytes;
                       }
                     #if !GNULIB_MBRTOC32_REGULAR
-                    if (mbsinit (&mbstate))
+                    if (mbsinit (&mbs))
                     #endif
                       break;
                   }