Dear Harald, hi all,

On 12.09.21 20:40, Harald Anlauf via Fortran wrote:
in find_substring_ref we erroneously handled given substring start and end
indices as unsigned integers.  However, gives indices could be negative,
which is legal as long as end < start, leading to a string of length zero.
The current behavior could lead to a wrong length as well as an invalid read
from (compiler) memory.

The fix allows to reintroduce code in testcase substr_6.f90 that was
erroneously considered as illegal.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?
As this is invalid code, I'd like to backport this fix.

OK to both – thanks for patch and all your recent patch work!

Tobias

Fortran - fix handling of substring start and end indices

gcc/fortran/ChangeLog:

      PR fortran/85130
      * expr.c (find_substring_ref): Handle given substring start and
      end indices as signed integers, not unsigned.

gcc/testsuite/ChangeLog:

      PR fortran/85130
      * gfortran.dg/substr_6.f90: Revert commit r8-7574, adding again
      test that was erroneously considered as illegal.

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955

Reply via email to