Avoid double bounds check at the start of the loop

Message ID 20230904145651.1449926-1-tirtajames45@gmail.com
State Dropped
Headers
Series Avoid double bounds check at the start of the loop |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Testing passed

Commit Message

James Tirta Halim Sept. 4, 2023, 2:56 p.m. UTC
  ---
 string/memmem.c | 4 ++--
 string/strstr.c | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)
  

Patch

diff --git a/string/memmem.c b/string/memmem.c
index 13df3bcdd4..dea3e5a29c 100644
--- a/string/memmem.c
+++ b/string/memmem.c
@@ -92,7 +92,7 @@  __memmem (const void *haystack, size_t hs_len,
   shift1 = m1 - shift[hash2 (ne + m1)];
   shift[hash2 (ne + m1)] = m1;
 
-  for ( ; hs <= end; )
+  do
     {
       /* Skip past character pairs not in the needle.  */
       do
@@ -121,7 +121,7 @@  __memmem (const void *haystack, size_t hs_len,
 
       /* Skip based on matching the hash of the needle end.  */
       hs += shift1;
-    }
+    } while (hs <= end);
   return NULL;
 }
 libc_hidden_def (__memmem)
diff --git a/string/strstr.c b/string/strstr.c
index 23618e2eb2..7ec812b931 100644
--- a/string/strstr.c
+++ b/string/strstr.c
@@ -121,6 +121,7 @@  STRSTR (const char *haystack, const char *needle)
   shift1 = m1 - shift[hash2 (ne + m1)];
   shift[hash2 (ne + m1)] = m1;
 
+  goto start;
   while (1)
     {
       if (__glibc_unlikely (hs > end))
@@ -130,6 +131,7 @@  STRSTR (const char *haystack, const char *needle)
 	    return NULL;
 	}
 
+start:
       /* Skip past character pairs not in the needle.  */
       do
 	{