com php-src: fixed *scanf() family: Zend/zend_int.h ext/s tandard/scanf.c
| From: | Anatol Belski | Date: | Sun, 10 Nov 2013 17:59:07 +0000 |
| Subject: | com php-src: fixed *scanf() family: Zend/zend_int.h ext/s tandard/scanf.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-73924@lists.php.net to get a copy of this message | ||
Commit: 57ce464a1c335602bccb1c7b73e97189d745c6a0
Author: Anatol Belski <ab@php.net> Sun, 10 Nov 2013 18:59:07 +0100
Parents: 094c93b6f8685e16484f7105f38d9a5afb564904
Branches: str_size_and_int64
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=57ce464a1c335602bccb1c7b73e97189d745c6a0
Log:
fixed *scanf() family
Changed paths:
M Zend/zend_int.h
M ext/standard/scanf.c
Diff:
diff --git a/Zend/zend_int.h b/Zend/zend_int.h
index 62121c3..ae15ce7 100644
--- a/Zend/zend_int.h
+++ b/Zend/zend_int.h
@@ -51,8 +51,11 @@ typedef unsigned long zend_uint_t;
# define ZEND_ITOA(i, s, len) _i64toa_s((i), (s), (len), 10)
# define ZEND_ATOI(i, s) i = _atoi64((s))
# define ZEND_STRTOL(s0, s1, base) _strtoi64((s0), (s1), (base))
+# define ZEND_STRTOUL(s0, s1, base) _strtoui64((s0), (s1), (base))
# define ZEND_INT_FMT "%I64d"
# define ZEND_UINT_FMT "%I64u"
+# define ZEND_STRTOL_PTR _strtoi64
+# define ZEND_STRTOUL_PTR _strtoui64
# else
# define ZEND_ITOA(i, s, len) \
do { \
@@ -61,11 +64,15 @@ typedef unsigned long zend_uint_t;
} while (0)
# define ZEND_ATOI(i, s) (i) = atoll((s))
# define ZEND_STRTOL(s0, s1, base) strtoll((s0), (s1), (base))
+# define ZEND_STRTOUL(s0, s1, base) strtoull((s0), (s1), (base))
# define ZEND_INT_FMT "%lld"
# define ZEND_UINT_FMT "%llu"
+# define ZEND_STRTOL_PTR strtoll
+# define ZEND_STRTOUL_PTR strtoull
# endif
#else
# define ZEND_STRTOL(s0, s1, base) strtol((s0), (s1), (base))
+# define ZEND_STRTOUL(s0, s1, base) strtoul((s0), (s1), (base))
# ifdef PHP_WIN32
# define ZEND_ITOA(i, s, len) _ltoa_s((i), (s), (len), 10)
# define ZEND_ATOI(i, s) i = atol((s))
@@ -79,6 +86,8 @@ typedef unsigned long zend_uint_t;
# endif
# define ZEND_INT_FMT "%ld"
# define ZEND_UINT_FMT "%lu"
+# define ZEND_STRTOL_PTR strtol
+# define ZEND_STRTOUL_PTR strtoul
#endif
diff --git a/ext/standard/scanf.c b/ext/standard/scanf.c
index 02e2c71..57277b7 100644
--- a/ext/standard/scanf.c
+++ b/ext/standard/scanf.c
@@ -356,7 +356,7 @@ PHPAPI int ValidateFormat(char *format, int numVars, int *totalSubs)
* must not be a mixture of XPG3 specs and non-XPG3 specs
* in the same format string.
*/
- value = strtoul(format-1, &end, 10);
+ value = ZEND_STRTOUL(format-1, &end, 10);
if (*end != '$') {
goto notXpg;
}
@@ -403,7 +403,7 @@ xpgCheckDone:
* Parse any width specifier.
*/
if (isdigit(UCHAR(*ch))) {
- value = strtoul(format-1, &format, 10);
+ value = ZEND_STRTOUL(format-1, &format, 10);
flags |= SCAN_WIDTH;
ch = format++;
}
@@ -582,7 +582,7 @@ PHPAPI int php_sscanf_internal( char *string, char *format,
{
int numVars, nconversions, totalVars = -1;
int i, result;
- long value;
+ php_int_t value;
int objIndex;
char *end, *baseString;
zval **current;
@@ -590,11 +590,11 @@ PHPAPI int php_sscanf_internal( char *string, char *format,
int base = 0;
int underflow = 0;
size_t width;
- long (*fn)() = NULL;
+ php_int_t (*fn)() = NULL;
char *ch, sch;
int flags;
char buf[64]; /* Temporary buffer to hold scanned number
- * strings before they are passed to strtoul() */
+ * strings before they are passed to ZEND_STRTOUL() */
/* do some sanity checking */
if ((varStart > argCount) || (varStart < 0)){
@@ -709,7 +709,7 @@ literal:
flags |= SCAN_SUPPRESS;
ch = format++;
} else if ( isdigit(UCHAR(*ch))) {
- value = strtoul(format-1, &end, 10);
+ value = ZEND_STRTOUL(format-1, &end, 10);
if (*end == '$') {
format = end+1;
ch = format++;
@@ -721,7 +721,7 @@ literal:
* Parse any width specifier.
*/
if ( isdigit(UCHAR(*ch))) {
- width = strtoul(format-1, &format, 10);
+ width = ZEND_STRTOUL(format-1, &format, 10);
ch = format++;
} else {
width = 0;
@@ -748,7 +748,7 @@ literal:
current = args[objIndex++];
refcount = Z_REFCOUNT_PP(current);
zval_dtor( *current );
- ZVAL_LONG( *current, (long)(string - baseString) );
+ ZVAL_LONG( *current, (php_int_t)(string - baseString) );
Z_SET_REFCOUNT_PP(current, refcount);
Z_SET_ISREF_PP(current);
} else {
@@ -762,29 +762,29 @@ literal:
case 'D':
op = 'i';
base = 10;
- fn = (long (*)())strtol;
+ fn = (php_int_t (*)())ZEND_STRTOL_PTR;
break;
case 'i':
op = 'i';
base = 0;
- fn = (long (*)())strtol;
+ fn = (php_int_t (*)())ZEND_STRTOL_PTR;
break;
case 'o':
op = 'i';
base = 8;
- fn = (long (*)())strtol;
+ fn = (php_int_t (*)())ZEND_STRTOL_PTR;
break;
case 'x':
case 'X':
op = 'i';
base = 16;
- fn = (long (*)())strtol;
+ fn = (php_int_t (*)())ZEND_STRTOL_PTR;
break;
case 'u':
op = 'i';
base = 10;
flags |= SCAN_UNSIGNED;
- fn = (long (*)())strtoul;
+ fn = (php_int_t (*)())ZEND_STRTOUL_PTR;
break;
case 'f':
@@ -1060,9 +1060,9 @@ addToInt:
*/
if (!(flags & SCAN_SUPPRESS)) {
*end = '\0';
- value = (long) (*fn)(buf, NULL, base);
+ value = (php_int_t) (*fn)(buf, NULL, base);
if ((flags & SCAN_UNSIGNED) && (value < 0)) {
- snprintf(buf, sizeof(buf), "%lu", value); /* INTL: ISO digit */
+ snprintf(buf, sizeof(buf), ZEND_UINT_FMT, value); /* INTL: ISO digit */
if (numVars && objIndex >= argCount) {
break;
} else if (numVars) {