Subject: bin/12012: /usr/games/prime and /usr/games/factor assume 32bit long
To: None <gnats-bugs@gnats.netbsd.org>
From: None <itojun@itojun.org>
List: netbsd-bugs
Date: 01/20/2001 07:17:22
>Number:         12012
>Category:       bin
>Synopsis:       /usr/games/prime and /usr/games/factor assume 32bit long
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 20 07:20:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Jun-ichiro itojun Hagino
>Release:        1.5Q (and all previous releases)
>Organization:
	itojun.org
>Environment:
System: NetBSD starfruit.itojun.org 1.5Q NetBSD 1.5Q (STARFRUIT) #331: Thu Jan 18 15:40:52 JST 2001 itojun@starfruit.itojun.org:/usr/home/itojun/NetBSD/src/sys/arch/i386/compile/STARFRUIT i386
Architecture: i386
Machine: i386
>Description:
	/usr/games/{prime,factor} uses fixed Eratosthenes sieve table,
	which has up to 65537.  since 2^32 - 1 < 65537^2 < 2^33 - 1,
	they can only support 32bit values.

	the tools use "unsigned long" as the type to hold internal
	computation results. 
	on 32bit architectures (like i386), the tools will raise error if we
	give a value larger than 32bit, due to strtoul() overflow.
	on non-32bit architectures we support (like alpha), long is bigger
	than 32bits (like 64bits).  so strtoul() succeeds even with values
	larger than 2^32, and the tools can give bogus results.
>How-To-Repeat:
	code inspection.
>Fix:
	- use u_int32_t to hold internal computation results.
	- grow sieve table as necessary.  for huge numbers, this change can
	  result in slower computation time.
>Release-Note:
>Audit-Trail:
>Unformatted: