From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-out.m-online.net (mail-out.m-online.net [IPv6:2001:a60:0:28:0:1:25:1]) by sourceware.org (Postfix) with ESMTPS id 7AF553839DAE; Fri, 25 Nov 2022 20:40:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7AF553839DAE Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nefkom.net Received: from frontend03.mail.m-online.net (unknown [192.168.6.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4NJmvq2312z1s88k; Fri, 25 Nov 2022 21:40:22 +0100 (CET) Received: from localhost (dynscan3.mnet-online.de [192.168.6.84]) by mail.m-online.net (Postfix) with ESMTP id 4NJmvp63hhz1qqlR; Fri, 25 Nov 2022 21:40:22 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan3.mail.m-online.net [192.168.6.84]) (amavisd-new, port 10024) with ESMTP id 202BZmNUsqe1; Fri, 25 Nov 2022 21:40:22 +0100 (CET) X-Auth-Info: mdPe994CDKIfx+U/JpxjaJiTl5rC/+ZG+llj+nJ4eMjT0zDLcKeZaqPABWPO15Bg Received: from igel.home (aftr-82-135-86-84.dynamic.mnet-online.de [82.135.86.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Fri, 25 Nov 2022 21:40:22 +0100 (CET) Received: by igel.home (Postfix, from userid 1000) id E22C42C31AF; Fri, 25 Nov 2022 21:40:21 +0100 (CET) From: Andreas Schwab To: Siddhesh Poyarekar via Libc-alpha Cc: Siddhesh Poyarekar Subject: Re: [PATCH] realloc: Return unchanged if request is within usable size References: <20221125200948.2399996-1-siddhesh@sourceware.org> X-Yow: I just heard the SEVENTIES were over!! And I was just getting in touch with my LEISURE SUIT!! Date: Fri, 25 Nov 2022 21:40:21 +0100 In-Reply-To: <20221125200948.2399996-1-siddhesh@sourceware.org> (Siddhesh Poyarekar via Libc-alpha's message of "Fri, 25 Nov 2022 15:09:48 -0500") Message-ID: <87v8n222fe.fsf@igel.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no 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 Nov 25 2022, Siddhesh Poyarekar via Libc-alpha wrote: > + /* Smoke test to make sure that allocations do not move if they have enough > + space to expand in the chunk. */ > + for (size_t sz = 3; sz < 256 * 1024; sz += 2048) > + { > + p = realloc (NULL, sz); > + if (p == NULL) > + FAIL_EXIT1 ("realloc (NULL, 31) returned NULL."); s/31/sz/ > + size_t newsz = malloc_usable_size (p); > + printf ("size: %zu, usable size: %zu, extra: %zu\n", > + sz, newsz, newsz - sz); > + void *new_p = realloc (p, newsz); > + if (new_p != p) The compiler is allowed to optimize this to true under the assumption that new_p == NULL (the only case where p is still a valid pointer). -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."