|
From: | Paolo Bonzini |
Subject: | Re: [PATCH v2 0/5] Speed up uNN_chr and uNN_strchr with Boyer-Moore algorithm |
Date: | Thu, 29 Jul 2010 17:29:41 +0200 |
User-agent: | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100621 Fedora/3.0.5-1.fc13 Lightning/1.0b2pre Thunderbird/3.0.5 |
On 07/29/2010 04:32 PM, Pádraig Brady wrote:
No! You can cheat!:) Just pass 4 to u8_mbtouc. There will be no out-of-bounds access: if the string ends before that, you get either a complete character or an EILSEQ.You don't get EILSEQ for u8_mbtouc(&uc,"aa",6);
But you get a complete character and 1 is returned. The point is that u8_mbtouc will look only one byte past the end of a (valid or invalid) character, and that one byte will be the nul in the u8_strstr case. Like this: if (!needle[0]) return haystack; n = u8_mbtouc(&uc, needle, 4); if (uc == 0xfffd && n != 3) return NULL; /* invalid, cannot be incomplete since we pass n=4 */ if (needle[n]) return strstr(haystack, needle); else return u8_strchr(haystack, uc); /* inlining would avoid uctomb */ Paolo
[Prev in Thread] | Current Thread | [Next in Thread] |