Commit 9eac113
committed
util.h: fix broken casts in Perl_instr() parameters
Why broken? Because haystack/needle are effectively macros (they expand
to token sequences), so a call like
Perl_instr(a + b, x ? y : z)
expands to
strstr((char *)a + b, (char *)x ? y : z)
which is just wrong.
Normally I'd simply add the missing parentheses ((char *)(haystack),
etc), but it's not clear to me why the casts were added in the first
place (and fairly recently, too, in commit 4e52881).
Background:
instr() was originally implemented in pre-standard C (without const and
without a prototype) in util.c, perl-1.0. The consts were added fairly
early on in 08105a9 (1997): char *
instr(register const char *big, register const char *little);
The hand-written C code was replaced by a call to strstr() in
5d1d68e. It cast away const from the arguments to strstr() for no
reason I can see: strstr() takes pointers to const char (just like
Perl_instr), so the pointers were immediately implicitly re-consted by
the prototype of strstr().
Commit fea1d2d straight up turned instr() into an alias for strstr(),
which was apparently fine without any casts for 4.5 years. The C code in
Perl_instr() was moved from util.c to mathoms.c in commit 534dad4.1 parent 7946d6a commit 9eac113
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
| 244 | + | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| |||
0 commit comments