Skip to content

Commit d40ae97

Browse files
authored
Zend language scanner: minor refactorings (#20480)
* Use uint32_t type * Remove some useless size_t casts * Explain why we include zend_globals.h
1 parent d026e2b commit d40ae97

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Zend/zend_language_scanner.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef ZEND_SCANNER_H
2121
#define ZEND_SCANNER_H
2222

23+
/* The zend_php_scanner_event enum is declared in zend_globals and we don't want everything to include zend_language_scanner.h */
2324
#include "zend_globals.h"
2425

2526
typedef struct _zend_lex_state {
@@ -71,7 +72,7 @@ typedef struct _zend_heredoc_label {
7172
/* Track locations of unclosed {, [, (, etc. for better syntax error reporting */
7273
typedef struct _zend_nest_location {
7374
char text;
74-
int lineno;
75+
uint32_t lineno;
7576
} zend_nest_location;
7677

7778
BEGIN_EXTERN_C()

Zend/zend_language_scanner.l

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "zend_language_scanner_defs.h"
3131

3232
#include <errno.h>
33+
#include <stdint.h>
3334
#include "zend.h"
3435
#ifdef ZEND_WIN32
3536
# include <Winuser.h>
@@ -600,7 +601,7 @@ static zend_op_array *zend_compile(int type)
600601
CG(ast_arena) = zend_arena_create(1024 * 32);
601602

602603
if (!zendparse()) {
603-
int last_lineno = CG(zend_lineno);
604+
uint32_t last_lineno = CG(zend_lineno);
604605
zend_file_context original_file_context;
605606
zend_oparray_context original_oparray_context;
606607
zend_op_array *original_active_op_array = CG(active_op_array);
@@ -1140,7 +1141,7 @@ skip_escape_conversion:
11401141
unsigned char *str;
11411142
// TODO: avoid realocation ???
11421143
s = Z_STRVAL_P(zendlval);
1143-
SCNG(output_filter)(&str, &sz, (unsigned char *)s, (size_t)Z_STRLEN_P(zendlval));
1144+
SCNG(output_filter)(&str, &sz, (unsigned char *)s, Z_STRLEN_P(zendlval));
11441145
zval_ptr_dtor(zendlval);
11451146
ZVAL_STRINGL(zendlval, (char *) str, sz);
11461147
efree(str);
@@ -1172,7 +1173,7 @@ static bool strip_multiline_string_indentation(
11721173
const char *str = Z_STRVAL_P(zendlval), *end = str + Z_STRLEN_P(zendlval);
11731174
char *copy = Z_STRVAL_P(zendlval);
11741175

1175-
int newline_count = 0;
1176+
uint32_t newline_count = 0;
11761177
size_t newline_len;
11771178
const char *nl;
11781179

@@ -1253,7 +1254,7 @@ static void copy_heredoc_label_stack(void *void_heredoc_label)
12531254
}
12541255

12551256
/* Check that { }, [ ], ( ) are nested correctly */
1256-
static void report_bad_nesting(char opening, int opening_lineno, char closing)
1257+
static void report_bad_nesting(char opening, uint32_t opening_lineno, char closing)
12571258
{
12581259
char buf[256];
12591260
size_t used = 0;
@@ -1361,7 +1362,7 @@ int ZEND_FASTCALL lex_scan(zval *zendlval, zend_parser_stack_elem *elem)
13611362
{
13621363
int token;
13631364
int offset;
1364-
int start_line = CG(zend_lineno);
1365+
uint32_t start_line = CG(zend_lineno);
13651366

13661367
ZVAL_UNDEF(zendlval);
13671368
restart:
@@ -2499,7 +2500,7 @@ inline_char_handler:
24992500
if (YYCURSOR < YYLIMIT) {
25002501
YYCURSOR++;
25012502
} else {
2502-
zend_throw_exception_ex(zend_ce_parse_error, 0, "Unterminated comment starting line %d", CG(zend_lineno));
2503+
zend_throw_exception_ex(zend_ce_parse_error, 0, "Unterminated comment starting line %" PRIu32, CG(zend_lineno));
25032504
if (PARSER_MODE()) {
25042505
RETURN_TOKEN(T_ERROR);
25052506
}
@@ -2616,7 +2617,7 @@ skip_escape_conversion:
26162617
zend_string *new_str;
26172618
s = Z_STRVAL_P(zendlval);
26182619
// TODO: avoid reallocation ???
2619-
SCNG(output_filter)((unsigned char **)&str, &sz, (unsigned char *)s, (size_t)Z_STRLEN_P(zendlval));
2620+
SCNG(output_filter)((unsigned char **)&str, &sz, (unsigned char *)s, Z_STRLEN_P(zendlval));
26202621
new_str = zend_string_init(str, sz, 0);
26212622
if (str != s) {
26222623
efree(str);

0 commit comments

Comments
 (0)