From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1225 invoked by alias); 2 Sep 2012 01:53:09 -0000 Received: (qmail 1209 invoked by uid 22791); 2 Sep 2012 01:53:07 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED 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; Sun, 02 Sep 2012 01:52:54 +0000 From: "mikulas at artax dot karlin.mff.cuni.cz" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/54454] gcc violates c99 specification w.r.t. flexible arrays Date: Sun, 02 Sep 2012 01:53:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: mikulas at artax dot karlin.mff.cuni.cz 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: In-Reply-To: References: 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-09/txt/msg00056.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54454 --- Comment #1 from mikulas at artax dot karlin.mff.cuni.cz 2012-09-02 01:52:54 UTC --- Another specification violation: section 6.7.2.1 paragraph 20 says that assignment of a structure with flexible array member doesn't copy any of the array elements. In gcc it is buggy because it copies some array elements. Try this: #include #include #include struct flexible { unsigned a; unsigned short b; unsigned char array[]; }; int main(void) { struct flexible *f1, *f2; f1 = malloc(sizeof(struct flexible) + 3); f1->array[0] = 0; f1->array[1] = 0; f1->array[2] = 0; f2 = malloc(sizeof(struct flexible) + 3); f2->array[0] = 1; f2->array[1] = 1; f2->array[2] = 1; *f2 = *f1; printf("f2->array[0] == %d (should be 1)\n", f2->array[0]); printf("f2->array[1] == %d (should be 1)\n", f2->array[1]); printf("f2->array[2] == %d (should be 1)\n", f2->array[2]); return 0; }