Subject: Re: reproduceable "integer divide fault trap": solved
To: None <netbsd-help@netbsd.org>
From: Jonathan A. Kollasch <jakllsch@kollasch.net>
List: netbsd-help
Date: 11/27/2005 14:41:46
--17pEHd4RhPHOinZp
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sun, Nov 27, 2005 at 12:47:52AM -0500, Christos Zoulas wrote:
> Good catch. I think that is a gcc bug. Can you try changing the code
> so that the comparison is between 2 64 bit quantities?

I changed:

cgsize = fs->fs_fsize * fs->fs_fpg;
to
cgsize = (int64_t)fs->fs_fsize * (int64_t)fs->fs_fpg;

dirsize = fs->fs_avgfilesize * fs->fs_avgfpdir;
to
dirsize = (int64_t)fs->fs_avgfilesize * (int64_t)fs->fs_avgfpdir;

if (dirsize < curdirsize)
to
if (dirsize < (int64_t)curdirsize)

mkdir(1) now works fine. Notably I tested the cgsize and dirsize variables with
and without the casts and they indeed differ on my wd1e slice. I'm not
sure if the cast in the "if" expression is necessary but I'd rather be safe
than dividing by zero. Thanks to David and Pavel for pointing out the dirsize
and cgsize problems. Thanks to all for your prompt help. I'll submit a PR with
these changes. For which branches should I request pullups?

	Jonathan Kollasch

here's the difference with and without the casts of a mkdir in a
2nd level directory of wd1e:

Nov 27 14:20:37 gallifrey /netbsd: cgsize 32b args 0xFFFFFFFFEF620000
Nov 27 14:20:37 gallifrey /netbsd: cgsize 64b args 0x5EF620000
Nov 27 14:20:37 gallifrey /netbsd: dirsize 32b args 0x0
Nov 27 14:20:37 gallifrey /netbsd: dirsize 64b args 0x800000000

--17pEHd4RhPHOinZp
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (NetBSD)

iD8DBQFDihoKOjx1ye3hmokRAjG5AJ0RWa4qStChrWv3mz6qcLXA8v93LACeNbH3
nf9d2fLELfn+3GA4ray3bMU=
=VB0u
-----END PGP SIGNATURE-----

--17pEHd4RhPHOinZp--