NetBSD Problem Report #43609

From www@NetBSD.org  Tue Jul 13 06:22:39 2010
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id D614363BADB
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 13 Jul 2010 06:22:39 +0000 (UTC)
Message-Id: <20100713062239.A2A5463BACE@www.NetBSD.org>
Date: Tue, 13 Jul 2010 06:22:39 +0000 (UTC)
From: kretschm@cs.uni-bonn.de
Reply-To: kretschm@cs.uni-bonn.de
To: gnats-bugs@NetBSD.org
Subject: hugs98 overflow bug when printing Integers on platforms with sizeof(long) != sizeof(int)
X-Send-Pr-Version: www-1.0

>Number:         43609
>Category:       pkg
>Synopsis:       hugs98 overflow bug when printing Integers on platforms with sizeof(long) != sizeof(int)
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 13 06:25:00 +0000 2010
>Last-Modified:  Wed Jul 14 14:05:02 +0000 2010
>Originator:     Matthias Kretschmer
>Release:        NetBSD 5.0.2_PATCH
>Organization:
>Environment:
NetBSD random87 5.0.2 NetBSD 5.0.2 (GENERIC) amd64
>Description:
If you convert Int to Integer using toInteger, then there is a sign extension bug in the underlying primitive.  This is only triggered on platforms with sizeof(long)==8 > sizeof(int)==4.

If you have the sign extension bug, then toInteger (minBound :: Int), toInteger (minBound :: Data.Int.Int32), etc. return false results.
>How-To-Repeat:
compile hugs98 on amd64 or any other LP64 platform and do the following in the interpreter:

Hugs> toInteger (minBound :: Int)
-18446744071562067968


where as it should read

Hugs> toInteger (minBound :: Int)
-2147483648
>Fix:
Changing src/bignums.c line 120 from

    no = (unsigned long)(-n);

to

    no = (unsigned long)(-(long)n);

solves the problem.

>Audit-Trail:
From: "OBATA Akio" <obache@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/43609: hugs98 overflow bug when printing Integers on
 platforms with sizeof(long) != sizeof(int)
Date: Wed, 14 Jul 2010 22:40:36 +0900

 Did you sent this issue to upstream?

From: Matthias Kretschmer <kretschm@cs.uni-bonn.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: pkg/43609: hugs98 overflow bug when printing Integers on platforms with sizeof(long) != sizeof(int)
Date: Wed, 14 Jul 2010 15:47:41 +0200

 Hi

 On Wed, Jul 14, 2010 at 01:45:03PM +0000, OBATA Akio wrote:
 >  Did you sent this issue to upstream?

 forgot to mention that I sent this to upstream some months ago.
 As nobody is reacting to this I thought it would at least be nice
 to have the patch included in pkgsrc.

From: "OBATA Akio" <obache@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/43609: hugs98 overflow bug when printing Integers on
 platforms with sizeof(long) != sizeof(int)
Date: Wed, 14 Jul 2010 23:01:10 +0900

 On Wed, 14 Jul 2010 22:50:03 +0900, Matthias Kretschmer <kretschm@cs.uni-bonn.de> wrote:

 >  forgot to mention that I sent this to upstream some months ago.
 >  As nobody is reacting to this I thought it would at least be nice
 >  to have the patch included in pkgsrc.

 I can't find your bug report.
 Could you show the ticket#? or url in The Hugs-Bugs Archives?

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.