]> granicus.if.org Git - php/commitdiff
Fix autoconversion of hexadecimal strings
authorZeev Suraski <zeev@php.net>
Sun, 6 May 2001 12:48:17 +0000 (12:48 +0000)
committerZeev Suraski <zeev@php.net>
Sun, 6 May 2001 12:48:17 +0000 (12:48 +0000)
It's time to close bug #5404 :)

Zend/zend_operators.h

index 9d3b9fdb688a6f206131b7c8a3b7c019adada057..9bb5a4803c6f4ea3089995bc8e9d4362be761f38 100644 (file)
@@ -62,13 +62,18 @@ static inline int is_numeric_string(char *str, int length, long *lval, double *d
        long local_lval;
        double local_dval;
        char *end_ptr;
+       int conv_base=10;
 
        if (!length) {
                return 0;
        }
        
+       /* handle hex numbers */
+       if (length>=2 && str[0]=='0' && (str[1]=='x' || str[1]=='X')) {
+               conv_base=16;
+       }
        errno=0;
-       local_lval = strtol(str, &end_ptr, 10);
+       local_lval = strtol(str, &end_ptr, 16);
        if (errno!=ERANGE && end_ptr == str+length) { /* integer string */
                if (lval) {
                        *lval = local_lval;
@@ -76,6 +81,10 @@ static inline int is_numeric_string(char *str, int length, long *lval, double *d
                return IS_LONG;
        }
 
+       if (conv_base==16) { /* hex string, under UNIX strtod() messes it up */
+               return 0;
+       }
+
        errno=0;
        local_dval = strtod(str, &end_ptr);
        if (errno!=ERANGE && end_ptr == str+length) { /* floating point string */