This is the mail archive of the
mailing list for the GCC project.
Re: Infinite loop in dcraw with current GCC versions
- From: Andrew Haley <aph at redhat dot com>
- To: Manuel LÃpez-IbÃÃez <lopezibanez at gmail dot com>, dcoffin at shell dot cybercom dot net
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>, ConchÃr Navid <conchur at web dot de>, Sven Eckelmann <sven at narfation dot org>, RenÃ Rebe ExactCODE <rene at exactcode dot com>
- Date: Sun, 01 Mar 2015 11:44:38 +0000
- Subject: Re: Infinite loop in dcraw with current GCC versions
- Authentication-results: sourceware.org; auth=none
- References: <CAESRpQDZs=EZTAj7bO5Dn8d=M8p8MuN7_s__XNatnL2BWgs9wA at mail dot gmail dot com> <CAESRpQBx7V=O-pH5Ckvt=XpJHYyEwCyZGz1HQTByqdKftQC0MQ at mail dot gmail dot com> <20150227190206 dot GA6175 at shell dot cybercom dot net> <CAESRpQCCWVQGeWMByFFiX6MLoA-VxJ3AAp5u99VdOy7h8SsgQg at mail dot gmail dot com> <20150227204552 dot GA8916 at shell dot cybercom dot net> <CAESRpQAbO-6Zy3FBvR56NDiAGJg8CZYtSTUPLR5jud0baNHKHg at mail dot gmail dot com>
On 28/02/15 16:27, Manuel LÃpez-IbÃÃez wrote:
> cam_xyz is type 'double ', thus I don't think you should cast it
> to 'double *', but in this respect I am just going by intuition, not
> by an actual reference to the standard. On the other hand,
> &cam_xyz should have type 'double *', and the standard does say
> that the data is contiguously allocated, yet the c-faq says that
> ((double *)(&cam_xyz))[j] "is not in strict conformance with the
> ANSI C Standard; according to an official interpretation"
> (http://c-faq.com/aryptr/ary2dfunc2.html), although without a
> reference to the standard, I have no idea what that means.
Here we go. :-)
ANSI defines E1[E2] as
and (therefore) cam_xyz[i][j] as
ISO/IEC 9899:1999, 6.5.1 Primary expressions:
"Successive subscript operators designate an element of a
multidimensional array object. If E is an n-dimensional array (n â 2)
with dimensions i Ã j Ã . . . Ã k, then E (used as other than an
lvalue) is converted to a pointer to an (n â 1)-dimensional array with
dimensions j Ã . . . Ã k. If the unary * operator is applied to this
pointer explicitly, or implicitly as a result of subscripting, the
result is the pointed-to (n â 1)-dimensional array, which itself is
converted into a pointer if used as other than an lvalue."
Therefore the result of the inner
is a one-dimensional array. You have no permission to dereference
beyond the end of that array, and any attempt to do so is UB.