Skip to content
Snippets Groups Projects
Commit 6a778f99 authored by Hallvard Furuseth's avatar Hallvard Furuseth
Browse files

Fix lutil_memrchr():

Avoid void* pointer arithmetic.
Convert int c to unsigned char, so c=<negative char value> will match.
Do not decrement pointer below start of array (even when value is not used).
parent 2bf647fa
No related branches found
No related tags found
No related merge requests found
......@@ -311,22 +311,21 @@ int mkstemp( char * template )
}
#endif
/*
/*
* Memory Reverse Search
*/
void *
lutil_memrchr(const void *b, int c, size_t n)
lutil_memrchr(const void *b, int c, size_t n)
{
if (n != 0) {
const unsigned char *s;
const unsigned char *s, *bb = b, cc = c;
for ( s = b + n; s-- > b; ) {
if ( *s == c ) {
return s;
for ( s = bb + n; s > bb; ) {
if ( *--s == cc ) {
return (void *) s;
}
}
}
return NULL;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment