]> Savannah Git Hosting - gnulib.git/commitdiff
string-desc: Fix undefined behaviour.
authorBruno Haible <bruno@clisp.org>
Tue, 10 Sep 2024 00:07:57 +0000 (02:07 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 17 Sep 2024 11:54:57 +0000 (13:54 +0200)
* lib/string-desc-contains.c (string_desc_contains): Handle the case of
an empty haystack before invoking 'memmem'.

ChangeLog
lib/string-desc-contains.c

index 3e00ff9390de00a000772da9cd015efff5d18d83..0ce413ce4509600b1645f75bf99890491cc9d562 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-09-09  Bruno Haible  <bruno@clisp.org>
+
+       string-desc: Fix undefined behaviour.
+       * lib/string-desc-contains.c (string_desc_contains): Handle the case of
+       an empty haystack before invoking 'memmem'.
+
 2024-09-05  Paul Eggert  <eggert@cs.ucla.edu>
 
        Fix COPYING.EXCEPTION license notices
index 21c52069f69fc5c0a070a1d06cc86f393d7c55bd..ec79d6acf00a639b1b4e5f2e290e16bce8a9e30a 100644 (file)
@@ -35,6 +35,8 @@ string_desc_contains (string_desc_t haystack, string_desc_t needle)
 {
   if (needle._nbytes == 0)
     return 0;
+  if (haystack._nbytes == 0)
+    return -1;
   void *found =
     memmem (haystack._data, haystack._nbytes, needle._data, needle._nbytes);
   if (found != NULL)