Fix strchrnul(3) and strrchr(3) missing an unsigned char cast.

Found by musl's libc-test.
This commit is contained in:
Jonas 'Sortie' Termansen 2014-08-19 20:57:26 +02:00
parent cbd46f610c
commit 88dd70991c
3 changed files with 6 additions and 6 deletions

View File

@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
This file is part of the Sortix C Library. This file is part of the Sortix C Library.
@ -27,5 +27,5 @@
extern "C" char* strchr(const char* str, int uc) extern "C" char* strchr(const char* str, int uc)
{ {
char* ret = strchrnul(str, uc); char* ret = strchrnul(str, uc);
return uc == ((unsigned char*) ret)[0] ? ret : NULL; return (unsigned char) uc == ((unsigned char*) ret)[0] ? ret : NULL;
} }

View File

@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
This file is part of the Sortix C Library. This file is part of the Sortix C Library.
@ -28,6 +28,6 @@ extern "C" char* strchrnul(const char* str, int uc)
{ {
const unsigned char* ustr = (const unsigned char*) str; const unsigned char* ustr = (const unsigned char*) str;
for ( size_t i = 0; true; i++) for ( size_t i = 0; true; i++)
if ( ustr[i] == uc || !ustr[i] ) if ( ustr[i] == (unsigned char) uc || !ustr[i] )
return (char*) str + i; return (char*) str + i;
} }

View File

@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
This file is part of the Sortix C Library. This file is part of the Sortix C Library.
@ -30,7 +30,7 @@ extern "C" char* strrchr(const char* str, int uc)
const char* last = NULL; const char* last = NULL;
for ( size_t i = 0; true; i++ ) for ( size_t i = 0; true; i++ )
{ {
if ( ustr[i] == uc ) if ( ustr[i] == (unsigned char) uc )
last = str + i; last = str + i;
if ( !ustr[i] ) if ( !ustr[i] )
break; break;