This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
(perl #131746) avoid undefined behaviour in Copy() etc
authorTony Cook <tony@develop-help.com>
Mon, 14 Aug 2017 01:52:39 +0000 (11:52 +1000)
committerTony Cook <tony@develop-help.com>
Mon, 4 Sep 2017 04:47:29 +0000 (14:47 +1000)
commitf14cf3632059d421de83cf901c7e849adc1fcd03
tree154fa1ff985a07e1daa78f467b4bfcbcb296c9ad
parent011c35bc25a9aebadb06d2e6e7f421615d5a7260
(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.
ext/File-Glob/Glob.pm
ext/File-Glob/Glob.xs
handy.h
pp_ctl.c
pp_hot.c