diff options
author | Tony Cook <tony@develop-help.com> | 2017-08-14 11:52:39 +1000 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2017-09-04 14:47:29 +1000 |
commit | f14cf3632059d421de83cf901c7e849adc1fcd03 (patch) | |
tree | 154fa1ff985a07e1daa78f467b4bfcbcb296c9ad /pp_hot.c | |
parent | 011c35bc25a9aebadb06d2e6e7f421615d5a7260 (diff) | |
download | perl-f14cf3632059d421de83cf901c7e849adc1fcd03.tar.gz |
(perl #131746) avoid undefined behaviour in Copy() etc
These functions depend on C library functions which have undefined
behaviour when passed NULL pointers, even when passed a zero 'n' value.
Some compilers use this information, ie. assume the pointers are
non-NULL when optimizing any following code, so we do need to
prevent such unguarded calls.
My initial thought was to add conditionals to each macro to skip the
call to the library function when n is zero, but this adds a cost to
every use of these macros, even when the n value is always true.
So instead I added asserts() which will give us a much more visible
indicator of such broken code and revealed the pp_caller and Glob.xs
issues also patched here.
Diffstat (limited to 'pp_hot.c')
-rw-r--r-- | pp_hot.c | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -4330,7 +4330,8 @@ PP(pp_entersub) AvARRAY(av) = ary; } - Copy(MARK+1,AvARRAY(av),items,SV*); + if (items) + Copy(MARK+1,AvARRAY(av),items,SV*); AvFILLp(av) = items - 1; } if (UNLIKELY((cx->blk_u16 & OPpENTERSUB_LVAL_MASK) == OPpLVAL_INTRO && |