public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: c/8268: no compile time array index checking
Date: Fri, 18 Oct 2002 10:26:00 -0000	[thread overview]
Message-ID: <20021018172603.1238.qmail@sources.redhat.com> (raw)

The following reply was made to PR c/8268; it has been noted by GNATS.

From: Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: c/8268: no compile time array index checking
Date: 18 Oct 2002 19:22:53 +0200

 --=-=-=
 
 Hi,
 
 ages ago, I wrote a patch for c-typeck.c that does this. Jeff Law
 suggested to place it in expr.c, so other languages would catch it,
 too. Here's a patch. Does it look like I'm on the right track?
 
 -- 
 	Falk
 
 --=-=-=
 Content-Type: text/x-patch
 Content-Disposition: attachment; filename=array-bounds.patch
 
 Index: expr.c
 ===================================================================
 RCS file: /cvs/gcc/gcc/gcc/expr.c,v
 retrieving revision 1.488
 diff -u -r1.488 expr.c
 --- expr.c	15 Oct 2002 20:09:32 -0000	1.488
 +++ expr.c	18 Oct 2002 15:59:49 -0000
 @@ -5634,6 +5634,19 @@
  	  tree low_bound = (domain ? TYPE_MIN_VALUE (domain) : 0);
  	  tree unit_size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (array)));
  
 +	  if (domain && TREE_CODE (index) == INTEGER_CST)
 +	    {
 +	      if ((TREE_CODE (low_bound) == INTEGER_CST
 +		   && tree_int_cst_lt(index, low_bound))
 +		  || (TREE_CODE (TYPE_MAX_VALUE (domain)) == INTEGER_CST
 +		      && tree_int_cst_lt (TYPE_MAX_VALUE (domain), index)
 +		      /* Accesses after the end of arrays of size 0 (gcc
 +			 extension) and 1 are likely intentional. */
 +		      && !tree_int_cst_lt (TYPE_MAX_VALUE (domain),
 +					   build_int_2 (2, 0))))
 +		warning ("array subscript out of range");
 +	    }
 +
  	  /* We assume all arrays have sizes that are a multiple of a byte.
  	     First subtract the lower bound, if any, in the type of the
  	     index, then convert to sizetype and multiply by the size of the
 
 --=-=-=--


             reply	other threads:[~2002-10-18 17:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-18 10:26 Falk Hueffner [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-01-28  0:46 Wolfgang Bangerth
2003-01-26 16:06 David Binderman
2003-01-08  2:40 bangerth
2002-10-17 14:26 d.binderman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021018172603.1238.qmail@sources.redhat.com \
    --to=falk.hueffner@student.uni-tuebingen.de \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).