https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53296
--- Comment #6 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
The initial patch above fixes the case Steve presented in Comment #4. At first
it appeared to also fix the original test case by the reporter. Then I compiled
it with -fsanitize=address as a check. All kinds of nasty stuff going on. It is
looking like I have uncovered another memory leak.
$ ./a.out
size 78
=================================================================
==46986==ERROR: AddressSanitizer: stack-buffer-overflow on address
0x7ba3273f00aa at pc 0x7fa329aec577 bp 0x7ffc1014a1e0 sp 0x7ffc101499a0
WRITE of size 128 at 0x7ba3273f00aa thread T0
#0 0x7fa329aec576 in memmove
../../../../gcc-test/libsanitizer/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc:100
#1 0x000000401173 in MAIN__ (/home/jerry/dev/prs/pr53296/a.out+0x401173)
#2 0x000000401a2b in main (/home/jerry/dev/prs/pr53296/a.out+0x401a2b)
#3 0x7fa3292f3680 in __libc_start_call_main (/lib64/libc.so.6+0x3680)
(BuildId: 17f2e1fd905f485786f6fd6e3bede4ad737137e7)
#4 0x7fa3292f3797 in __libc_start_main@GLIBC_2.2.5
(/lib64/libc.so.6+0x3797) (BuildId: 17f2e1fd905f485786f6fd6e3bede4ad737137e7)
#5 0x000000400514 in _start (/home/jerry/dev/prs/pr53296/a.out+0x400514)
Address 0x7ba3273f00aa is located in stack of thread T0 at offset 170 in frame
#0 0x00000040088a in MAIN__ (/home/jerry/dev/prs/pr53296/a.out+0x40088a)
This frame has 11 object(s):
[48, 52) '<unknown>'
[64, 68) '<unknown>'
[80, 84) 'str.15' (line 9)
[96, 101) 'str.14' (line 9)
[128, 136) 'FRAME.30' (line 1)
[160, 170) 'A.17' (line 9)
[192, 256) 'alloc' (line 4) <== Memory access at offset 170 partially
underflows this variable
[288, 352) 'atmp.16' (line 9) <== Memory access at offset 170 partially
underflows this variable
[384, 640) 'A.12' (line 9)
[704, 1232) 'dt_parm.9' (line 8)
[1360, 1888) 'dt_parm.19' (line 10)
HINT: this may be a false positive if your program uses some custom stack
unwind mechanism, swapcontext or vfork
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow
(/home/jerry/dev/prs/pr53296/a.out+0x401173) in MAIN__