[libc-commits] [libc] [libc] Fix stale char_ptr for find_first_character_wide read (PR #166594)

Alexey Samsonov via libc-commits libc-commits at lists.llvm.org
Wed Nov 5 10:00:55 PST 2025


================
@@ -136,11 +136,11 @@ find_first_character_wide_read(const unsigned char *src, unsigned char ch,
   const Word ch_mask = repeat_byte<Word>(ch);
 
   // Step 2: read blocks
-  for (const Word *block_ptr = reinterpret_cast<const Word *>(char_ptr);
-       !has_zeroes<Word>((*block_ptr) ^ ch_mask) && cur < n;
-       ++block_ptr, cur += sizeof(Word)) {
-    char_ptr = reinterpret_cast<const unsigned char *>(block_ptr);
-  }
+  const Word *block_ptr = reinterpret_cast<const Word *>(char_ptr);
+  for (; !has_zeroes<Word>((*block_ptr) ^ ch_mask) && cur < n;
----------------
vonosmas wrote:

I wonder if here (and everywhere in this function, `cur < n` check should go first in the `&&` condition? To ensure that whenever we're comparing the byte, this byte is actually inside the string (or a first byte of a word-size-block is inside the string)?

https://github.com/llvm/llvm-project/pull/166594


More information about the libc-commits mailing list