NetBSD Problem Report #59818

From stix@stix.id.au  Fri Dec  5 22:35:40 2025
Return-Path: <stix@stix.id.au>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 9EE171A9239
	for <gnats-bugs@gnats.NetBSD.org>; Fri,  5 Dec 2025 22:35:40 +0000 (UTC)
Message-Id: <20251205222722.100101A015@stix.id.au>
Date: Sat,  6 Dec 2025 09:27:22 +1100 (AEDT)
From: stix@stix.id.au
Reply-To: stix@stix.id.au
To: gnats-bugs@NetBSD.org
Subject: ksh Floating point exception (core dumped)
X-Send-Pr-Version: 3.95

>Number:         59818
>Category:       bin
>Synopsis:       ksh: Floating point exception (core dumped)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Dec 05 22:40:01 +0000 2025
>Originator:     Paul Ripke
>Release:        NetBSD 10.1_STABLE
>Organization:
Paul Ripke
"Great minds discuss ideas, average minds discuss events, small minds
 discuss people."
-- Disputed: Often attributed to Eleanor Roosevelt. 1948.
>Environment:
System: NetBSD slave 10.1_STABLE NetBSD 10.1_STABLE (SLAVE) #18: Sun Jul 20 16:09:40 AEST 2025 stix@slave:/home/netbsd/netbsd-10/obj.amd64/home/netbsd/netbsd-10/src/sys/arch/amd64/compile/SLAVE amd64
Architecture: x86_64
Machine: amd64
>Description:

This is mostly a cute "feature" of (I think) amd64, generating a floating
point exception from an integer overflow.

ksh$ echo $((-9223372036854775808/-1))
Floating point exception (core dumped)

>How-To-Repeat:

As above.

>Fix:

Something like the following?

diff --git a/bin/ksh/expr.c b/bin/ksh/expr.c
index 71e54091b44d..4a00c2053395 100644
--- a/bin/ksh/expr.c
+++ b/bin/ksh/expr.c
@@ -349,6 +349,15 @@ evalexpr(es, prec)
 			else
 				evalerr(es, ET_STR, "zero divisor");
 		}
+		if ((op == O_DIV || op == O_MOD || op == O_DIVASN
+		     || op == O_MODASN) && vl->val.i == INTMAX_MIN
+		     && vr->val.i == -1)
+		{
+			if (es->noassign)
+				vr->val.i = 1;
+			else
+				evalerr(es, ET_STR, "divide error");
+		}
 		switch ((int) op) {
 		case O_TIMES:
 		case O_TIMESASN:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2025 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.