[gfortran,patch] Fix PR27588: Add substring out of bounds check

Tobias Burnus burnus@net-b.de
Wed Oct 4 16:29:00 GMT 2006


:ADDPATCH fortran:

The attached patch adds a "substring out of bounds" check, in the spirit
of trans-array.c's gfc_trans_array_bound_check.

The output error is (e.g.):
Fortran runtime error: Substring out of bounds: lower bound is less than
one (in file 'string2.f90', at line 5)
Fortran runtime error: Substring out of bounds: upper bound exceeds
string length (in file 'cbnd1.for', at line 5)

In principle there is also a version which outputs the variable name,
but this does not work (contrary to gfc_trans_array_bound_check, where
also both versions exist). Either it is not available, or I check the
wrong variable.

There is another problem:
The location shown is off by one line; e.g.
cat -n testsuite/gfortran.dg/char_bounds_check_fail_1.f90
[...]
     8        j = i+9
     9        zz(i:j) = 'abcdef'
~> gfortran -fbounds-check char_bounds_check_fail_1.f90; ./a.out
Fortran runtime error: Substring out of bounds: upper bound exceeds
string length (in file 'char_bounds_check_fail_1.f90', at line 8)
I probably mishandle gfc_get_backend_locus(&loc); but I fail to see,
how to do this properly.

The patch fixes PR27588 and passes also the cbnd1, cbnd2 and cbnd4 test
of the http://www.polyhedron.com/pb05/linux/diagnose.html test suit
(modulo line number).

Tobias


2006-10-04 Tobias Burnus <burnus@net-b.de>
    PR fortran/27588
    * trans-expr.c: Add substring boundary check to gfc_conv_substring
    * gfortran.dg/

2006-10-04 Tobias Burnus <burnus@net-b.de>
    PR fortran/27588
    * gfortran.dg/char_bounds_check_fail_1.f90
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch_PR27588.diff
Type: text/x-patch
Size: 2527 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20061004/f7e6117d/attachment.bin>


More information about the Fortran mailing list