From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from resdmta-h1p-028482.sys.comcast.net (resdmta-h1p-028482.sys.comcast.net [IPv6:2001:558:fd02:2446::c]) by sourceware.org (Postfix) with ESMTPS id ABEFF383D5D5 for ; Tue, 13 Dec 2022 19:23:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ABEFF383D5D5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=comcast.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=comcast.net Received: from resomta-h1p-027914.sys.comcast.net ([96.102.179.199]) by resdmta-h1p-028482.sys.comcast.net with ESMTP id 56uwpnPoi1BPJ5Aripp7H1; Tue, 13 Dec 2022 19:22:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=20190202a; t=1670959378; bh=YRj416wMSS+DMPEQ5W5n7aIqse8IBXkdP+a2DvAw4XM=; h=Received:Received:Content-Type:Mime-Version:Subject:From:Date: Message-Id:To:Xfinity-Spam-Result; b=SfcuH4EY9NOglKxkvHPnqmBFFwtr8THeC+KWpH4SOevZeU+9R84eOp+6nzWl9VV98 UULtz+GwGl9DPOA1FWtgn7LRKMkPPYrqlcCDAOe7HG+o3xhWX5C9D7K4T8cL9Exson IBed7SCUGipAXw8GR3mYoU1iaiNVDAYSJkzGMvL2Td7cMK8aNA2FofRZIQr3gz0G6z rF+LWHcKNdpCq7CrXE6yGfxtuepovYzuWxDdDDlQ95NtUkbV+e1K9CM+0O6+9pyc3V 5QFS5UHbPj9QheJYM5YlR79sy7+5FNGw73bx0l5hSqkQ1d5COaCeTxqBgUKNmpIRq9 1x10d7Um6bMfw== Received: from smtpclient.apple ([73.60.223.101]) by resomta-h1p-027914.sys.comcast.net with ESMTPSA id 5ArfpfqEReLhS5ArhpvaSy; Tue, 13 Dec 2022 19:22:58 +0000 X-Xfinity-VAAS: gggruggvucftvghtrhhoucdtuddrgedvhedrfedugdehtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucevohhmtggrshhtqdftvghsihdpqfgfvfdppffquffrtefokffrnecuuegrihhlohhuthemuceftddunecunecujfgurheptggguffhjgffvefgkfhfvffosehtqhhmtdhhtddvnecuhfhrohhmpefrrghulhcumfhonhhinhhguceophgruhhlkhhonhhinhhgsegtohhmtggrshhtrdhnvghtqeenucggtffrrghtthgvrhhnpeevkeevleffleeigfeiudefheegjedthfegudejheeukeeitdfgteffvefggffgvdenucfkphepjeefrdeitddrvddvfedruddtudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhephhgvlhhopehsmhhtphgtlhhivghnthdrrghpphhlvgdpihhnvghtpeejfedriedtrddvvdefrddutddupdhmrghilhhfrhhomhepphgruhhlkhhonhhinhhgsegtohhmtggrshhtrdhnvghtpdhnsggprhgtphhtthhopedvpdhrtghpthhtoheprghlgidrmhgrnhhprghgvghssehgmhgrihhlrdgtohhmpdhrtghpthhtohepghgttgesghgttgdrghhnuhdrohhrgh X-Xfinity-VMeta: sc=0.00;st=legit Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: [BUG] missing warning for pointer arithmetic out of bounds From: Paul Koning In-Reply-To: Date: Tue, 13 Dec 2022 14:22:55 -0500 Cc: gcc@gcc.gnu.org Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Alejandro Colomar X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > On Dec 13, 2022, at 2:08 PM, Alejandro Colomar via Gcc = wrote: >=20 > Hi! >=20 > For the following program: >=20 >=20 > $ cat buf.c > #include >=20 > int main(void) > { > char *p, buf[5]; >=20 > p =3D buf + 6; > printf("%p\n", p); > } >=20 >=20 > There are no warnings in gcc, as I would expect: >=20 > $ gcc -Wall -Wextra buf.c -O0 >=20 > Clang does warn, however: >=20 > $ clang -Weverything -Wall -Wextra buf.c -O0 > buf.c:8:17: warning: format specifies type 'void *' but the = argument has type 'char *' [-Wformat-pedantic] > printf("%p\n", p); > ~~ ^ > %s > buf.c:7:6: warning: the pointer incremented by 6 refers past the = end of the array (that contains 5 elements) = [-Warray-bounds-pointer-arithmetic] > p =3D buf + 6; > ^ ~ I thought void * is a generic pointer that accepts any pointer argument. = So a warning about char* being passed in seems to be flat out wrong. > buf.c:5:2: note: array 'buf' declared here > char *p, buf[5]; > ^ > 2 warnings generated. That was discussed just days ago: C says that a pointer one past the end = of the array is legal. So here too it looks like Clang is wrong and GCC = is right. paul