Skip to content

Commit 41d4456

Browse files
committed
ext/standard/scanf: remove varStart parameter which is always 0
And remove relevant now useless sanity checks
1 parent acf692c commit 41d4456

File tree

5 files changed

+8
-14
lines changed

5 files changed

+8
-14
lines changed

ext/spl/spl_directory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2494,7 +2494,7 @@ PHP_METHOD(SplFileObject, fscanf)
24942494
RETURN_THROWS();
24952495
}
24962496

2497-
php_sscanf_internal(ZSTR_VAL(intern->u.file.current_line), ZSTR_VAL(format_str), num_varargs, varargs, 0, return_value);
2497+
php_sscanf_internal(ZSTR_VAL(intern->u.file.current_line), ZSTR_VAL(format_str), num_varargs, varargs, return_value);
24982498
}
24992499
/* }}} */
25002500

ext/standard/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ PHP_FUNCTION(fscanf)
956956
RETURN_FALSE;
957957
}
958958

959-
php_sscanf_internal(buf, format, argc, args, 0, return_value);
959+
php_sscanf_internal(buf, format, argc, args, return_value);
960960

961961
efree(buf);
962962
}

ext/standard/scanf.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,12 @@ static int ValidateFormat(char *format, int numVars, int *totalSubs)
567567
* format format string
568568
* argCount total number of elements in the args array
569569
* args arguments passed in from user function (f|s)scanf
570-
* varStart offset (in args) of 1st variable passed in to (f|s)scanf
571570
* return_value set with the results of the scan
572571
*/
573572

574573
PHPAPI int php_sscanf_internal( char *string, char *format,
575574
uint32_t argCount, zval *args,
576-
int varStart, zval *return_value)
575+
zval *return_value)
577576
{
578577
int numVars, nconversions, totalVars = -1;
579578
int i, result;
@@ -591,11 +590,7 @@ PHPAPI int php_sscanf_internal( char *string, char *format,
591590
char buf[64]; /* Temporary buffer to hold scanned number
592591
* strings before they are passed to strtoul() */
593592

594-
/* do some sanity checking */
595-
if ((varStart > argCount) || (varStart < 0)){
596-
varStart = SCAN_MAX_ARGS + 1;
597-
}
598-
numVars = argCount - varStart;
593+
numVars = argCount;
599594
if (numVars < 0) {
600595
numVars = 0;
601596
}
@@ -608,13 +603,13 @@ PHPAPI int php_sscanf_internal( char *string, char *format,
608603
return SCAN_ERROR_INVALID_FORMAT;
609604
}
610605

611-
objIndex = numVars ? varStart : 0;
606+
objIndex = 0;
612607

613608
/*
614609
* If any variables are passed, make sure they are all passed by reference
615610
*/
616611
if (numVars) {
617-
for (i = varStart;i < argCount;i++){
612+
for (i = 0; i < argCount; i++){
618613
ZEND_ASSERT(Z_ISREF(args[i]) && "Parameter must be passed by reference");
619614
}
620615
}
@@ -636,7 +631,6 @@ PHPAPI int php_sscanf_internal( char *string, char *format,
636631
return FAILURE;
637632
}
638633
}
639-
varStart = 0; /* Array index starts from 0 */
640634
}
641635

642636
baseString = string;

ext/standard/scanf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* e.g. fscanf
3535
*/
3636
PHPAPI int php_sscanf_internal(char *string,char *format,uint32_t argCount,zval *args,
37-
int varStart, zval *return_value);
37+
zval *return_value);
3838

3939

4040
#endif /* SCANF_H */

ext/standard/string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5870,7 +5870,7 @@ PHP_FUNCTION(sscanf)
58705870
Z_PARAM_VARIADIC('*', args, num_args)
58715871
ZEND_PARSE_PARAMETERS_END();
58725872

5873-
php_sscanf_internal(str, format, num_args, args, 0, return_value);
5873+
php_sscanf_internal(str, format, num_args, args, return_value);
58745874

58755875
}
58765876
/* }}} */

0 commit comments

Comments
 (0)