From 3f4b26a46f907a6c4641512a6e3d6f4c90937f69 Mon Sep 17 00:00:00 2001 From: JeffBezanson Date: Tue, 16 Aug 2011 19:59:46 +0000 Subject: [PATCH] checking for overflow in integer literals fixing FLT_EPSILON --- femtolisp/Makefile | 2 +- femtolisp/read.c | 6 ++++++ llt/Makefile | 2 +- llt/dtypes.h | 2 +- llt/fp.c | 1 - 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/femtolisp/Makefile b/femtolisp/Makefile index eb03b4e..98af21a 100644 --- a/femtolisp/Makefile +++ b/femtolisp/Makefile @@ -11,7 +11,7 @@ LLT = $(LLTDIR)/libllt.a # OS flags: LINUX, WIN32, MACOSX # architecture flags: __CPU__=xxx, BITS64, ARCH_X86, ARCH_X86_64 -CONFIG = -DLINUX -DARCH_X86 -D__CPU__=586 +CONFIG = -DLINUX -DARCH_X86_64 -DBITS64 -D__CPU__=686 FLAGS = -falign-functions -Wall -Wno-strict-aliasing -I$(LLTDIR) $(CFLAGS) -DUSE_COMPUTED_GOTO $(CONFIG) LIBFILES = $(LLT) LIBS = $(LIBFILES) -lm diff --git a/femtolisp/read.c b/femtolisp/read.c index e3aae72..8b08dc0 100644 --- a/femtolisp/read.c +++ b/femtolisp/read.c @@ -60,11 +60,17 @@ int isnumtok_base(char *tok, value_t *pval, int base) if (pval) *pval = mk_double(D_NINF); return 1; } + errno = 0; i64 = strtoll(tok, &end, base); + if (errno) + return 0; if (pval) *pval = return_from_int64(i64); return (*end == '\0'); } + errno = 0; ui64 = strtoull(tok, &end, base); + if (errno) + return 0; if (pval) *pval = return_from_uint64(ui64); return (*end == '\0'); } diff --git a/llt/Makefile b/llt/Makefile index 49aabbe..4ff895a 100644 --- a/llt/Makefile +++ b/llt/Makefile @@ -12,7 +12,7 @@ TESTER = llttest # OS flags: LINUX, WIN32, MACOSX # architecture flags: __CPU__=xxx, BITS64, ARCH_X86, ARCH_X86_64 -CONFIG = -DLINUX -DARCH_X86 -D__CPU__=586 +CONFIG = -DLINUX -DARCH_X86_64 -DBITS64 -D__CPU__=686 FLAGS = -Wall -Wno-strict-aliasing $(CFLAGS) $(CONFIG) LIBS = diff --git a/llt/dtypes.h b/llt/dtypes.h index 713802b..c38f6ca 100644 --- a/llt/dtypes.h +++ b/llt/dtypes.h @@ -156,7 +156,7 @@ typedef u_ptrint_t uptrint_t; #define BIT31 0x80000000 #define DBL_EPSILON 2.2204460492503131e-16 -#define FLT_EPSILON 1.1920928e-7 +#define FLT_EPSILON 1.192092896e-7 #define DBL_MAX 1.7976931348623157e+308 #define DBL_MIN 2.2250738585072014e-308 #define FLT_MAX 3.402823466e+38 diff --git a/llt/fp.c b/llt/fp.c index 12731fc..a48ecd7 100644 --- a/llt/fp.c +++ b/llt/fp.c @@ -47,7 +47,6 @@ static inline int64_t llabs(int64_t j) return NBABS(j, 64); } #else -extern int64_t llabs(int64_t j); #endif int dbl_equals(double a, double b)