5151#define PHP_JSON_INT_MAX_LENGTH (MAX_LENGTH_OF_LONG - 1 )
5252
5353#define PHP_JSON_TOKEN_LENGTH () ((size_t ) (s->cursor - s->token))
54- #define PHP_JSON_TOKEN_LOCATION (location ) (s)->errloc.location
5554
5655static void php_json_scanner_copy_string (php_json_scanner *s, size_t esc_size)
5756{
@@ -96,10 +95,8 @@ void php_json_scanner_init(php_json_scanner *s, const char *str, size_t str_len,
9695 s->cursor = (php_json_ctype *) str;
9796 s->limit = (php_json_ctype *) str + str_len;
9897 s->options = options;
99- PHP_JSON_TOKEN_LOCATION (first_column) = 1 ;
100- PHP_JSON_TOKEN_LOCATION (first_line) = 1 ;
101- PHP_JSON_TOKEN_LOCATION (last_column) = 1 ;
102- PHP_JSON_TOKEN_LOCATION (last_line) = 1 ;
98+ s->line = 1 ;
99+ s->line_start = (php_json_ctype *) str;
103100 PHP_JSON_CONDITION_SET (JS );
104101}
105102
@@ -108,8 +105,6 @@ int php_json_scan(php_json_scanner *s)
108105 ZVAL_NULL (&s->value );
109106
110107std:
111- PHP_JSON_TOKEN_LOCATION (first_column) = s->errloc .last_column ;
112- PHP_JSON_TOKEN_LOCATION (first_line) = s->errloc .last_line ;
113108 s->token = s->cursor ;
114109
115110/* !re2c
@@ -155,49 +150,27 @@ std:
155150 UTF16_3 = UTFPREF ( ( ( HEXC | [efEF] ) HEX ) | ( [dD] HEX7 ) ) HEX{2} ;
156151 UTF16_4 = UTFPREF [dD] [89abAB] HEX{2} UTFPREF [dD] [c-fC-F] HEX{2} ;
157152
158- <JS>"{" {
159- PHP_JSON_TOKEN_LOCATION(last_column)++;
160- return '{';
161- }
162- <JS>"}" {
163- PHP_JSON_TOKEN_LOCATION(last_column)++;
164- return '}';
165- }
166- <JS>"[" {
167- PHP_JSON_TOKEN_LOCATION(last_column)++;
168- return '[';
169- }
170- <JS>"]" {
171- PHP_JSON_TOKEN_LOCATION(last_column)++;
172- return ']';
173- }
174- <JS>":" {
175- PHP_JSON_TOKEN_LOCATION(last_column)++;
176- return ':';
177- }
178- <JS>"," {
179- PHP_JSON_TOKEN_LOCATION(last_column)++;
180- return ',';
181- }
153+ <JS>"{" { return '{'; }
154+ <JS>"}" { return '}'; }
155+ <JS>"[" { return '['; }
156+ <JS>"]" { return ']'; }
157+ <JS>":" { return ':'; }
158+ <JS>"," { return ','; }
182159 <JS>"null" {
183- PHP_JSON_TOKEN_LOCATION(last_column) += 4;
184160 ZVAL_NULL(&s->value);
185161 return PHP_JSON_T_NUL;
186162 }
187163 <JS>"true" {
188- PHP_JSON_TOKEN_LOCATION(last_column) += 4;
189164 ZVAL_TRUE(&s->value);
190165 return PHP_JSON_T_TRUE;
191166 }
192167 <JS>"false" {
193- PHP_JSON_TOKEN_LOCATION(last_column) += 5;
194168 ZVAL_FALSE(&s->value);
195169 return PHP_JSON_T_FALSE;
196170 }
197171 <JS>INT {
198172 bool bigint = 0, negative = s->token[0] == '-';
199173 size_t digits = PHP_JSON_TOKEN_LENGTH();
200- PHP_JSON_TOKEN_LOCATION(last_column) += digits;
201174 digits -= negative;
202175 if (digits >= PHP_JSON_INT_MAX_LENGTH) {
203176 if (digits == PHP_JSON_INT_MAX_LENGTH) {
@@ -221,19 +194,15 @@ std:
221194 }
222195 }
223196 <JS>FLOAT|EXP {
224- PHP_JSON_TOKEN_LOCATION(last_column) += PHP_JSON_TOKEN_LENGTH();
225197 ZVAL_DOUBLE(&s->value, zend_strtod((char *) s->token, NULL));
226198 return PHP_JSON_T_DOUBLE;
227199 }
228200 <JS>NL {
229- PHP_JSON_TOKEN_LOCATION(last_line)++;
230- PHP_JSON_TOKEN_LOCATION(last_column) = 1;
231- goto std;
232- }
233- <JS>WS {
234- PHP_JSON_TOKEN_LOCATION(last_column) += PHP_JSON_TOKEN_LENGTH();
201+ s->line++;
202+ s->line_start = s->cursor;
235203 goto std;
236204 }
205+ <JS>WS { goto std; }
237206 <JS>EOI {
238207 if (s->limit < s->cursor) {
239208 return PHP_JSON_T_EOI;
243212 }
244213 }
245214 <JS>["] {
246- PHP_JSON_TOKEN_LOCATION(last_column)++;
247215 s->str_start = s->cursor;
248216 s->str_esc = 0;
249217 s->utf8_invalid = 0;
@@ -268,22 +236,18 @@ std:
268236 return PHP_JSON_T_ERROR;
269237 }
270238 <STR_P1>UTF16_1 {
271- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
272239 s->str_esc += 5;
273240 PHP_JSON_CONDITION_GOTO(STR_P1);
274241 }
275242 <STR_P1>UTF16_2 {
276- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
277243 s->str_esc += 4;
278244 PHP_JSON_CONDITION_GOTO(STR_P1);
279245 }
280246 <STR_P1>UTF16_3 {
281- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
282247 s->str_esc += 3;
283248 PHP_JSON_CONDITION_GOTO(STR_P1);
284249 }
285250 <STR_P1>UTF16_4 {
286- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
287251 s->str_esc += 8;
288252 PHP_JSON_CONDITION_GOTO(STR_P1);
289253 }
292256 return PHP_JSON_T_ERROR;
293257 }
294258 <STR_P1>ESC {
295- PHP_JSON_TOKEN_LOCATION(last_column) += 2;
296259 s->str_esc++;
297260 PHP_JSON_CONDITION_GOTO(STR_P1);
298261 }
301264 return PHP_JSON_T_ERROR;
302265 }
303266 <STR_P1>["] {
304- PHP_JSON_TOKEN_LOCATION(last_column)++;
305267 zend_string *str;
306268 size_t len = (size_t)(s->cursor - s->str_start - s->str_esc - 1 + s->utf8_invalid_count);
307269 if (len == 0) {
@@ -322,22 +284,7 @@ std:
322284 return PHP_JSON_T_STRING;
323285 }
324286 }
325- <STR_P1>UTF8_1 {
326- PHP_JSON_TOKEN_LOCATION(last_column)++;
327- PHP_JSON_CONDITION_GOTO(STR_P1);
328- }
329- <STR_P1>UTF8_2 {
330- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
331- PHP_JSON_CONDITION_GOTO(STR_P1);
332- }
333- <STR_P1>UTF8_3 {
334- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
335- PHP_JSON_CONDITION_GOTO(STR_P1);
336- }
337- <STR_P1>UTF8_4 {
338- PHP_JSON_TOKEN_LOCATION(last_column) += 1;
339- PHP_JSON_CONDITION_GOTO(STR_P1);
340- }
287+ <STR_P1>UTF8 { PHP_JSON_CONDITION_GOTO(STR_P1); }
341288 <STR_P1>ANY {
342289 if (s->options & (PHP_JSON_INVALID_UTF8_IGNORE | PHP_JSON_INVALID_UTF8_SUBSTITUTE)) {
343290 if (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) {
0 commit comments