public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "manu at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/35652] [4.2/4.3/4.4 Regression] offset warning should be given in the front-end Date: Sat, 01 Nov 2008 17:46:00 -0000 [thread overview] Message-ID: <20081101174441.27996.qmail@sourceware.org> (raw) In-Reply-To: <bug-35652-11271@http.gcc.gnu.org/bugzilla/> ------- Comment #8 from manu at gcc dot gnu dot org 2008-11-01 17:44 ------- This is my current patch and it works in this testcase. However, it also triggers on cases like: const char *p = str + sizeof(str) Perhaps I am doing this at the wrong place. Any suggestions? @@ -3322,10 +3323,36 @@ pointer_int_sum (enum tree_code resultco /* Create the sum or difference. */ if (resultcode == MINUS_EXPR) intop = fold_build1 (NEGATE_EXPR, sizetype, intop); + + if (TREE_CODE (intop) == INTEGER_CST) + { + tree offset_node; + tree string_cst = string_constant (ptrop, &offset_node); + + if (string_cst != 0 + && !(offset_node && TREE_CODE (offset_node) != INTEGER_CST)) + { + HOST_WIDE_INT max = TREE_STRING_LENGTH (string_cst) - 1; + HOST_WIDE_INT offset; + if (offset_node == 0) + offset = 0; + else if (! host_integerp (offset_node, 0)) + offset = -1; + else + offset = tree_low_cst (offset_node, 0); + + offset = offset + tree_low_cst (intop, 0); + if (offset < 0 || offset > max) + warning_at (location, 0, + "offset %<%ld%> outside bounds of constant string", + tree_low_cst (intop, 0)); + } + } + ret = fold_build2 (POINTER_PLUS_EXPR, result_type, ptrop, intop); fold_undefer_and_ignore_overflow_warnings (); return ret; -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35652
next prev parent reply other threads:[~2008-11-01 17:46 UTC|newest] Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-03-20 21:07 [Bug c++/35652] New: Location information incorrect on string bounds warning simon_baldwin at yahoo dot com 2008-03-21 12:50 ` [Bug c++/35652] " rguenth at gcc dot gnu dot org 2008-03-21 12:53 ` [Bug c++/35652] [4.1/4.2/4.3/4.4 Regression] " rguenth at gcc dot gnu dot org 2008-03-21 13:02 ` rguenth at gcc dot gnu dot org 2008-04-26 17:01 ` simonb at gcc dot gnu dot org 2008-04-26 17:22 ` simon_baldwin at yahoo dot com 2008-04-26 20:53 ` rguenth at gcc dot gnu dot org 2008-07-04 22:41 ` [Bug c++/35652] [4.2/4.3/4.4 " jsm28 at gcc dot gnu dot org 2008-10-30 22:46 ` [Bug c++/35652] [4.2/4.3/4.4 Regression] offset warning should be given in the front-end manu at gcc dot gnu dot org 2008-11-01 17:46 ` manu at gcc dot gnu dot org [this message] 2008-11-02 12:22 ` rguenther at suse dot de 2008-11-02 12:54 ` manu at gcc dot gnu dot org 2008-11-02 13:07 ` Andrew Thomas Pinski 2008-11-02 13:04 ` rguenth at gcc dot gnu dot org 2008-11-02 13:09 ` pinskia at gmail dot com 2009-02-03 16:40 ` bonzini at gnu dot org 2009-02-08 15:46 ` manu at gcc dot gnu dot org 2009-03-27 7:17 ` andreasmeier80 at gmx dot de 2009-03-27 12:53 ` hjl at gcc dot gnu dot org 2009-03-27 14:31 ` [Bug c++/35652] [4.2/4.3 " dominiq at lps dot ens dot fr 2009-03-27 14:34 ` rguenth at gcc dot gnu dot org 2009-03-27 14:44 ` dominiq at lps dot ens dot fr 2009-03-27 14:50 ` dominiq at lps dot ens dot fr 2009-03-27 15:13 ` dominiq at lps dot ens dot fr 2009-03-30 13:51 ` jakub at gcc dot gnu dot org 2009-03-30 17:42 ` jakub at gcc dot gnu dot org 2009-03-31 13:11 ` espindola at google dot com 2009-03-31 13:12 ` espindola at google dot com 2009-03-31 20:49 ` [Bug c++/35652] [4.3 " jsm28 at gcc dot gnu dot org 2009-04-11 17:01 ` rob1weld at aol dot com 2009-04-14 14:51 ` pinskia at gcc dot gnu dot org 2009-04-15 7:41 ` dcb314 at hotmail dot com 2009-04-28 4:57 ` bje at gcc dot gnu dot org 2009-08-04 12:40 ` rguenth at gcc dot gnu dot org 2009-08-04 23:42 ` [Bug c++/35652] [4.3/4.4/4.5 " manu at gcc dot gnu dot org 2009-12-20 18:09 ` jason at gcc dot gnu dot org 2009-12-20 18:50 ` jakub at gcc dot gnu dot org 2010-02-03 5:24 ` jason at gcc dot gnu dot org 2010-02-03 16:28 ` jason at gcc dot gnu dot org 2010-02-03 16:29 ` jason at gcc dot gnu dot org
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=20081101174441.27996.qmail@sourceware.org \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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: linkBe 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).