NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/59818: ksh Floating point exception (core dumped)



>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:



Home | Main Index | Thread Index | Old Index