Mercurial > hg > octave-nkf > gnulib-hg
changeset 17405:2760c772c42c
memchr2: port --enable-gcc-warnings to clang
* lib/memchr2.c (memchr2):
Avoid casts from looser to stricter-aligned pointers.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Wed, 15 May 2013 00:26:14 -0700 |
parents | 832be175c090 |
children | 253d6bbd7aa4 |
files | ChangeLog lib/memchr2.c |
diffstat | 2 files changed, 16 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2013-05-15 Paul Eggert <eggert@cs.ucla.edu> + memchr2: port --enable-gcc-warnings to clang + * lib/memchr2.c (memchr2): + Avoid casts from looser to stricter-aligned pointers. + mbsstr: port --enable-gcc-warnings to clang * lib/mbsstr.c (knuth_morris_pratt_multibyte): Avoid casts from looser to stricter-aligned pointers.
--- a/lib/memchr2.c +++ b/lib/memchr2.c @@ -43,6 +43,7 @@ typedef unsigned long int longword; const unsigned char *char_ptr; + void const *void_ptr; const longword *longword_ptr; longword repeated_one; longword repeated_c1; @@ -57,14 +58,18 @@ return memchr (s, c1, n); /* Handle the first few bytes by reading one byte at a time. - Do this until CHAR_PTR is aligned on a longword boundary. */ - for (char_ptr = (const unsigned char *) s; - n > 0 && (size_t) char_ptr % sizeof (longword) != 0; - --n, ++char_ptr) - if (*char_ptr == c1 || *char_ptr == c2) - return (void *) char_ptr; + Do this until VOID_PTR is aligned on a longword boundary. */ + for (void_ptr = s; + n > 0 && (uintptr_t) void_ptr % sizeof (longword) != 0; + --n) + { + char_ptr = void_ptr; + if (*char_ptr == c1 || *char_ptr == c2) + return (void *) void_ptr; + void_ptr = char_ptr + 1; + } - longword_ptr = (const longword *) char_ptr; + longword_ptr = void_ptr; /* All these elucidatory comments refer to 4-byte longwords, but the theory applies equally well to any size longwords. */