From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A0E7938582B6; Wed, 15 Nov 2023 09:34:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0E7938582B6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700040893; bh=WOPRg0dBQH7tIotoPnd/wqpXb1shcEXiUTWHPlVYIHM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=wFUOykJaXMlmNET1+iGhEu9hcbSKUoDVxXE0Lj4bZ6zo9MW3Xv4M20AdOUykI25Z7 wUGDE2cWzKP/0a9TQiErXlXBb5KzKLg81IcyXR6jXvyEx7ucnN8xfYgiGRtu+AvTSi HmpcrvonziRtU36YxgmPQ5mRBYiNP9Pem5NXgTjQ= From: "xry111 at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/112539] a struct with an array of unknown size at the end allows writing past end of the struct Date: Wed, 15 Nov 2023 09:34:53 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 11.4.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: xry111 at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112539 Xi Ruoyao changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |xry111 at gcc dot gnu.org --- Comment #3 from Xi Ruoyao --- This invalid bug report is actually not related to flexible array member. = It's just invoking an undefined behavior. With -fsanitize=3Dundefined -fno-sanitize-recover: t.c:13:19: runtime error: store to address 0x7ffd20f7fb30 with insufficient space for an object of type 'char' 0x7ffd20f7fb30: note: pointer points here 00 00 00 00 00 00 00 00 00 00 00 00 00 c7 f6 e9 8f 37 ae d2 68 fc f7 20= fd 7f 00 00 00 00 00 00 ^=20 In C even int a[1]; return a[114514]; will compile. But it triggers an undefined behavior at runtime. An undefi= ned behavior may cause a program crash, output some garbage, or "behave as you expected" if you are lucky.=