Skip to content

Commit a4cdd52

Browse files
committed
ext/standard/scanf: convert format param to zend_string
In preparation for better format parsing
1 parent 89ac4f5 commit a4cdd52

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
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, return_value);
2497+
php_sscanf_internal(ZSTR_VAL(intern->u.file.current_line), format_str, num_varargs, varargs, return_value);
24982498
}
24992499
/* }}} */
25002500

ext/standard/file.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,16 +929,16 @@ PHPAPI PHP_FUNCTION(fgetc)
929929
PHP_FUNCTION(fscanf)
930930
{
931931
uint32_t argc = 0;
932-
size_t format_len;
933932
zval *args = NULL;
934933
zval *file_handle;
935-
char *buf, *format;
934+
char *buf;
935+
zend_string *format;
936936
size_t len;
937937
void *what;
938938

939939
ZEND_PARSE_PARAMETERS_START(2, -1)
940940
Z_PARAM_RESOURCE(file_handle)
941-
Z_PARAM_STRING(format, format_len)
941+
Z_PARAM_STR(format)
942942
Z_PARAM_VARIADIC('*', args, argc)
943943
ZEND_PARSE_PARAMETERS_END();
944944

ext/standard/scanf.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ static void ReleaseCharSet(CharSet *cset)
299299
*
300300
*----------------------------------------------------------------------
301301
*/
302-
static int ValidateFormat(const char *format, uint32_t numVars, uint32_t *totalSubs)
302+
static int ValidateFormat(const zend_string *zstr_format, uint32_t numVars, uint32_t *totalSubs)
303303
{
304304
#define STATIC_LIST_SIZE 16
305305
int flags;
@@ -325,6 +325,7 @@ static int ValidateFormat(const char *format, uint32_t numVars, uint32_t *totalS
325325
}
326326
memset(nassign, 0, sizeof(uint32_t)*numVars);
327327

328+
const char *format = ZSTR_VAL(zstr_format);
328329
while (*format != '\0') {
329330
ch = format++;
330331
flags = 0;
@@ -570,7 +571,7 @@ static int ValidateFormat(const char *format, uint32_t numVars, uint32_t *totalS
570571
* return_value set with the results of the scan
571572
*/
572573

573-
PHPAPI int php_sscanf_internal(const char *string, const char *format,
574+
PHPAPI int php_sscanf_internal(const char *string, const zend_string *zstr_format,
574575
uint32_t argCount, zval *args,
575576
zval *return_value)
576577
{
@@ -601,7 +602,7 @@ PHPAPI int php_sscanf_internal(const char *string, const char *format,
601602
* Check for errors in the format string.
602603
*/
603604
uint32_t totalVars = 0;
604-
if (ValidateFormat(format, numVars, &totalVars) != SCAN_SUCCESS) {
605+
if (ValidateFormat(zstr_format, numVars, &totalVars) != SCAN_SUCCESS) {
605606
scan_set_error_return( assignToVariables, return_value );
606607
return SCAN_ERROR_INVALID_FORMAT;
607608
}
@@ -646,6 +647,7 @@ PHPAPI int php_sscanf_internal(const char *string, const char *format,
646647
nconversions = 0;
647648
/* note ! - we need to limit the loop for objIndex to keep it in bounds */
648649

650+
const char *format = ZSTR_VAL(zstr_format);
649651
while (*format != '\0') {
650652
ch = format++;
651653
flags = 0;

ext/standard/scanf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* The following are here solely for the benefit of the scanf type functions
3434
* e.g. fscanf
3535
*/
36-
PHPAPI int php_sscanf_internal(const char *string, const char *format,uint32_t argCount,zval *args,
36+
PHPAPI int php_sscanf_internal(const char *string, const zend_string *format, uint32_t argCount, zval *args,
3737
zval *return_value);
3838

3939

ext/standard/string.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5860,13 +5860,14 @@ PHP_FUNCTION(str_pad)
58605860
PHP_FUNCTION(sscanf)
58615861
{
58625862
zval *args = NULL;
5863-
char *str, *format;
5864-
size_t str_len, format_len;
5863+
char *str;
5864+
size_t str_len;
5865+
zend_string *format;
58655866
uint32_t num_args = 0;
58665867

58675868
ZEND_PARSE_PARAMETERS_START(2, -1)
58685869
Z_PARAM_STRING(str, str_len)
5869-
Z_PARAM_STRING(format, format_len)
5870+
Z_PARAM_STR(format)
58705871
Z_PARAM_VARIADIC('*', args, num_args)
58715872
ZEND_PARSE_PARAMETERS_END();
58725873

0 commit comments

Comments
 (0)