diff options
author | Karl Williamson <khw@cpan.org> | 2019-12-07 13:47:05 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2019-12-18 09:33:09 -0700 |
commit | 4aada8b9eda25f3f024283c0c27c1424b5ba40ff (patch) | |
tree | 2c0ded2d593e998be054336ebf9648e4e18877fb /handy.h | |
parent | fcafb10c71dbfc03eacb02eeb0c567facc269a72 (diff) | |
download | perl-4aada8b9eda25f3f024283c0c27c1424b5ba40ff.tar.gz |
Add memCHRs() macro and use it
This replaces strchr("list", c) calls throughout the core. They don't
work properly when 'c' is a NUL, returning the position of the
terminating NUL in "list" instead of failure. This could lead to
segfaults or even security issues.
Diffstat (limited to 'handy.h')
-rw-r--r-- | handy.h | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -478,6 +478,13 @@ Like L</memNE>, but the second string is a literal enclosed in double quotes, C<l1> gives the number of bytes in C<s1>. Returns zero if non-equal, or zero if non-equal. +=for apidoc Am|bool|memCHRs|"list"|char c +Returns the position of the first occurence of the byte C<c> in the literal +string C<"list">, or NULL if C<c> doesn't appear in C<"list">. All bytes are +treated as unsigned char. Thus this macro can be used to determine if C<c> is +in a set of particular characters. Unlike L<strchr(3)>, it works even if C<c> +is C<NUL> (and the set doesn't include C<NUL>). + =cut New macros should use the following conventions for their names (which are @@ -569,6 +576,8 @@ based on the underlying C library functions): #define memGT(s1,s2,l) (memcmp(s1,s2,l) > 0) #define memGE(s1,s2,l) (memcmp(s1,s2,l) >= 0) +#define memCHRs(s1,c) ((const char *) memchr("" s1 "" , c, sizeof(s1)-1)) + /* * Character classes. * |