[前][次][番号順一覧][スレッド一覧]

ruby-changes:21453

From: ngoto <ko1@a...>
Date: Sat, 22 Oct 2011 02:35:35 +0900 (JST)
Subject: [ruby-changes:21453] ngoto:r33502 (trunk): * numeric.c (rb_infinity, rb_nan): use union to prevent bus error

ngoto	2011-10-22 02:34:58 +0900 (Sat, 22 Oct 2011)

  New Revision: 33502

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33502

  Log:
    * numeric.c (rb_infinity, rb_nan): use union to prevent bus error
      caused by misalignment.  [Bug #5469] [ruby-dev:44657]
    * include/ruby/missing.h (INFINITY, NAN): ditto

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/missing.h
    trunk/numeric.c

Index: include/ruby/missing.h
===================================================================
--- include/ruby/missing.h	(revision 33501)
+++ include/ruby/missing.h	(revision 33502)
@@ -124,20 +124,27 @@
 RUBY_EXTERN double cbrt(double);
 #endif
 
+#if !defined(INFINITY) || !defined(NAN)
+union bytesequence4_or_float {
+  unsigned char bytesequence[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 bytesequence4_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 bytesequence4_or_float rb_nan;
+# define NAN (rb_nan.float_value)
 #endif
 
 #ifndef isinf
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33501)
+++ ChangeLog	(revision 33502)
@@ -1,3 +1,10 @@
+Sat Oct 22 02:07:48 2011  Naohisa Goto  <ngotogenome@g...>
+
+	* numeric.c (rb_infinity, rb_nan): use union to prevent bus error
+	  caused by misalignment.  [Bug #5469] [ruby-dev:44657]
+
+	* include/ruby/missing.h (INFINITY, NAN): ditto
+
 Fri Oct 21 22:02:17 2011  Nobuyoshi Nakada  <nobu@r...>
 
 	* gc.c (initial_params): pack in a struct.
Index: numeric.c
===================================================================
--- numeric.c	(revision 33501)
+++ numeric.c	(revision 33502)
@@ -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 bytesequence4_or_float rb_infinity = { 0x00, 0x00, 0x80, 0x7f };
 #else
-const unsigned char rb_infinity[] = "\x7f\x80\x00\x00";
+const union bytesequence4_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 bytesequence4_or_float rb_nan = { 0x00, 0x00, 0xc0, 0x7f };
 #else
-const unsigned char rb_nan[] = "\x7f\xc0\x00\x00";
+const union bytesequence4_or_float rb_nan = { 0x7f, 0xc0, 0x00, 0x00 };
 #endif
 
 #ifndef HAVE_ROUND

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]