]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libgrep: Optimize and silence gcc warning.
authorBruno Haible <bruno@clisp.org>
Fri, 26 May 2023 21:02:24 +0000 (23:02 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 26 May 2023 22:26:13 +0000 (00:26 +0200)
* gettext-tools/libgrep/m-fgrep.c (Fexecute): Set mb_properties to NULL in a
unibyte locale.

gettext-tools/libgrep/m-fgrep.c

index 3de354db551b26f7457c4063f292d2d5a967bd66..3589675baf3e8fcc5ff18e2d9cfa6be1df3bc366 100644 (file)
@@ -149,6 +149,8 @@ Fexecute (const void *compiled_pattern, const char *buf, size_t buf_size,
   char *mb_properties;
   if (MB_CUR_MAX > 1)
     mb_properties = check_multibyte_string (buf, buf_size);
+  else
+    mb_properties = NULL;
 
   for (beg = buf; beg <= buflim; ++beg)
     {
@@ -156,8 +158,7 @@ Fexecute (const void *compiled_pattern, const char *buf, size_t buf_size,
       size_t offset = kwsexec (ckwset->kwset, beg, buflim - beg, &kwsmatch);
       if (offset == (size_t) -1)
         {
-          if (MB_CUR_MAX > 1)
-            free (mb_properties);
+          free (mb_properties);
           return offset;
         }
       if (MB_CUR_MAX > 1 && mb_properties[offset+beg-buf] == 0)
@@ -167,8 +168,7 @@ Fexecute (const void *compiled_pattern, const char *buf, size_t buf_size,
       if (exact)
         {
           *match_size = len;
-          if (MB_CUR_MAX > 1)
-            free (mb_properties);
+          free (mb_properties);
           return beg - buf;
         }
       if (ckwset->match_lines)
@@ -192,8 +192,7 @@ Fexecute (const void *compiled_pattern, const char *buf, size_t buf_size,
                   offset = kwsexec (ckwset->kwset, beg, --len, &kwsmatch);
                   if (offset == (size_t) -1)
                     {
-                      if (MB_CUR_MAX > 1)
-                        free (mb_properties);
+                      free (mb_properties);
                       return offset;
                     }
                   curr = beg + offset;
@@ -207,8 +206,7 @@ Fexecute (const void *compiled_pattern, const char *buf, size_t buf_size,
         goto success;
     }
 
-  if (MB_CUR_MAX > 1)
-    free (mb_properties);
+  free (mb_properties);
   return -1;
 
  success:
@@ -223,8 +221,7 @@ Fexecute (const void *compiled_pattern, const char *buf, size_t buf_size,
     while (buf < beg && beg[-1] != eol)
       --beg;
     *match_size = end - beg;
-    if (MB_CUR_MAX > 1)
-      free (mb_properties);
+    free (mb_properties);
     return beg - buf;
   }
 }