From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5826 invoked by alias); 12 Apr 2012 03:50:53 -0000 Received: (qmail 5816 invoked by uid 22791); 12 Apr 2012 03:50:52 -0000 X-SWARE-Spam-Status: No, hits=-3.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,SUBJ_OBFU_PUNCT_FEW,SUBJ_OBFU_PUNCT_MANY X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 12 Apr 2012 03:50:40 +0000 From: "vapier at gentoo dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug other/52944] New: [4.5/4.6 Regression] __builtin_object_size(..., 1) no longer returns (size_t)-1 for consecutive flexible/zero-length array members Date: Thu, 12 Apr 2012 03:50:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: other X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vapier at gentoo dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-04/txt/msg00799.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52944 Bug #: 52944 Summary: [4.5/4.6 Regression] __builtin_object_size(..., 1) no longer returns (size_t)-1 for consecutive flexible/zero-length array members Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: other AssignedTo: unassigned@gcc.gnu.org ReportedBy: vapier@gentoo.org Target: x86_64-linux-gnu consider the code: struct stct { int i; union { short k; char buf[0]; }; char tail[]; }; char buf[100]; main() { struct stct *foo = (void *)buf; printf("%i\n", __builtin_object_size(foo->buf, 1)); } when compiled with gcc-4.4, we get -1. but with gcc-4.5 and gcc-4.6, we get 0. granted, this code is a bit odd, but in some cases, it makes sense. imo, the trailing series of flexible/zero-length array members should get the same treatment rather than just the last one. gcc doesn't allow flexible array members inside of unions which is unfortunate. with tftp, the packet is described by: struct tftphdr { short opcode; union { unsigned short tu_block; short tu_code; char tu_stuff[0]; }; char th_data[]; }; when opcode is 1, the rest of the packet is a C string. i.e. the buffer: char x[] = { 1, 0, 'f', 'i', 'l', 'e', '\0', }; opcode = 1, tu_stuff = "file" when opcode is 3 though, the tu_block field will be a number, and the rest of the data will be in th_data. i.e. the buffer: char x[] = { 2, 0, 3, 0, <8KiB>, }; opcode = 2, tu_block = 3, th_data = 8KiB