Permalink
Browse files

Fix cast in C_random_fixnum so it doesn't cause overflow and truncati…

…on on amd64 for large arguments like most-positive-fixnum (as used in hash-tables)

Signed-off-by: felix <felix@call-with-current-continuation.org>
(cherry picked from commit 140d713)
  • Loading branch information...
1 parent 2a7de60 commit ab8b1a3cc615d3bfeba71e39c5fbd0faa519714a Peter Bex committed with Feb 29, 2012
Showing with 1 addition and 1 deletion.
  1. +1 −1 chicken.h
View
@@ -1122,7 +1122,7 @@ extern double trunc(double);
C_unfix(end1) - C_unfix(start1) ), C_SCHEME_UNDEFINED)
#define C_words(n) C_fix(C_bytestowords(C_unfix(n)))
#define C_bytes(n) C_fix(C_wordstobytes(C_unfix(n)))
-#define C_random_fixnum(n) C_fix((int)(((double)rand())/(RAND_MAX + 1.0) * C_unfix(n)))
+#define C_random_fixnum(n) C_fix((C_word)(((double)rand())/(RAND_MAX + 1.0) * C_unfix(n)))
#define C_randomize(n) (srand(C_unfix(n)), C_SCHEME_UNDEFINED)
#define C_block_size(x) C_fix(C_header_size(x))
#define C_pointer_address(x) ((C_byte *)C_block_item((x), 0))

0 comments on commit ab8b1a3

Please sign in to comment.