]> 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, 10 Sep 2024 00:07:57 +0000 (02:07 +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 d3731a561da96910fc3ad7e90e48c69ac576524a..756ae71eea8f66ae5ffcb3adc4e076e684730929 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-09  Bruno Haible  <bruno@clisp.org>
 
        striconv, striconveh, unicodeio: Drop workaround for glibc 2.1.
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)