mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Fix autoconversion of hexadecimal strings
It's time to close bug #5404 :)
This commit is contained in:
parent
dc30520622
commit
cd033b1271
1 changed files with 10 additions and 1 deletions
|
@ -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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue