Branch: refs/heads/blead Home: https://github.com/Perl/perl5 Commit: 6a35e68252e884e02d0cf10d92a681fb257d5779 https://github.com/Perl/perl5/commit/6a35e68252e884e02d0cf10d92a681fb257d5779 Author: Lukas Mai <lukasmai....@gmail.com> Date: 2025-04-17 (Thu, 17 Apr 2025)
Changed paths: M util.h Log Message: ----------- 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 4e52881229). 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 08105a92a3 (1997): char * instr(register const char *big, register const char *little); The hand-written C code was replaced by a call to strstr() in 5d1d68e202. 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 fea1d2dd5d 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 534dad4824. To unsubscribe from these emails, change your notification settings at https://github.com/Perl/perl5/settings/notifications