Since we cannot guarantee that all machines do ieee math, or that they have

the proper math setup deal with SIGFPE directly.
This commit is contained in:
christos 2008-05-02 15:10:05 +00:00
parent 3ba209837a
commit 00c6e78061
2 changed files with 21 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: main1.c,v 1.17 2006/11/08 18:31:15 christos Exp $ */
/* $NetBSD: main1.c,v 1.18 2008/05/02 15:10:05 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: main1.c,v 1.17 2006/11/08 18:31:15 christos Exp $");
__RCSID("$NetBSD: main1.c,v 1.18 2008/05/02 15:10:05 christos Exp $");
#endif
#include <sys/types.h>
@ -47,6 +47,7 @@ __RCSID("$NetBSD: main1.c,v 1.17 2006/11/08 18:31:15 christos Exp $");
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#include <signal.h>
#include "lint1.h"
@ -119,10 +120,19 @@ int zflag = 1;
err_set msgset;
sig_atomic_t fpe;
static void usage(void);
int main(int, char *[]);
/*ARGSUSED*/
static void
sigfpe(int s)
{
fpe = 1;
}
int
main(int argc, char *argv[])
{
@ -198,6 +208,7 @@ main(int argc, char *argv[])
if (yflag)
yydebug = 1;
(void)signal(SIGFPE, sigfpe);
initmem();
initdecl();
initscan();

View File

@ -1,4 +1,4 @@
/* $NetBSD: tree.c,v 1.48 2008/04/27 01:45:04 christos Exp $ */
/* $NetBSD: tree.c,v 1.49 2008/05/02 15:10:05 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: tree.c,v 1.48 2008/04/27 01:45:04 christos Exp $");
__RCSID("$NetBSD: tree.c,v 1.49 2008/05/02 15:10:05 christos Exp $");
#endif
#include <stdlib.h>
@ -45,6 +45,7 @@ __RCSID("$NetBSD: tree.c,v 1.48 2008/04/27 01:45:04 christos Exp $");
#include <float.h>
#include <limits.h>
#include <math.h>
#include <signal.h>
#include "lint1.h"
#include "cgram.h"
@ -88,6 +89,8 @@ static void chkaidx(tnode_t *, int);
static void chkcomp(op_t, tnode_t *, tnode_t *);
static void precconf(tnode_t *);
extern sig_atomic_t fpe;
/*
* Initialize mods of operators.
*/
@ -2904,6 +2907,7 @@ foldflt(tnode_t *tn)
tspec_t t;
ldbl_t l, r = 0;
fpe = 0;
v = xcalloc(1, sizeof (val_t));
v->v_tspec = t = tn->tn_type->t_tspec;
@ -2974,7 +2978,7 @@ foldflt(tnode_t *tn)
if (isnan((double)v->v_ldbl))
LERROR("foldflt()");
if (!finite((double)v->v_ldbl) ||
if (fpe || !finite((double)v->v_ldbl) ||
(t == FLOAT &&
(v->v_ldbl > FLT_MAX || v->v_ldbl < -FLT_MAX)) ||
(t == DOUBLE &&
@ -2988,6 +2992,7 @@ foldflt(tnode_t *tn)
} else {
v->v_ldbl = v->v_ldbl < 0 ? -LDBL_MAX: LDBL_MAX;
}
fpe = 0;
}
return (getcnode(tn->tn_type, v));