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

Bug#1030231: hugs: toInteger (minBound :: Int) incorrect on 64bit



Package: hugs
Version: 98.200609.21-6
Severity: normal
Tags: patch
X-Debbugs-Cc: claude@mathr.co.uk

Dear Maintainer,

   * What led up to the situation?

I evaluated:

> (minBound :: Int, toInteger (minBound :: Int))

   * What was the outcome of this action?

Two different numbers were output.

   * What outcome did you expect instead?

Two identical numbers to be output.


The consequences of this bug include
broken bitwise operations for Integer
(arithmetic overflow exceptions).


The problem is in src/bignums.c, because -INT_MIN == INT_MIN.

Attached patch fixes the problem for me on aarch64 and x86_64.


Regards,


Claude

-- System Information:
Debian Release: 11.6
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable-debug'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 5.10.0-21-amd64 (SMP w/2 CPU threads)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), LANGUAGE=en_GB:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages hugs depends on:
ii  libc6                                          2.31-13+deb11u5
ii  libhugs-base-bundled [libhugs-base]            98.200609.21-6
ii  libhugs-haskell98-bundled [libhugs-haskell98]  98.200609.21-6
ii  libreadline8                                   8.1-1

Versions of packages hugs recommends:
ii  libhugs-alut-bundled [libhugs-alut]                98.200609.21-6
ii  libhugs-cabal-bundled [libhugs-cabal]              98.200609.21-6
ii  libhugs-fgl-bundled [libhugs-fgl]                  98.200609.21-6
ii  libhugs-glut-bundled [libhugs-glut]                98.200609.21-6
ii  libhugs-haskell-src-bundled [libhugs-haskell-src]  98.200609.21-6
ii  libhugs-haxml-bundled [libhugs-haxml]              98.200609.21-6
ii  libhugs-hgl-bundled [libhugs-hgl]                  98.200609.21-6
ii  libhugs-hunit-bundled [libhugs-hunit]              98.200609.21-6
ii  libhugs-mtl-bundled [libhugs-mtl]                  98.200609.21-6
ii  libhugs-network-bundled [libhugs-network]          98.200609.21-6
ii  libhugs-openal-bundled [libhugs-openal]            98.200609.21-6
ii  libhugs-opengl-bundled [libhugs-opengl]            98.200609.21-6
ii  libhugs-parsec-bundled [libhugs-parsec]            98.200609.21-6
ii  libhugs-quickcheck-bundled [libhugs-quickcheck]    98.200609.21-6
ii  libhugs-stm-bundled [libhugs-stm]                  98.200609.21-6
ii  libhugs-time-bundled [libhugs-time]                98.200609.21-6
ii  libhugs-unix-bundled [libhugs-unix]                98.200609.21-6
ii  libhugs-x11-bundled [libhugs-x11]                  98.200609.21-6
ii  libhugs-xhtml-bundled [libhugs-xhtml]              98.200609.21-6

Versions of packages hugs suggests:
pn  cpphs         <none>
pn  haskell-doc   <none>
pn  haskell-mode  <none>

-- no debconf information
diff -wur old/hugs98-98.200609.21/src/bignums.c new/hugs98-98.200609.21/src/bignums.c
--- old/hugs98-98.200609.21/src/bignums.c	2004-10-29 13:43:09.000000000 +0100
+++ new/hugs98-98.200609.21/src/bignums.c	2023-02-01 11:15:18.575315477 +0000
@@ -117,7 +117,7 @@
 	unsigned long no;
 	Cell nx;
 	if (n<0) {
-	    no = (unsigned long)(-n);
+	    no = (unsigned long)(-(signed long)(n));
 	    bn = pair(NEGNUM,NIL);
 	}
 	else {

Reply to: