Issue #5469 has been updated by Nobuyoshi Nakada.

Category set to core
Status changed from Open to Assigned
Assignee set to Naohisa Goto
Target version set to 2.0

????????????????????????????????????????????????????

?????????stream???union中???????????{}???足????????????????????
# stream?????????????????????????????????????????????
----------------------------------------
Bug #5469: Bus Error when accessing NAN and INFINITY
http://redmine.ruby-lang.org/issues/5469

Author: Naohisa Goto
Status: Assigned
Priority: Normal
Assignee: Naohisa Goto
Category: core
Target version: 2.0
ruby -v: -


????INFINITY???NAN???????系???義????????????????????numeric.c ?????以?????????使?????????
 const unsigned char rb_infinity[] = "\x00\x00\x80\x7f";
 const unsigned char rb_nan[] = "\x00\x00\xc0\x7f";
(?????little endian?????????????????????)
???????????????????述??????????????????????????????????????????????????
????系??CPU??????????????????????????????????Bus Error ???????????
????????????Sparc Solaris 10 ???? Fujitsu C Compiler 5.6 ???????????????? Bus Error ??????????????

以??????????????????????????????????大?夫?????????
???????????????????????????????????????????????????????

???????述?? 1.9.3 ????????????????????????????????起????????????????????????????????????????????????????????????????

===================================================================
--- include/ruby/missing.h	(revision 33498)
+++ include/ruby/missing.h	(working copy)
@@ -124,20 +124,27 @@
 RUBY_EXTERN double cbrt(double);
 #endif
 
+#if !defined(INFINITY) || !defined(NAN)
+union bytestream4_or_float {
+  unsigned char stream[4]; 
+  float float_value;
+};
+#endif
+
 #ifdef INFINITY
 # define HAVE_INFINITY
 #else
 /** @internal */
-RUBY_EXTERN const unsigned char rb_infinity[];
-# define INFINITY (*(float *)rb_infinity)
+RUBY_EXTERN const union bytestream4_or_float rb_infinity;
+# define INFINITY (rb_infinity.float_value)
 #endif
 
 #ifdef NAN
 # define HAVE_NAN
 #else
 /** @internal */
-RUBY_EXTERN const unsigned char rb_nan[];
-# define NAN (*(float *)rb_nan)
+RUBY_EXTERN const union bytestream4_or_float rb_nan;
+# define NAN (rb_nan.float_value)
 #endif
 
 #ifndef isinf
Index: numeric.c
===================================================================
--- numeric.c	(revision 33498)
+++ numeric.c	(working copy)
@@ -66,16 +66,16 @@
 
 #ifdef HAVE_INFINITY
 #elif !defined(WORDS_BIGENDIAN) /* BYTE_ORDER == LITTLE_ENDIAN */
-const unsigned char rb_infinity[] = "\x00\x00\x80\x7f";
+const union bytestream4_or_float rb_infinity = { 0x00, 0x00, 0x80, 0x7f };
 #else
-const unsigned char rb_infinity[] = "\x7f\x80\x00\x00";
+const union bytestream4_or_float rb_infinity = { 0x7f, 0x80, 0x00, 0x00 };
 #endif
 
 #ifdef HAVE_NAN
 #elif !defined(WORDS_BIGENDIAN) /* BYTE_ORDER == LITTLE_ENDIAN */
-const unsigned char rb_nan[] = "\x00\x00\xc0\x7f";
+const union bytestream4_or_float rb_nan = { 0x00, 0x00, 0xc0, 0x7f };
 #else
-const unsigned char rb_nan[] = "\x7f\xc0\x00\x00";
+const union bytestream4_or_float rb_nan = { 0x7f, 0xc0, 0x00, 0x00 };
 #endif
 
 #ifndef HAVE_ROUND




-- 
http://redmine.ruby-lang.org