From: Luke Howard Date: Sun, 21 Sep 2003 06:26:43 +0000 (+0000) Subject: Define SLAP_STRTOL macro for integerBitAndMatch() and integerBitOrMatch() X-Git-Tag: OPENLDAP_REL_ENG_2_1_MP~691 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3846a8881a5c5baf766619d6fa85302925abae89;p=openldap Define SLAP_STRTOL macro for integerBitAndMatch() and integerBitOrMatch() usage - necessary to use larger types for interop with a certain client that would expect the assertion (attr:1.2.840.113556.1.4.803:=2147483648) to match a signed value (eg. -2147483646). There are probably better / more portable solutions; review appreciated. --- diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index e5fc458612..7fe8d87c5c 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -1787,6 +1787,22 @@ numericStringNormalize( return LDAP_SUCCESS; } +/* + * Integer conversion macros that will use the largest available + * type. + */ +#if defined(HAVE_STRTOLL) && defined(LLONG_MAX) && defined(LLONG_MIN) +# define SLAP_STRTOL(n,e,b) strtoll(n,e,b) +# define SLAP_LONG_MAX LLONG_MAX +# define SLAP_LONG_MIN LLONG_MIN +# define SLAP_LONG long long +#else +# define SLAP_STRTOL(n,e,b) strtol(n,e,b) +# define SLAP_LONG_MAX LONG_MAX +# define SLAP_LONG_MIN LONG_MIN +# define SLAP_LONG long +#endif /* HAVE_STRTOLL ... */ + static int integerBitAndMatch( int *matchp, @@ -1796,16 +1812,16 @@ integerBitAndMatch( struct berval *value, void *assertedValue ) { - long lValue, lAssertedValue; + SLAP_LONG lValue, lAssertedValue; /* safe to assume integers are NUL terminated? */ - lValue = strtol(value->bv_val, NULL, 10); - if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE ) { + lValue = SLAP_STRTOL(value->bv_val, NULL, 10); + if(( lValue == SLAP_LONG_MIN || lValue == SLAP_LONG_MAX) && errno == ERANGE ) { return LDAP_CONSTRAINT_VIOLATION; } - lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10); - if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) + lAssertedValue = SLAP_STRTOL(((struct berval *)assertedValue)->bv_val, NULL, 10); + if(( lAssertedValue == SLAP_LONG_MIN || lAssertedValue == SLAP_LONG_MAX ) && errno == ERANGE ) { return LDAP_CONSTRAINT_VIOLATION; @@ -1824,16 +1840,16 @@ integerBitOrMatch( struct berval *value, void *assertedValue ) { - long lValue, lAssertedValue; + SLAP_LONG lValue, lAssertedValue; /* safe to assume integers are NUL terminated? */ - lValue = strtol(value->bv_val, NULL, 10); - if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE ) { + lValue = SLAP_STRTOL(value->bv_val, NULL, 10); + if(( lValue == SLAP_LONG_MIN || lValue == SLAP_LONG_MAX ) && errno == ERANGE ) { return LDAP_CONSTRAINT_VIOLATION; } - lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10); - if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) + lAssertedValue = SLAP_STRTOL(((struct berval *)assertedValue)->bv_val, NULL, 10); + if(( lAssertedValue == SLAP_LONG_MIN || lAssertedValue == SLAP_LONG_MAX ) && errno == ERANGE ) { return LDAP_CONSTRAINT_VIOLATION;