with src = ST(1) and fallback_cb as subroutine which reallocate perl stack
leads to undefined behaviour when pointers to perl stack variables are
modified more times between two sequence points.
When that code is compiled under gcc 4.6 then at first is evaluated pointer
for ST(0), second is evaluation of encode_method() function and third is
assignment of return value. But encode_method() modified pointers to perl
stack variables and old pointer for ST(0) from first step does not have to
be correct...
With this patch ST(0) is not directly modified between two sequence points
but via temporary variable RETVAL. Tested under valgrind that memory
corruption disappeared.
Construction like this:
ST(0) = encodemethod(aTHX enc, enc->f_utf8, src, check, NULL, Nullsv, NULL, fallback_cb);
with src = ST(1) and fallback_cb as subroutine which reallocate perl stack leads to undefined behaviour when pointers to perl stack variables are modified more times between two sequence points.
When that code is compiled under gcc 4.6 then at first is evaluated pointer for ST(0), second is evaluation of encode_method() function and third is assignment of return value. But encode_method() modified pointers to perl stack variables and old pointer for ST(0) from first step does not have to be correct...
With this patch ST(0) is not directly modified between two sequence points but via temporary variable RETVAL. Tested under valgrind that memory corruption disappeared.
Fixes bug: https://rt.cpan.org/Public/Bug/Display.html?id=113164