This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [fortran,patch] Impose limit on string length
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: FX <fxcoudert at gmail dot com>
- Cc: Fortran List <fortran at gcc dot gnu dot org>, gcc-patches at gcc dot gnu dot org
- Date: Sat, 16 May 2009 09:22:06 -0700
- Subject: Re: [fortran,patch] Impose limit on string length
- References: <98776638-3E1E-440D-91BC-FB3C43D7579F@gmail.com>
On Sat, May 16, 2009 at 06:05:16PM +0200, FX wrote:
> Hi all,
>
> This patch adds checks to string lengths, to avoid getting carried and
> accepting strings longer than the target's MAX_INT. This is something
> stupid to do, of course, but we should error out instead of silently
> compiling it (with wrapping to int type).
>
> This is half the fix for PR 31243: this patch deals with the compile-
> time checks, while some runtime checks may later be enforced
> (protected behind -fcheck=bounds?). The fix is fairly simple, except
> for one thing: I have to prevent range-checking for the result of LEN
> simplification, because otherwise we can issue errors twice
> (furthermore, I'm convinced with the new checks during resolution, the
> range can actually never be exceeded.
>
> Bootstrapped and regtested on x86_64-linux (both -m32 and -m64), comes
> with 3 testcases. OK to commit?
>
A couple comments.
1) Your testcase appear to be missing '! { dg-do compile }' or
'! { dg-do run }' directives.
2) Do the testcases require a system with a large amount of memory?
3) A few corrections to the patch:
+
+ if (compare_bound_mpz_t (ref->u.ss.end,
+ gfc_integer_kinds[k].huge) == CMP_GT
+ && (compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_EQ
+ || compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_GT))
+ {
+ gfc_error ("Substring end index at %L is too large",
+ &ref->u.ss.start->where);
Shouldn't this be ref->u.ss.end->where?
+ return FAILURE;
+ }
+ /* Check that the character length is not to large. */
s/to/too
--
Steve