On 2011-12-25 at 17:02:04 [+0100], fredrik.holmqvist@xxxxxxxxx wrote: > diff --git a/src/system/libroot/posix/string/strlen.c > b/src/system/libroot/posix/string/strlen.c > index 013c278..a94ded2 100644 > --- a/src/system/libroot/posix/string/strlen.c > +++ b/src/system/libroot/posix/string/strlen.c > @@ -6,30 +6,29 @@ > #include <string.h> > #include <SupportDefs.h> > > -// From Bit twiddling hacks: > http://graphics.stanford.edu/~seander/bithacks.html > -#define hasZeroByte(value) (value - 0x01010101) & ~value & 0x80808080 > + > +/* From Bit twiddling hacks: > + http://graphics.stanford.edu/~seander/bithacks.html */ > +#define HasZeroByte(value) ((value - 0x01010101) & ~value & 0x80808080) > + HAS_ZERO_BYTE(). "!= 0" to produce a boolean value. > > size_t > -strlen(char const *s) > +strlen(const char* s) s is not a good name. > { > - size_t i = 0; > - uint32 *value; > - > - //Make sure we use aligned access > - while (((uint32) s + i) & 3) { > - if (!s[i]) return i; > - i++; > - } > - > - //Check four bytes at once > - value = (uint32 *) (s + i); > - while (!(hasZeroByte(*value))) > - value++; > - > - //Find the exact length > - i = ((char *) value) - s; > - while (s[i]) > - i++; > - > - return i; > + size_t length = 0; > + uint32* valuePointer; > + > + /* Align access for four byte reads */ The C++ style comments were fine in principle, save for the missing space. > + for (; (((addr_t) s + length) & 3) != 0; length++) No space after cast operator. > + if (s[length] == '\0') > + return length; > + > + /* Check four bytes for zero char */ > + for (valuePointer = (uint32*) (s + length); > !HasZeroByte(*valuePointer); > + valuePointer++); > + > + /* Find the exact length */ > + for (length = ((char*) valuePointer) - s; s[length] != '\0'; length++); Ditto. > + > + return length; > } > diff --git a/src/system/libroot/posix/string/strnlen.c > b/src/system/libroot/posix/string/strnlen.c > index 05a2920..677fd4f 100644 > --- a/src/system/libroot/posix/string/strnlen.c > +++ b/src/system/libroot/posix/string/strnlen.c [...] Same issues in this file, just more of them. CU, Ingo