http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25071

Janne Blomqvist <jb at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |jb at gcc dot gnu.org
         Resolution|FIXED                       |

--- Comment #7 from Janne Blomqvist <jb at gcc dot gnu.org> 2011-01-25 12:01:17 
UTC ---
Reopening..

(In reply to comment #6)
> I believe this is fixed by PR30940.
> 
> The first example gives:
> Warnung: Actual argument contains too few elements for dummy argument 'i' 
> (4/6)
> at (1)
> 
> The second example:
> Warnung: Character length of actual argument shorter than of dummy argument 
> 'y'
> (10/20) at (1)
> 
> It currently gives only warnings since I failed to get any comments when an
> error and when only a warning should be given.

Sorry for being 'a bit' late with comments, but IMHO this should be an error
and not just a warning, because

1) The standard says so

2) Other compilers reject it (so we can't argue that we must support this
common extension)

3) Not rejecting it makes it really easy to corrupt memory. Consider

program x
  character(len=10) :: a, b, c
  a = "1234567890"
  b = a
  c = a
  call xx2(b)
  print *, '::', a, '::', b, '::', c, '::'
contains
  subroutine xx2(name)
    character(len=20), intent(inout) :: name
    name = 'hi'
  end subroutine xx2
end program

This prints (gfortran 4.4, x86_64 Linux):

$ ./chardummy2
 ::    567890::hi        ::1234567890::

That is, blanking out the remaining 18 characters at the end of the character b
passed to xx2 overwrites part of the character a (why are only 4 characters
overwritten and not all 10? because they are allocated 4/8/16? byte aligned on
the stack). Note that neither bounds checking nor valgrind detects this error.

> 
> Missing is the check for array element designators: PR32616.

I haven't looked, but maybe PR30940 and PR32616 would need to be fixed as well?

Reply via email to