diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-01-31 12:27:11 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-01-31 12:27:11 -0200 |
commit | 1143bf92868a9ec47107a302db43a8e5275d8d80 (patch) | |
tree | 648f463b6ea6bbc8985fa7681d90630800cdb62c /lua.stx | |
parent | d9ecc135458a8538c00e12db654513662262d300 (diff) | |
download | lua-1143bf92868a9ec47107a302db43a8e5275d8d80.tar.gz lua-1143bf92868a9ec47107a302db43a8e5275d8d80.tar.bz2 lua-1143bf92868a9ec47107a302db43a8e5275d8d80.zip |
better check when converting from float to int, to avoid overflow
(on some machines it may result in run-time error)
Diffstat (limited to 'lua.stx')
-rw-r--r-- | lua.stx | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -1,6 +1,6 @@ | |||
1 | %{ | 1 | %{ |
2 | 2 | ||
3 | char *rcs_luastx = "$Id: lua.stx,v 3.41 1996/11/08 12:49:35 roberto Exp roberto $"; | 3 | char *rcs_luastx = "$Id: lua.stx,v 3.42 1997/01/15 16:11:37 roberto Exp roberto $"; |
4 | 4 | ||
5 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
@@ -163,9 +163,9 @@ static void add_varbuffer (Long var) | |||
163 | 163 | ||
164 | static void code_number (float f) | 164 | static void code_number (float f) |
165 | { | 165 | { |
166 | Word i = (Word)f; | 166 | Word i; |
167 | if (f == (float)i) /* f has an (short) integer value */ | 167 | if (f >= 0 && f <= (float)MAX_WORD && (float)(i=(Word)f) == f) { |
168 | { | 168 | /* f has an (short) integer value */ |
169 | if (i <= 2) code_byte(PUSH0 + i); | 169 | if (i <= 2) code_byte(PUSH0 + i); |
170 | else if (i <= 255) | 170 | else if (i <= 255) |
171 | { | 171 | { |