Created attachment 44433 [details]
fortran module and example program that used to print environment table
Program could read process environment table and print it up through at least GNU/gfortran 6.4. Now at 7.0.3 it loops showing first entry fron environment table several hundred times and then fails with a segfault.
Created attachment 44434 [details]
C code for interfacing to Fortran for printing environment table
*** Bug 86666 has been marked as a duplicate of this bug. ***
Confirmed. The change occurred between revisions r237590 (2016-06-20, OK) and r238821 (2016-07-28, wrong code.
If I compile the C file with r237590 and link the object file to the fortran file compiled with any revision (I have tried), the test works. This looks as a C bug rather than a fortran one.
Note that compiling the C file with -Wall gives
pr86667.c: In function 'my_initenv':
pr86667.c:39:7: warning: value computed is not used [-Wunused-value]
pr86667.c: In function 'my_readenv':
pr86667.c:54:14: warning: operation on 'ep' may be undefined [-Wsequence-point]
Also I get the warning (on darwin)
ld: warning: tentative definition of '_longest_env_variable' with size 8 from '/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccDHXTrU.o' is being replaced by real definition of smaller size 4 from 'pr86667.o'
The test works as expected if I replace
in the C file.
*ep=*ep++ is undefined.
Did not mean to get a debug session for the code. The code had been working for several years and "broke" when I updated gfortran (and incidently, gcc). Thanks to everyone for looking at it so promptly. Wasted a bunch of time condensing the Fortran down to a simple reproducer, when it was in the C all along.