mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-23 16:19:35 -05:00
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).
This commit is contained in:
parent
2bf647fa16
commit
6a778f99f5
1 changed files with 7 additions and 8 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue