sizeof(size_t) on ia32 is 4 thus 2^32 = 4,294,967,296 Byte can be accessed by
unsigned.
   real(4), dimension(1025*1024*1024) :: m
can thus not be accessed on ia32. Currently, gfortran does detect this overflow
at compile time.

Expected: The same as ifort:
fortcom: Error: mem.f, line 3: A common block or variable may not exceed
2147483647 bytes
      REAL(4), DIMENSION(1074790400) :: T
-----------------------------------^)

(2147483647 = 2^31-1 -> signed int32.)

Analogously for allocate() of pointers and arrays. Currently this does not fail
even if sizeof(datatype)*size overflows size_t. As size_t is always possitive,
the malloc() works sucessfully. In my case it produces:
1074790400*4 = 4194304. I get a coredump if I access T(1048577) as I only
allocated T(1:1048576:1).

Other compilers seem to have an overflow check somewhere. Maybe it works the
following [symbolically written]
  if(size > 2**sizeof(size_t)/sizeof(datatype)) call error()
at least they return a non-successful status with allocate.


-- 
           Summary: Check for memory allocations bigger than size_t
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tobias dot burnus at physik dot fu-berlin dot de


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

Reply via email to