From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 06DEC3857017 for ; Mon, 13 Nov 2023 23:23:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 06DEC3857017 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 06DEC3857017 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699917798; cv=none; b=n6M7s4i41mILwhEdKfH6nDpnx82TdGCP0Vz7nfp1HNoM1D/ULb1bUD87pRvn3OCnBhpygcxr0tkD77l2wtnjcDhlqphBq1fYztQ3A0FIcWIU1721F0klScJdZhFB4ewnXw2pwbajYqjMbqkLG5z7rKDXkE+gjsmkvuExL68LchY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699917798; c=relaxed/simple; bh=lA6NGU9XFZNSaUrQCnP0WVD1A6Rzr0evZ7mhIknQZjg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ocg/45ZD+lBWF7fvJB/oYUdmwZJCSM/WJ50rrtcdM0hkn7WK5Sa9RZd+0VOMnKXqzj0Czrai7HaYP/wLFtEM+mUPfJEbyRrWDHcE+tuVc/stTN5FLTxkmKGPfdcpCQuC3STvIxLu9bHHsVFELqt5fEX/hkxiYMKDGZV5jUoShWM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699917796; 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: in-reply-to:in-reply-to; bh=d9CvfkGcGIY9l2s92CxW2Tja6lK7eDpHxhmeUlQHwRg=; b=BWk1cCcLpmPAXva2p23IlS7YYG/Vr7c2QHU2Xvri7skg16qq2TrJR7SBX6QuTOTyfrv3Bx z8xyp1oOGkZpd+AGk1d7dSs5GCZNtXRZV+8behKwwph12alH/OQksPhs5DiO+GyF1tgYRc Y3k5vEJatq1ah2TZdCcJcXtW0lJVyOw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-473-iT1eL5rwPNO0kVT7LHmWxA-1; Mon, 13 Nov 2023 18:23:13 -0500 X-MC-Unique: iT1eL5rwPNO0kVT7LHmWxA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 227BD101A54C; Mon, 13 Nov 2023 23:23:13 +0000 (UTC) Received: from greed.delorie.com (unknown [10.22.9.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C5421C060AE; Mon, 13 Nov 2023 23:23:12 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.15.2/8.15.2) with ESMTP id 3ADNNCg51124933; Mon, 13 Nov 2023 18:23:12 -0500 From: DJ Delorie To: "=?ISO-8859-2?Q?Niklas_Hamb=FCchen?=" Cc: libc-alpha@sourceware.org, schwab@linux-m68k.org Subject: Re: [PATCH v2] malloc_stats(): Fix `unsigned int` overflow In-Reply-To: Date: Mon, 13 Nov 2023 18:23:11 -0500 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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: Niklas Hambchen writes: >>> + fprintf (stderr, "max mmap regions = %10d\n", mp_.max_n_mmaps); >> >> This causes a negative number to be printed when max_n_mmaps increments >> past 2^31, where using "u" defers bad results until 2^32. So IMHO this >> one is a regression, not a fix. > > I'm not sure I understand: > That statement holds for all `int`s, so following this logic, all > `int`s should be casted to `unsigned int` first and printed with `%u`, > and `%d` would be quite useless. > > Doesn't it make more sense to print an `int` with `%d` as normal, so > that you can _see_ in `malloc_stats()` when it overflows? It only really overflows when it wraps around 2^32. Until then, the value is still useful, as long as you present it properly. An alternative would be to print out "(overflowed)" if the value exceeds 2^31 It just didn't seem right to take something that prints 0..2^32-1 and reduce it to only print 0..2^31-1. The other cases were stored as size_t and potentially truncated, which is a different sort of overflow bug.