]> 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 14:06:17 +0000 (16:06 +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 fa48d7a5bdbe4b9cd221989535fee84f35641e4a..9b25a979bdb14c295fd1166bea1f0a01b382d812 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)