From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4CC5F385843E; Fri, 26 May 2023 16:27:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CC5F385843E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685118432; bh=BgtjVxwWukIi0IKGsIIG4/ITcjCWFoogTi/wapUoXic=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CU5slCxrL4f+5VNb+m8+S1B51zzeUT4Ej+yGy8CF52254RWx2pwp5J3DSerwvqtxF Qb2P/ipVOustgobYIiq3k36R9KoQ2Uexm+oLjLz7ZfUallXMsMDfxQdP5Xonm7TBaR DCoXPi571JXsScrJa6y8AtkA6M/38xvRFx+Es/+Q= From: "bruno at clisp dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/109990] [12/13/14 Regression] Bogus -Wuse-after-free warning after realloc Date: Fri, 26 May 2023 16:27:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: bruno at clisp dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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: 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=3D109990 --- Comment #4 from Bruno Haible --- > >=20 > > char *new_pool =3D (char *) realloc (string_space, ne= w_size); > > if (new_pool =3D=3D ((void *)0)) > > goto out; > > if (__builtin_expect (string_space !=3D new_pool, 0)) > > { > > size_t i; > > for (i =3D 0; i < nmap; i++) > > { > > map[i].alias +=3D new_pool - string_space; > > map[i].value +=3D new_pool - string_space; > > } > > } > > string_space =3D new_pool; > Also I think `new_pool - string_space` is undefined really. That is > subtracting two unrelated arrays is undefined. You can only compare equal= ity > on them. That is the only way of keeping track of pointers _into_ the string_space a= rea, when it is reallocated. How else would you want to do it?=