Skip to content

Commit 9003847

Browse files
committed
ext/standard/scanf: use type uint32_t instead of int for variables in ValidateFormat()
1 parent a431568 commit 9003847

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

ext/standard/scanf.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,19 @@ static void ReleaseCharSet(CharSet *cset)
304304
*
305305
*----------------------------------------------------------------------
306306
*/
307-
static int ValidateFormat(char *format, int numVars, uint32_t *totalSubs)
307+
static int ValidateFormat(char *format, uint32_t numVars, uint32_t *totalSubs)
308308
{
309309
#define STATIC_LIST_SIZE 16
310-
int value, i, flags;
310+
int flags;
311311
bool gotXpg = false;
312312
bool gotSequential = false;
313313
char *end, *ch = NULL;
314-
int staticAssign[STATIC_LIST_SIZE];
315-
int *nassign = staticAssign;
316-
int objIndex, xpgSize, nspace = STATIC_LIST_SIZE;
314+
uint32_t staticAssign[STATIC_LIST_SIZE];
315+
uint32_t *nassign = staticAssign;
316+
uint32_t objIndex = 0;
317+
uint32_t xpgSize = 0;
318+
uint32_t nspace = STATIC_LIST_SIZE;
319+
zend_ulong value;
317320

318321
bool assignToVariables = numVars;
319322
/*
@@ -322,15 +325,13 @@ static int ValidateFormat(char *format, int numVars, uint32_t *totalSubs)
322325
* a variable is multiply assigned or left unassigned.
323326
*/
324327
if (numVars > nspace) {
325-
nassign = (int*)safe_emalloc(sizeof(int), numVars, 0);
328+
nassign = safe_emalloc(sizeof(uint32_t), numVars, 0);
326329
nspace = numVars;
327330
}
328331
for (i = 0; i < nspace; i++) {
329332
nassign[i] = 0;
330333
}
331334

332-
xpgSize = objIndex = 0;
333-
334335
while (*format != '\0') {
335336
ch = format++;
336337
flags = 0;
@@ -490,21 +491,21 @@ static int ValidateFormat(char *format, int numVars, uint32_t *totalSubs)
490491
* make sure that we grow to a large enough size. xpgSize is
491492
* guaranteed to be at least one larger than objIndex.
492493
*/
493-
value = nspace;
494+
uint32_t value = nspace;
494495
if (xpgSize) {
495496
nspace = xpgSize;
496497
} else {
497498
nspace += STATIC_LIST_SIZE;
498499
}
499500
if (nassign == staticAssign) {
500501
nassign = (void *)safe_emalloc(nspace, sizeof(int), 0);
501-
for (i = 0; i < STATIC_LIST_SIZE; ++i) {
502+
for (uint32_t i = 0; i < STATIC_LIST_SIZE; ++i) {
502503
nassign[i] = staticAssign[i];
503504
}
504505
} else {
505506
nassign = (void *)erealloc((void *)nassign, nspace * sizeof(int));
506507
}
507-
for (i = value; i < nspace; i++) {
508+
for (uint32_t i = value; i < nspace; i++) {
508509
nassign[i] = 0;
509510
}
510511
}
@@ -526,7 +527,7 @@ static int ValidateFormat(char *format, int numVars, uint32_t *totalSubs)
526527

527528
*totalSubs = numVars;
528529

529-
for (i = 0; i < numVars; i++) {
530+
for (uint32_t i = 0; i < numVars; i++) {
530531
if (nassign[i] > 1) {
531532
zend_value_error("%s", "Variable is assigned by multiple \"%n$\" conversion specifiers");
532533
goto error;

0 commit comments

Comments
 (0)