Skip to content

Commit ed152e1

Browse files
committed
Revert "toke.c: Change S_scan_word parameter"
This essentially reverts commit 9f0a1b6. But instead of reverting to the sizeof() formerly used, it keeps the spirit of the reverted commit, changing C_ARRAY_END() calls to instead C_ARRAY_LENGTH() Fixes #23828
1 parent d9c4e67 commit ed152e1

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

embed.fnc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3142,8 +3142,8 @@ Adp |char * |scan_vstring |SPTR const char *s \
31423142
|EPTR const char * const e \
31433143
|NN SV *sv
31443144
EXpx |char * |scan_word |NN char *s \
3145-
|SPTR char *dest \
3146-
|EPTR char *dest_end \
3145+
|NN char *dest \
3146+
|STRLEN destlen \
31473147
|int allow_package \
31483148
|NN STRLEN *slp
31493149
Cp |U32 |seed

proto.h

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

toke.c

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,8 +2275,7 @@ S_force_word(pTHX_ char *start, int token, int check_keyword, int allow_pack)
22752275
if ( isIDFIRST_lazy_if_safe(s, PL_bufend, UTF)
22762276
|| (allow_pack && *s == ':' && s[1] == ':') )
22772277
{
2278-
s = scan_word(s,
2279-
PL_tokenbuf, C_ARRAY_END(PL_tokenbuf),
2278+
s = scan_word(s, PL_tokenbuf, C_ARRAY_LENGTH(PL_tokenbuf),
22802279
allow_pack, &len);
22812280
if (check_keyword) {
22822281
char *s2 = PL_tokenbuf;
@@ -4813,7 +4812,7 @@ S_intuit_method(pTHX_ char *start, SV *ioname, CV *cv)
48134812
return *s == '(' ? METHCALL : METHCALL0;
48144813
}
48154814

4816-
s = scan_word(s, tmpbuf, C_ARRAY_END(tmpbuf), TRUE, &len);
4815+
s = scan_word(s, tmpbuf, C_ARRAY_LENGTH(tmpbuf), TRUE, &len);
48174816
/* start is the beginning of the possible filehandle/object,
48184817
* and s is the end of it
48194818
* tmpbuf is a copy of it (but with single quotes as double colons)
@@ -5451,7 +5450,7 @@ yyl_dollar(pTHX_ char *s)
54515450
} while (isSPACE(*t));
54525451
if (isIDFIRST_lazy_if_safe(t, PL_bufend, UTF)) {
54535452
STRLEN len;
5454-
t = scan_word(t, tmpbuf, C_ARRAY_END(tmpbuf), TRUE, &len);
5453+
t = scan_word(t, tmpbuf, C_ARRAY_LENGTH(tmpbuf), TRUE, &len);
54555454
while (isSPACE(*t))
54565455
t++;
54575456
if ( *t == ';'
@@ -5484,7 +5483,7 @@ yyl_dollar(pTHX_ char *s)
54845483
char tmpbuf[C_ARRAY_LENGTH(PL_tokenbuf)];
54855484
int t2;
54865485
STRLEN len;
5487-
scan_word(s, tmpbuf, C_ARRAY_END(tmpbuf), TRUE, &len);
5486+
scan_word(s, tmpbuf, C_ARRAY_LENGTH(tmpbuf), TRUE, &len);
54885487
if ((t2 = keyword(tmpbuf, len, 0))) {
54895488
/* binary operators exclude handle interpretations */
54905489
switch (t2) {
@@ -5555,7 +5554,7 @@ yyl_sub(pTHX_ char *s, const int key)
55555554
{
55565555

55575556
PL_expect = XATTRBLOCK;
5558-
d = scan_word(s, tmpbuf, C_ARRAY_END(PL_tokenbuf), TRUE, &len);
5557+
d = scan_word(s, tmpbuf, C_ARRAY_LENGTH(PL_tokenbuf) - 1, TRUE, &len);
55595558
if (key == KEY_format)
55605559
format_name = S_newSV_maybe_utf8(aTHX_ s, d - s);
55615560
*PL_tokenbuf = '&';
@@ -6162,8 +6161,7 @@ yyl_colon(pTHX_ char *s)
61626161
I32 tmp;
61636162
SV *sv;
61646163
STRLEN len;
6165-
char *d = scan_word(s,
6166-
PL_tokenbuf, C_ARRAY_END(PL_tokenbuf),
6164+
char *d = scan_word(s, PL_tokenbuf, C_ARRAY_LENGTH(PL_tokenbuf),
61676165
FALSE, &len);
61686166
if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
61696167
if (tmp < 0) tmp = -tmp;
@@ -6343,8 +6341,7 @@ yyl_leftcurly(pTHX_ char *s, const U8 formbrack)
63436341
}
63446342
if (d < PL_bufend && isIDFIRST_lazy_if_safe(d, PL_bufend, UTF)) {
63456343
STRLEN len;
6346-
d = scan_word(d,
6347-
PL_tokenbuf + 1, C_ARRAY_END(PL_tokenbuf),
6344+
d = scan_word(d, PL_tokenbuf + 1, C_ARRAY_LENGTH(PL_tokenbuf) - 1,
63486345
FALSE, &len);
63496346
while (d < PL_bufend && SPACE_OR_TAB(*d))
63506347
d++;
@@ -7162,8 +7159,7 @@ yyl_foreach(pTHX_ char *s)
71627159
/* skip optional package name, as in "for my abc $x (..)" */
71637160
if (UNLIKELY(isIDFIRST_lazy_if_safe(p, PL_bufend, UTF))) {
71647161
STRLEN len;
7165-
p = scan_word(p,
7166-
PL_tokenbuf, C_ARRAY_END(PL_tokenbuf),
7162+
p = scan_word(p, PL_tokenbuf, C_ARRAY_LENGTH(PL_tokenbuf),
71677163
TRUE, &len);
71687164
p = skipspace(p);
71697165
paren_is_valid = FALSE;
@@ -7193,8 +7189,7 @@ yyl_do(pTHX_ char *s, I32 orig_keyword)
71937189
char *d;
71947190
STRLEN len;
71957191
*PL_tokenbuf = '&';
7196-
d = scan_word(s,
7197-
PL_tokenbuf + 1, C_ARRAY_END(PL_tokenbuf),
7192+
d = scan_word(s, PL_tokenbuf + 1, C_ARRAY_LENGTH(PL_tokenbuf) - 1,
71987193
1, &len);
71997194
if (len && memNEs(PL_tokenbuf+1, len, "CORE")
72007195
&& !keyword(PL_tokenbuf + 1, len, 0)) {
@@ -7250,9 +7245,7 @@ yyl_my(pTHX_ char *s, I32 my)
72507245
s = skipspace(s);
72517246
if (isIDFIRST_lazy_if_safe(s, PL_bufend, UTF)) {
72527247
STRLEN len;
7253-
s = scan_word(s,
7254-
PL_tokenbuf, C_ARRAY_END(PL_tokenbuf),
7255-
TRUE, &len);
7248+
s = scan_word(s, PL_tokenbuf, C_ARRAY_LENGTH(PL_tokenbuf), TRUE, &len);
72567249
if (memEQs(PL_tokenbuf, len, "sub"))
72577250
/* my sub ... */
72587251
return yyl_sub(aTHX_ s, my);
@@ -7727,8 +7720,7 @@ yyl_just_a_word(pTHX_ char *s, STRLEN len, I32 orig_keyword, struct code c)
77277720
if ((*s == '\'' && FEATURE_APOS_AS_NAME_SEP_IS_ENABLED)
77287721
|| (*s == ':' && s[1] == ':')) {
77297722
STRLEN morelen;
7730-
s = scan_word(s,
7731-
PL_tokenbuf + len, C_ARRAY_END(PL_tokenbuf),
7723+
s = scan_word(s, PL_tokenbuf + len, C_ARRAY_LENGTH(PL_tokenbuf) - len,
77327724
TRUE, &morelen);
77337725
if (no_op_error) {
77347726
S_warn_expect_operator(aTHX_ "Bareword",s,FALSE);
@@ -8480,8 +8472,7 @@ yyl_word_or_keyword(pTHX_ char *s, STRLEN len, I32 key, I32 orig_keyword, struct
84808472
s = skipspace(s);
84818473
if (isIDFIRST_lazy_if_safe(s, PL_bufend, UTF)) {
84828474
const char *t;
8483-
char *d = scan_word(s,
8484-
PL_tokenbuf, C_ARRAY_END(PL_tokenbuf),
8475+
char *d = scan_word(s, PL_tokenbuf, C_ARRAY_LENGTH(PL_tokenbuf),
84858476
FALSE, &len);
84868477
for (t=d; isSPACE(*t);)
84878478
t++;
@@ -8915,7 +8906,7 @@ yyl_key_core(pTHX_ char *s, STRLEN len, struct code c)
89158906
STRLEN olen = len;
89168907
char *d = s;
89178908
s += 2;
8918-
s = scan_word(s, PL_tokenbuf, C_ARRAY_END(PL_tokenbuf), FALSE, &len);
8909+
s = scan_word(s, PL_tokenbuf, C_ARRAY_LENGTH(PL_tokenbuf), FALSE, &len);
89198910
if ((*s == ':' && s[1] == ':')
89208911
|| (!(key = keyword(PL_tokenbuf, len, 1)) && *s == '\'' &&
89218912
FEATURE_APOS_AS_NAME_SEP_IS_ENABLED))
@@ -8995,7 +8986,7 @@ yyl_keylookup(pTHX_ char *s, GV *gv)
89958986
c.gv = gv;
89968987

89978988
PL_bufptr = s;
8998-
s = scan_word(s, PL_tokenbuf, C_ARRAY_END(PL_tokenbuf), FALSE, &len);
8989+
s = scan_word(s, PL_tokenbuf, C_ARRAY_LENGTH(PL_tokenbuf), FALSE, &len);
89998990

90008991
/* Some keywords can be followed by any delimiter, including ':' */
90018992
anydelim = word_takes_any_delimiter(PL_tokenbuf, len);
@@ -10351,12 +10342,12 @@ S_parse_ident(pTHX_ char **s, char **d, char * const e, int allow_package,
1035110342
}
1035210343

1035310344
char *
10354-
Perl_scan_word(pTHX_ char *s, char *dest, char * dest_end, int allow_package, STRLEN *slp)
10345+
Perl_scan_word(pTHX_ char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
1035510346
{
1035610347
PERL_ARGS_ASSERT_SCAN_WORD;
1035710348

1035810349
char *d = dest;
10359-
char * const e = dest_end - 3; /* two-character token, ending NUL */
10350+
char * const e = d + destlen - 3; /* two-character token, ending NUL */
1036010351
bool is_utf8 = cBOOL(UTF);
1036110352

1036210353
parse_ident(&s, &d, e, allow_package, is_utf8, TRUE);
@@ -13825,7 +13816,8 @@ Perl_parse_label(pTHX_ U32 flags)
1382513816
t = s = PL_bufptr;
1382613817
if (!isIDFIRST_lazy_if_safe(s, PL_bufend, UTF))
1382713818
goto no_label;
13828-
t = scan_word(s, PL_tokenbuf, C_ARRAY_END(PL_tokenbuf), FALSE, &wlen);
13819+
t = scan_word(s, PL_tokenbuf, C_ARRAY_LENGTH(PL_tokenbuf),
13820+
FALSE, &wlen);
1382913821
if (word_takes_any_delimiter(s, wlen))
1383013822
goto no_label;
1383113823
bufptr_pos = s - SvPVX(PL_linestr);

0 commit comments

Comments
 (0)