Subject: bin/12012: /usr/games/prime and /usr/games/factor assume 32bit long
To: None <>
From: None <>
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
>Originator:     Jun-ichiro itojun Hagino
>Release:        1.5Q (and all previous releases)
System: NetBSD 1.5Q NetBSD 1.5Q (STARFRUIT) #331: Thu Jan 18 15:40:52 JST 2001 i386
Architecture: i386
Machine: i386
	/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.
	code inspection.
	- 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.