Skip to content

Commit 8660497

Browse files
committed
ext/standard/scanf: add const qualifiers in BuildCharSet() and ValidateFormat()
1 parent 66733bb commit 8660497

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

ext/standard/scanf.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ static inline void scan_set_error_return(bool assignToVariables, zval *return_va
131131
*/
132132
static char * BuildCharSet(CharSet *cset, char *format)
133133
{
134-
char *ch, start;
134+
const char *ch;
135135
int nranges;
136-
char *end;
136+
const char *end;
137137

138138
memset(cset, 0, sizeof(CharSet));
139139

@@ -170,7 +170,7 @@ static char * BuildCharSet(CharSet *cset, char *format)
170170
*/
171171
cset->nchars = cset->nranges = 0;
172172
ch = format++;
173-
start = *ch;
173+
char start = *ch;
174174
if (*ch == ']' || *ch == '-') {
175175
cset->chars[cset->nchars++] = *ch;
176176
ch = format++;
@@ -299,13 +299,13 @@ static void ReleaseCharSet(CharSet *cset)
299299
*
300300
*----------------------------------------------------------------------
301301
*/
302-
static int ValidateFormat(char *format, uint32_t numVars, uint32_t *totalSubs)
302+
static int ValidateFormat(const char *format, uint32_t numVars, uint32_t *totalSubs)
303303
{
304304
#define STATIC_LIST_SIZE 16
305305
int flags;
306306
bool gotXpg = false;
307307
bool gotSequential = false;
308-
char *end, *ch = NULL;
308+
const char *ch = NULL;
309309
uint32_t staticAssign[STATIC_LIST_SIZE];
310310
uint32_t *nassign = staticAssign;
311311
uint32_t objIndex = 0;
@@ -348,6 +348,7 @@ static int ValidateFormat(char *format, uint32_t numVars, uint32_t *totalSubs)
348348
* must not be a mixture of XPG3 specs and non-XPG3 specs
349349
* in the same format string.
350350
*/
351+
char *end = NULL;
351352
value = ZEND_STRTOUL(format-1, &end, 10);
352353
if (*end != '$') {
353354
goto notXpg;
@@ -395,8 +396,10 @@ static int ValidateFormat(char *format, uint32_t numVars, uint32_t *totalSubs)
395396
* Parse any width specifier.
396397
*/
397398
if (isdigit(UCHAR(*ch))) {
398-
value = ZEND_STRTOUL(format-1, &format, 10);
399+
char *end = NULL;
400+
value = ZEND_STRTOUL(format-1, &end, 10);
399401
flags |= SCAN_WIDTH;
402+
format = end;
400403
ch = format++;
401404
}
402405

0 commit comments

Comments
 (0)