From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from cyan.elm.relay.mailchannels.net (cyan.elm.relay.mailchannels.net [23.83.212.47]) by sourceware.org (Postfix) with ESMTPS id C83EF3858D1E for ; Wed, 17 May 2023 00:19:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C83EF3858D1E 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 B51D8882044; Wed, 17 May 2023 00:19:28 +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 478D1881775; Wed, 17 May 2023 00:19:28 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1684282768; a=rsa-sha256; cv=none; b=bVBZS8/waCnGG7jbQBiojEx/Yk2RbBMn+r2berLrpxjgjZWEmRgmiaYKp/R1HU4BJQuAVN SXVW/U3bQhhXhLVpGcrNXHHt/uKiM8gSDnp8urwZ1uQrwrk9iuZccTge0/hRtdBw1HZCIX KZ0lOfONaQx3oz8KK+WdJosrmEM3rfAjbmxx0hElRAHOD8bl8KLZZvXFgQQiajaSRZJogr /BPYClZX7mRm9KNqAiKJlSBu3+Fs9ClmWSTSZ0FvewsXmlPqWLZk3N3hkH0b/zSouhUezu 79njJEGwCw5dUu3JWnZNBZdEvlVnu/fuKBsCj3Pz3gBKOxZLIRWu9k+kBef0eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1684282768; 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=HWu9wa3SA+2alKeTl1TKjx94JEptQjPy8YNKtOR4G+w=; b=TU/Qm9k6Aq9b0vwWLJBc5hG3eNOk2qWqNboTOvo7ckFHwWTPoOxUpOFv1W/XrC/6owhrve icbdoexry2g6H+M2ZSSh2f7tNiqeMwzD/D8E9w0xllmfR5aYx4Ba1MDWe55oz91VSzGOLW 3AmSYAfKcYX5B/umV6L/9YAQdrc+ZqhxayJEbLL3Ck+edknWkwlAgGeN1bDLsBtSU9x8WO MQTkHyufB1EIhN5ov5rw3VlfQl67tehxZ+rFWps/R5hKg+pYlJJyPyfRH9Tf9mj3C+I6iE 84Uhfvfm+eu9/tANFQN4tetltwFKq2QLQovDjKd4AuCrMHXnNhYnbWG8p0pkSQ== ARC-Authentication-Results: i=1; rspamd-5cdf8fd7d9-r57sl; 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-Lyrical-Turn: 12611caf6e07e05c_1684282768537_724295767 X-MC-Loop-Signature: 1684282768537:2815028240 X-MC-Ingress-Time: 1684282768537 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.61 (trex/6.8.1); Wed, 17 May 2023 00:19:28 +0000 Received: from [192.168.0.182] (bras-vprn-toroon4834w-lp130-09-174-91-45-80.dsl.bell.ca [174.91.45.80]) (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 4QLYdC5XwLzJp; Tue, 16 May 2023 17:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1684282768; bh=HWu9wa3SA+2alKeTl1TKjx94JEptQjPy8YNKtOR4G+w=; h=Date:Subject:To:Cc:From:Content-Type:Content-Transfer-Encoding; b=JIJuUpuvSjsk5nxyn7yBzYmH3WiRoYIQfVH8XU5eZTeU0Er3HAygAD294XcEGIj5a gAdOQjDj5c8PyHlVPyMLn6vUSTnLbVRJcZiviY2T6He/RPLsK+cJnFMCOLxGwmTqUa xAnQgWEGS0NUONqlGikUTH/L62hDj0BKOMYOh/O695tKlrpe49Rqicpw7CpcejBGRv 8jF8wsB+FohDXp88MMoUUpk9Jqe7si2m5kRAwz/8BVsuyWzc/hysm4C37qABRPX/sk 76k22uTyiqcd/S9Ke+74tshxjRNtaMavOwCLAxHOsQDraP9TDVuEy4EopRJSN2s75m GaEOfNRFR0vXA== Message-ID: Date: Tue, 16 May 2023 20:19:25 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] stdlib: Avoid undefined behavior in stdlib/tst-labs Content-Language: en-US To: Florian Weimer , libc-alpha@sourceware.org Cc: Siddhesh Poyarekar , Joe Simmons-Talbott References: <87cz303qon.fsf@oldenburg.str.redhat.com> From: Siddhesh Poyarekar In-Reply-To: <87cz303qon.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3038.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,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: Reviewed-by: Siddhesh Poyarekar On 2023-05-16 17:35, Florian Weimer via Libc-alpha wrote: > The last loop could attempt to overflow beyond INT_MAX on 32-bit > architectures. > > Also switch to GNU style. > > --- > stdlib/tst-labs.c | 25 +++++++++++++------------ > 1 file changed, 13 insertions(+), 12 deletions(-) > > diff --git a/stdlib/tst-labs.c b/stdlib/tst-labs.c > index 92b456745a..a8d2381f87 100644 > --- a/stdlib/tst-labs.c > +++ b/stdlib/tst-labs.c > @@ -25,25 +25,26 @@ > > static int do_test (void) > { > - long i; > + long int i; > > - TEST_COMPARE(labs(LONG_MAX), LONG_MAX); > - TEST_COMPARE(labs(LONG_MIN + 1), LONG_MAX); > - TEST_COMPARE(labs(-1), 1); > - TEST_COMPARE(labs(0), 0); > - TEST_COMPARE(labs(1), 1); > + TEST_COMPARE (labs (LONG_MAX), LONG_MAX); > + TEST_COMPARE (labs (LONG_MIN + 1), LONG_MAX); > + TEST_COMPARE (labs (-1), 1); > + TEST_COMPARE (labs (0), 0); > + TEST_COMPARE (labs (1), 1); > > for (i = LONG_MIN + 1; i < LONG_MIN + INT_MAX; i += LARGE_PRIME) > - TEST_COMPARE(labs(i), -i); > + TEST_COMPARE (labs (i), -i); > > - for (i = LONG_MAX - INT_MAX; i < LONG_MAX - LARGE_PRIME; i += LARGE_PRIME) > - TEST_COMPARE(labs(i), i); > + for (i = LONG_MAX - INT_MAX; i < LONG_MAX - LARGE_PRIME; > + i += LARGE_PRIME) > + TEST_COMPARE (labs (i), i); > > for (i = INT_MIN + 1; i < 0; i += LARGE_PRIME) > - TEST_COMPARE(labs(i), -i); > + TEST_COMPARE (labs (i), -i); > > - for (i = 0; i < INT_MAX; i += LARGE_PRIME) > - TEST_COMPARE(labs(i), i); > + for (i = 0; i <= INT_MAX - LARGE_PRIME; i += LARGE_PRIME) > + TEST_COMPARE (labs (i), i); > > return EXIT_SUCCESS; > } > > base-commit: 641c4c2b7eb80e2cb2121b1c31096158091a6419 >