From nobody@FreeBSD.ORG Mon Jul 12 11:05:07 1999
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id 2248E150C7; Mon, 12 Jul 1999 11:05:07 -0700 (PDT)
Message-Id: <19990712180507.2248E150C7@hub.freebsd.org>
Date: Mon, 12 Jul 1999 11:05:07 -0700 (PDT)
From: frodef@acm.org
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@freebsd.org
Subject: /usr/bin/jot crashes with floating point exception
X-Send-Pr-Version: www-1.0

>Number:         12611
>Category:       bin
>Synopsis:       /usr/bin/jot crashes with floating point exception
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    sheldonh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 12 11:10:01 PDT 1999
>Closed-Date:    Thu Jun 22 06:07:08 PDT 2000
>Last-Modified:  Thu Jun 22 06:07:51 PDT 2000
>Originator:     Frode Vatvedt Fjeld
>Release:        stable
>Organization:
University of Troms, Norway
>Environment:
FreeBSD dslab7.cs.uit.no 3.2-STABLE FreeBSD 3.2-STABLE #31:
Thu Jun 24 20:16:38 CEST 1999
frodef@dslab7.cs.uit.no:/usr/src/sys/compile/FVF-KERNEL  i386
>Description:
/usr/bin/jot core-dumps with a floating point exception when
trying to generate a large (32-bit) random number.
>How-To-Repeat:
% jot -r 1 -p 4294967296
zsh: floating point exception (core dumped)  jot -r 1 -p 4294967296

>Fix:


>Release-Note:
>Audit-Trail:

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: frodef@acm.org
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/12611: /usr/bin/jot crashes with floating point exception 
Date: Tue, 13 Jul 1999 12:46:45 +0200

 On Mon, 12 Jul 1999 11:05:07 MST, frodef@acm.org wrote:
 
 > >How-To-Repeat:
 > % jot -r 1 -p 4294967296
 > zsh: floating point exception (core dumped)  jot -r 1 -p 4294967296
 
 It's not always reproducible because it relies on a random number, which
 might be small on any given run. However, when it does fail, I get the
 following:
 
 | (gdb) set args -r 1 -p 4294967296
 | (gdb) run
 | Starting program: /usr/bin/jot -r 1 -p 4294967296
 | 
 | Program received signal SIGFPE, Arithmetic exception.
 | 0x804918b in putdata (x=4058183150.1194973, notlast=0)
 |     at /usr/src/usr.bin/jot/jot.c:313
 | 313             long            d = x;
 | (gdb) back
 | #0  0x804918b in putdata (x=4058183150.1194973, notlast=0)
 |     at /usr/src/usr.bin/jot/jot.c:313
 | #1  0x804881e in main (argc=5, argv=0xbfbfd680)
 |     at /usr/src/usr.bin/jot/jot.c:106
 | #2  0x80486d1 in _start ()
 
 It looks like a simple assignment from a long to a double. Try the
 following patch.
 
 Ciao,
 Sheldon.
 
 Index: jot.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/jot/jot.c,v
 retrieving revision 1.9
 diff -u -d -r1.9 jot.c
 --- jot.c	1999/05/13 12:18:24	1.9
 +++ jot.c	1999/07/13 10:42:06
 @@ -310,8 +310,8 @@
  	double x;
  	long notlast;
  {
 -	long		d = x;
 -	register long	*dp = &d;
 +	double		d = x;
 +	register double	*dp = &d;
  
  	if (boring)				/* repeated word */
  		printf(format);
 
State-Changed-From-To: open->feedback 
State-Changed-By: sheldonh 
State-Changed-When: Tue Jul 13 04:08:58 PDT 1999 
State-Changed-Why:  
Waiting for submitter's feedback on supplied patch. 
Responsible-Changed-From-To: freebsd-bugs->sheldonh 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Tue Jul 13 04:09:44 PDT 1999 
Responsible-Changed-Why:  
Looks like I'll take this one. :-) 

From: Frode Vatvedt Fjeld <frodef@acm.org>
To: Sheldon Hearn <sheldonh@uunet.co.za>
Cc:  
Subject: Re: bin/12611: /usr/bin/jot crashes with floating point exception
Date: 13 Jul 1999 14:09:40 +0200

 Sheldon Hearn <sheldonh@uunet.co.za> writes:
 > It's not always reproducible because it relies on a random number,
 
 Right, I forgot that in my report. Your patch seems to do the trick
 here, I get no more core-dumps.
 
 Thanks,
 -- 
 Frode Vatvedt Fjeld
 
 
State-Changed-From-To: feedback->analyzed 
State-Changed-By: sheldonh 
State-Changed-When: Mon Jul 19 03:17:39 PDT 1999 
State-Changed-Why:  
My patch isn't a proper fix. We need to do two things. First, we need to 
fix jot's printf(3) conversion specifier parsing in getformat(). Then 
we need to fix the main code so that it uses the correct data types for 
each of (chardata), (dox) and (!(chardata || dox)). I'm working on it. 
State-Changed-From-To: analyzed->suspended 
State-Changed-By: sheldonh 
State-Changed-When: Thu Jul 22 10:36:34 PDT 1999 
State-Changed-Why:  
Doing it the right way is too much work. I've done the conversion  
specifier format parsing part of the fix and installed a signal 
handler to avoid dropping core on overflow. I'll leave this 
suspended for anyone looking for a challenge. :-) 
State-Changed-From-To: suspended->closed 
State-Changed-By: sheldonh 
State-Changed-When: Thu Jun 22 06:07:08 PDT 2000 
State-Changed-Why:  
FreeBSD now uses the less strict policy for exceptions, motting 
this point. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=12611 
>Unformatted:
