diff options
author | Karl Williamson <khw@cpan.org> | 2018-12-06 10:02:55 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2018-12-07 21:12:16 -0700 |
commit | 540fa6e13ee03c8b97e3406902f8bd4984eeec3f (patch) | |
tree | bfcc035f473b0b79806773cb0a66d9985ef5eb69 | |
parent | 8a100c918ec81926c0536594df8ee1fcccb171da (diff) | |
download | perl-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.h | 4 | ||||
-rw-r--r-- | regexec.c | 8 |
2 files changed, 6 insertions, 6 deletions
@@ -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 */ @@ -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 |