public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "meklund at cisco dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/44386] New: builtin_object_size_ assumes a flexible array for a long array in a structure of known length Date: Wed, 02 Jun 2010 15:15:00 -0000 [thread overview] Message-ID: <bug-44386-11981@http.gcc.gnu.org/bugzilla/> (raw) When the last element of a structure is an array, builtin_object_size__ always assumes it is a flexible array no matter the length. For example, the below code compiled with '-O2' in 4.5.0 gives an unexpected length in 'a', 'b', 'd', and 'f'. At a minimum, it is expected that 'a' and 'd' should return 40 since 'e' is returning 40. It is debatable if 'b' and 'f' should return 40 or the remaining size of the malloced memory. #include <stdio.h> struct bar0 { char c[40]; }; struct bar1 { char c[40]; char d[40]; }; struct bar *bp; int main() { struct bar0 *b0; struct bar0 *b0m = malloc(200); struct bar1 *b1; struct bar1 *b1m = malloc(200); printf("%ld\n", __builtin_object_size(b0->c, 3)); // a. Returned 0, expected 40 printf("%ld\n", __builtin_object_size(b0m->c, 3)); // b. Returned 200, expected 40 or 200 printf("%ld\n", __builtin_object_size(b1->c, 3)); // c. Returned 40, expected 40 printf("%ld\n", __builtin_object_size(b1->d, 3)); // d. Returned 0, expected 40 printf("%ld\n", __builtin_object_size(b1m->c, 3)); // e. Returned 40, expected 40 printf("%ld\n", __builtin_object_size(b1m->d, 3)); // f. Returned 160, expected 40 or 160 return 0; } -- Summary: builtin_object_size_ assumes a flexible array for a long array in a structure of known length Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: meklund at cisco dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44386
next reply other threads:[~2010-06-02 15:15 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2010-06-02 15:15 meklund at cisco dot com [this message] 2010-06-02 16:33 ` [Bug c/44386] " meklund at cisco dot com 2010-06-02 18:04 ` [Bug middle-end/44386] " pinskia at gcc dot gnu dot org 2010-06-02 18:05 ` [Bug c/44386] " jakub at gcc dot gnu dot org 2010-06-07 15:27 ` [Bug middle-end/44386] " meklund at cisco dot com
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=bug-44386-11981@http.gcc.gnu.org/bugzilla/ \ --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).