From: John Hodge Date: Wed, 18 Feb 2015 07:55:26 +0000 (+0800) Subject: Usermode/libc - Fix strchr and strrchr behavior X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=230612b2efeeb769f1d96193ec01b10bd36d9873;p=tpg%2Facess2.git Usermode/libc - Fix strchr and strrchr behavior --- diff --git a/Usermode/Libraries/libc.so_src/string.c b/Usermode/Libraries/libc.so_src/string.c index d61d51dd..09481d86 100644 --- a/Usermode/Libraries/libc.so_src/string.c +++ b/Usermode/Libraries/libc.so_src/string.c @@ -184,15 +184,16 @@ EXPORT char *strndup(const char *str, size_t maxlen) /** * \fn EXPORT char *strchr(char *str, int character) * \brief Locate a character in a string + * \note The terminating NUL is part of the string */ EXPORT char *strchr(const char *_str, int character) { const unsigned char* str = (const unsigned char*)_str; - for(;*str;str++) + do { if( *str == character ) return (char*)str; - } + } while( *str++ ); return NULL; } @@ -203,11 +204,12 @@ EXPORT char *strchr(const char *_str, int character) EXPORT char *strrchr(const char *_str, int character) { const unsigned char* str = (const unsigned char*)_str; - for( size_t i = strlen(_str); i--; ) + size_t i = strlen(_str); + do { if(str[i] == character) return (void*)&str[i]; - } + } while( i -- ); return NULL; }