From: Hallvard Furuseth Date: Mon, 14 Nov 2005 15:40:01 +0000 (+0000) Subject: Fix lutil_memrchr(): X-Git-Tag: OPENLDAP_REL_ENG_2_2_MP~23 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6a778f99f5645c744dc6c17abc7f9bfb766a00f9;p=openldap Fix lutil_memrchr(): Avoid void* pointer arithmetic. Convert int c to unsigned char, so c= will match. Do not decrement pointer below start of array (even when value is not used). --- diff --git a/libraries/liblutil/utils.c b/libraries/liblutil/utils.c index d2fea36db2..d227f32828 100644 --- a/libraries/liblutil/utils.c +++ b/libraries/liblutil/utils.c @@ -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; -} - +}