diff options
Diffstat (limited to 'libc/string')
-rw-r--r-- | libc/string/generic/strnlen.c | 6 | ||||
-rw-r--r-- | libc/string/x86_64/strcat.S | 2 | ||||
-rw-r--r-- | libc/string/x86_64/strcspn.S | 2 | ||||
-rw-r--r-- | libc/string/x86_64/strlen.S | 2 | ||||
-rw-r--r-- | libc/string/x86_64/strspn.S | 2 |
5 files changed, 8 insertions, 6 deletions
diff --git a/libc/string/generic/strnlen.c b/libc/string/generic/strnlen.c index 4d4cde84f..82d4122ec 100644 --- a/libc/string/generic/strnlen.c +++ b/libc/string/generic/strnlen.c @@ -29,15 +29,17 @@ '\0' terminator is found in that many characters, return MAXLEN. */ size_t strnlen (const char *str, size_t maxlen) { - const char *char_ptr, *end_ptr = str + maxlen; + const char *char_ptr, *end_ptr; const unsigned long int *longword_ptr; unsigned long int longword, himagic, lomagic; if (maxlen == 0) return 0; - if (__builtin_expect (end_ptr < str, 0)) + if (__builtin_expect ((uintptr_t)str + maxlen < (uintptr_t)str, 0)) end_ptr = (const char *) ~0UL; + else + end_ptr = str + maxlen; /* Handle the first few characters by reading one character at a time. Do this until CHAR_PTR is aligned on a longword boundary. */ diff --git a/libc/string/x86_64/strcat.S b/libc/string/x86_64/strcat.S index 55e09e5f1..209e19062 100644 --- a/libc/string/x86_64/strcat.S +++ b/libc/string/x86_64/strcat.S @@ -106,7 +106,7 @@ ENTRY (BP_SYM (strcat)) /* Align, it is a jump target. */ /* Next 3 insns are 8 bytes total, make sure we decode them in one go */ - .p2align 3,,8 + .p2align 3,,7 3: subq $8,%rax /* correct pointer increment. */ diff --git a/libc/string/x86_64/strcspn.S b/libc/string/x86_64/strcspn.S index 7a06c8867..5ef565db7 100644 --- a/libc/string/x86_64/strcspn.S +++ b/libc/string/x86_64/strcspn.S @@ -94,7 +94,7 @@ L(1): leaq -4(%rdx), %rax /* prepare loop */ /* but it will also align entire function to 16 bytes, */ /* potentially creating largish padding at link time. */ /* We are aligning to 8 bytes instead: */ - .p2align 3,,8 + .p2align 3,,7 L(3): addq $4, %rax /* adjust pointer for full loop round */ diff --git a/libc/string/x86_64/strlen.S b/libc/string/x86_64/strlen.S index 9e84326c2..2fe2f58b2 100644 --- a/libc/string/x86_64/strlen.S +++ b/libc/string/x86_64/strlen.S @@ -102,7 +102,7 @@ ENTRY (strlen) /* Align, it is a jump target. */ /* Next 3 insns are 8 bytes total, make sure we decode them in one go */ - .p2align 3,,8 + .p2align 3,,7 3: subq $8,%rax /* correct pointer increment. */ diff --git a/libc/string/x86_64/strspn.S b/libc/string/x86_64/strspn.S index 366377649..8dc42656b 100644 --- a/libc/string/x86_64/strspn.S +++ b/libc/string/x86_64/strspn.S @@ -89,7 +89,7 @@ L(1): leaq -4(%rdx), %rax /* prepare loop */ /* but it will also align entire function to 16 bytes, */ /* potentially creating largish padding at link time. */ /* We are aligning to 8 bytes instead: */ - .p2align 3,,8 + .p2align 3,,7 L(3): addq $4, %rax /* adjust pointer for full loop round */ |