util.h: fix broken casts in Perl_instr() parameters #23201
Merged
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why broken? Because haystack/needle are effectively macros (they expand to token sequences), so a call like
expands to
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.