summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2018-12-06 10:02:55 -0700
committerKarl Williamson <khw@cpan.org>2018-12-07 21:12:16 -0700
commit540fa6e13ee03c8b97e3406902f8bd4984eeec3f (patch)
treebfcc035f473b0b79806773cb0a66d9985ef5eb69
parent8a100c918ec81926c0536594df8ee1fcccb171da (diff)
downloadperl-540fa6e13ee03c8b97e3406902f8bd4984eeec3f.tar.gz
regexec.c: Use mnemonics instead of "256"
There are only three valid numbers in Computer Science: 0, 1, and "as many as you like". 256 is not therefore a valid number, and its use should be commented, or better, a mnemonic used instead. These uses were spotted by lgtm as being unnecessary, and some people were confused as to their purpose. This commit changes the 256, to in one case, a sizeof() that indicates its a guard against going outside the array bounds of that data structure. And in the 2nd case, it verifies that it fits inside the space allotted to a function parameter. A comment helps clarify that.
-rw-r--r--perl.h4
-rw-r--r--regexec.c8
2 files changed, 6 insertions, 6 deletions
diff --git a/perl.h b/perl.h
index e436e03899..c04ccc0f5d 100644
--- a/perl.h
+++ b/perl.h
@@ -4690,7 +4690,7 @@ EXTCONST unsigned char PL_latin1_lc[];
#ifndef PERL_GLOBAL_STRUCT /* or perlvars.h */
#ifdef DOINIT
-EXT unsigned char PL_fold_locale[] = { /* Unfortunately not EXTCONST. */
+EXT unsigned char PL_fold_locale[256] = { /* Unfortunately not EXTCONST. */
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
@@ -4725,7 +4725,7 @@ EXT unsigned char PL_fold_locale[] = { /* Unfortunately not EXTCONST. */
248, 249, 250, 251, 252, 253, 254, 255
};
#else
-EXT unsigned char PL_fold_locale[]; /* Unfortunately not EXTCONST. */
+EXT unsigned char PL_fold_locale[256]; /* Unfortunately not EXTCONST. */
#endif
#endif /* !PERL_GLOBAL_STRUCT */
diff --git a/regexec.c b/regexec.c
index eb24567e04..dc5131b0da 100644
--- a/regexec.c
+++ b/regexec.c
@@ -9772,14 +9772,14 @@ S_reginclass(pTHX_ regexp * const prog, const regnode * const n, const U8* const
match = TRUE;
}
else if (flags & ANYOF_LOCALE_FLAGS) {
- if ((flags & ANYOFL_FOLD)
- && c < 256
+ if ( (flags & ANYOFL_FOLD)
+ && c < sizeof(PL_fold_locale)
&& ANYOF_BITMAP_TEST(n, PL_fold_locale[c]))
{
match = TRUE;
}
- else if (ANYOF_POSIXL_TEST_ANY_SET(n)
- && c < 256
+ else if ( ANYOF_POSIXL_TEST_ANY_SET(n)
+ && c <= U8_MAX /* param to isFOO_lc() */
) {
/* The data structure is arranged so bits 0, 2, 4, ... are set