From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bee.birch.relay.mailchannels.net (bee.birch.relay.mailchannels.net [23.83.209.14]) by sourceware.org (Postfix) with ESMTPS id DE2A538582AB for ; Fri, 17 Feb 2023 14:01:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE2A538582AB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 14250541A5E; Fri, 17 Feb 2023 14:01:26 +0000 (UTC) Received: from pdx1-sub0-mail-a305.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 89618540895; Fri, 17 Feb 2023 14:01:25 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1676642485; a=rsa-sha256; cv=none; b=dzq/7S49anrGJhDsFzv5oslw1pfbJH1F2+QOJqK9eiJ6a9lZgb611jBOe2j4l7eCCKf0kr cC09h5T9bGKX2/xSDqap2LGcupAiGW8M9ol24jNdH8WjOOqrvOWcuqcvU4fJRE/cuEpdr6 u90Oow40cXlqX3CTU1iUnp39oWKuaE0kztDg/ftt16fNXYjP4+KNPuhAoj7ojkPCHX6Jcc dSMMncJBh08SPb8GhCI/9G/n4GJc/QtV9JBf1BtRdY0N7SzVpGZIiE0lisWgsDbU89mLy/ 8CG4Ex2tfhPkJau+mEpgT9mWEyltNTOrJyic5HfL8ddiofQ1PD2NBTbuvB8+PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1676642485; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VNlPbyNDUo73O2rgdI6se34LUWSN+V1e7TdeXAcNk4w=; b=jGTznryUSFzf2aEsLMt0d5NuKAP3/cCYHFK8w23DBx41nKvcHp7XOjtnviF734ccHp1eui bcbZ102a6zrYVE21bOeI4An3AghGdCf6W7KAIXzfzPcoeOhVNTJBWvv0ku5ecnRWQho3cR QQYOp2DAGBNYI+PVOeH1X46hD/L0lIOtwDHV/i1wI8r901YMrEyaS1/ssLtyPsYIrEi6eA xMEfFD1v8UDkbpMMCuI/M8mp6aXzO/04SD1HAJJ0MZiVtYsTdWHG9xThLkgjlYCSTNdOQv E0zw8qcTaFBn4ooH/HPfLLsGzEH98v5kZCYOklCHxtyWXjmkBf32gN41XyC5vQ== ARC-Authentication-Results: i=1; rspamd-b9c55767f-ngqs4; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Drop-Oafish: 25ed8a15275023e9_1676642485871_457153138 X-MC-Loop-Signature: 1676642485871:953417145 X-MC-Ingress-Time: 1676642485871 Received: from pdx1-sub0-mail-a305.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.126.30.40 (trex/6.7.1); Fri, 17 Feb 2023 14:01:25 +0000 Received: from [192.168.0.182] (bras-vprn-toroon4834w-lp130-09-174-91-45-59.dsl.bell.ca [174.91.45.59]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a305.dreamhost.com (Postfix) with ESMTPSA id 4PJD4h4RJ2z8J; Fri, 17 Feb 2023 06:01:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1676642485; bh=VNlPbyNDUo73O2rgdI6se34LUWSN+V1e7TdeXAcNk4w=; h=Date:Subject:To:Cc:From:Content-Type:Content-Transfer-Encoding; b=xCKnaItZjXglJADVWiwcHp5u4P/jnxHBPfE/77wvdNUzIyRAcrcbeZik8Wr1p6VPu tSslusgB+zoti9CAHejSlGp1hXLqsvsbEPglCnKfaHJFZ2YVM/bziTWlnl/ljBQXaU 0Rn8gsDfbeVDNamqtkVFIgSyTo6Hw/mQpRlrtC16XPVJZvv4ni/pKyL8NI165JwjhV xKoN4K/9wzcNU1GRCwjG1jPrXqYAQm922MnSNUz873/GrF+rrZr9aTOHEV+DqRMZua U1Ob5QXcLxW6M/zB5lFfBSYuh8YGkVtvgM5lY9rKnKxXOER8Ylr1a40bIRvBBLXTZE KaU0U9OSh/YJQ== Message-ID: Date: Fri, 17 Feb 2023 09:01:23 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: Missed warning (-Wuse-after-free) Content-Language: en-US To: David Malcolm , Alejandro Colomar , GCC Cc: Iker Pedrosa References: <8ed6d28c-69dc-fed8-5ab5-99f685f06fac@gmail.com> <38e7e994a81d2a18666404dbaeb556f3508a6bd6.camel@redhat.com> <500fdb4e5352e5140fd57ec3cb94090b15fc2cfe.camel@redhat.com> From: Siddhesh Poyarekar In-Reply-To: <500fdb4e5352e5140fd57ec3cb94090b15fc2cfe.camel@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3030.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,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 2023-02-17 08:44, David Malcolm wrote: > This is possibly a silly question, but what *are* these safe > alternatives? [1] How does one test to see if an object has been > reallocated? Oops sorry, I snipped off that part when pasting from the man page. Typically such conditionals are used to update pointers within structs (and in some overly adventurous cases, continue using the old pointer!) and the alternative is to save offsets in structs and not pointers. The text I missed quoting here: """ void adjust_pointers (int**, int); void grow (int **p, int n) { int **q = (int**)realloc (p, n *= 2); if (q == p) return; adjust_pointers ((int**)q, n); } To avoid the warning at this level, store offsets into allocated memory instead of pointers. This approach obviates needing to adjust the stored pointers after reallocation. """ Sid > Dave > [1] Would suggesting "rust" here be too snarky? :-P I think the equivalent American expression is "lets take this outside" ;)