From patchwork Thu Jul 10 02:19:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 116008 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D2FE3858280 for ; Thu, 10 Jul 2025 02:21:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D2FE3858280 X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id C6747385840C for ; Thu, 10 Jul 2025 02:19:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C6747385840C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C6747385840C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=85.10.215.148 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1752113969; cv=none; b=BgpW5lDmNUo1+eI78XvP8+bPykKMhR+DTgxS49OaUdsd2CTVZAD2r3I7HVMVen7/9A042mBl4fANdB4/Ko7v/G6s9FSbLqrj/+DfnUkC0nfTE1OfpzyNqafsphX7KiTduMympvRuhvGChgE0aNI4nAyupxvtVmADlpYYp+GNhRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1752113969; c=relaxed/simple; bh=otB836TuPvTx0qY7orauAbxf6Zle9rGf7sqTJ1W/4jU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=qJKek2fyPSip4WqDW3l5ehrWpKrx/HZe8LKI9MP1V7CA1rtAtT0aOTTcYJ8NbbXrau/HBvCLNmiQ+vdsZlAwdw8htVfQgCz0Y84fbtfm0hjWtFqbi7zNZZy44uetdtCecNqSWmKc1ewdyCYg9cimo/xUl+O2xCsg+1y32PVfPTs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C6747385840C Received: from sslproxy06.your-server.de ([78.46.172.3]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1uZgsd-000KHV-2e for newlib@sourceware.org; Thu, 10 Jul 2025 04:19:23 +0200 Received: from localhost ([127.0.0.1]) by sslproxy06.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uZgsd-000Ddw-2K for newlib@sourceware.org; Thu, 10 Jul 2025 04:19:23 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 3A23648014F for ; Thu, 10 Jul 2025 04:19:23 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavis, port 10032) with ESMTP id vzEuTL2F-pHN for ; Thu, 10 Jul 2025 04:19:23 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id D6065480157 for ; Thu, 10 Jul 2025 04:19:22 +0200 (CEST) X-Virus-Scanned: amavis at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavis, port 10026) with ESMTP id 3ihKDEMuP-li for ; Thu, 10 Jul 2025 04:19:22 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id A7C8E480184 for ; Thu, 10 Jul 2025 04:19:22 +0200 (CEST) From: Sebastian Huber To: newlib@sourceware.org Subject: [PATCH 3/7] Fix overflow errors in sbttous and sbttoms Date: Thu, 10 Jul 2025 04:19:14 +0200 Message-ID: <20250710021918.112394-4-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250710021918.112394-1-sebastian.huber@embedded-brains.de> References: <20250710021918.112394-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Virus-Scanned: Clear (ClamAV 1.0.7/27694/Wed Jul 9 10:42:34 2025) X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, 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 X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org From: Alan Somers Both of these functions would overflow for very large inputs. Add tests for them. Also, add tests for the inverse functions, *stosbt, whose overflow errors were fixed by 4c30b9ecd47. PR: 263073 MFC after: 1 week Sponsored by: Axcient Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D34809 --- newlib/libc/include/sys/time.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/newlib/libc/include/sys/time.h b/newlib/libc/include/sys/time.h index 006d1f663..35575d59d 100644 --- a/newlib/libc/include/sys/time.h +++ b/newlib/libc/include/sys/time.h @@ -220,7 +220,11 @@ static __inline int64_t sbttous(sbintime_t _sbt) { - return ((1000000 * _sbt) >> 32); +#ifdef KASSERT + KASSERT(_sbt >= 0, ("Negative values illegal for sbttous: %jx", _sbt)); +#endif + return ((_sbt >> 32) * 1000000 + + (1000000 * (_sbt & 0xffffffffu) >> 32)); } static __inline sbintime_t @@ -240,8 +244,10 @@ ustosbt(int64_t _us) static __inline int64_t sbttoms(sbintime_t _sbt) { - - return ((1000 * _sbt) >> 32); +#ifdef KASSERT + KASSERT(_sbt >= 0, ("Negative values illegal for sbttoms: %jx", _sbt)); +#endif + return ((_sbt >> 32) * 1000 + (1000 * (_sbt & 0xffffffffu) >> 32)); } static __inline sbintime_t