From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 5C92F1F910 for ; Fri, 25 Nov 2022 20:40:39 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71CA838381EB for ; Fri, 25 Nov 2022 20:40:37 +0000 (GMT) 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-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" 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."