浏览代码

Replace type punning with explicit memcpys

Turo Lamminen 7 年之前
父节点
当前提交
6aa32b41a1
共有 1 个文件被更改,包括 14 次插入6 次删除
  1. 14 6
      include/assimp/qnan.h

+ 14 - 6
include/assimp/qnan.h

@@ -98,8 +98,10 @@ AI_FORCE_INLINE bool is_qnan(float in)
     //   compare <register-with-different-width> against <in>
     //   compare <register-with-different-width> against <in>
 
 
     // FIXME: Use <float> stuff instead? I think fpclassify needs C99
     // FIXME: Use <float> stuff instead? I think fpclassify needs C99
-    return (reinterpret_cast<_IEEESingle*>(&in)->IEEE.Exp == (1u << 8)-1 &&
-        reinterpret_cast<_IEEESingle*>(&in)->IEEE.Frac);
+    _IEEESingle temp;
+    memcpy(&temp, &in, sizeof(float));
+    return (temp.IEEE.Exp == (1u << 8)-1 &&
+        temp.IEEE.Frac);
 }
 }
 
 
 // ---------------------------------------------------------------------------
 // ---------------------------------------------------------------------------
@@ -114,8 +116,10 @@ AI_FORCE_INLINE bool is_qnan(double in)
     //   compare <register-with-different-width> against <in>
     //   compare <register-with-different-width> against <in>
 
 
     // FIXME: Use <float> stuff instead? I think fpclassify needs C99
     // FIXME: Use <float> stuff instead? I think fpclassify needs C99
-    return (reinterpret_cast<_IEEEDouble*>(&in)->IEEE.Exp == (1u << 11)-1 &&
-        reinterpret_cast<_IEEEDouble*>(&in)->IEEE.Frac);
+    _IEEEDouble temp;
+    memcpy(&temp, &in, sizeof(in));
+    return (temp.IEEE.Exp == (1u << 11)-1 &&
+        temp.IEEE.Frac);
 }
 }
 
 
 // ---------------------------------------------------------------------------
 // ---------------------------------------------------------------------------
@@ -125,7 +129,9 @@ AI_FORCE_INLINE bool is_qnan(double in)
  *  @param in Input value */
  *  @param in Input value */
 AI_FORCE_INLINE bool is_special_float(float in)
 AI_FORCE_INLINE bool is_special_float(float in)
 {
 {
-    return (reinterpret_cast<_IEEESingle*>(&in)->IEEE.Exp == (1u << 8)-1);
+    _IEEESingle temp;
+    memcpy(&temp, &in, sizeof(float));
+    return (temp.IEEE.Exp == (1u << 8)-1);
 }
 }
 
 
 // ---------------------------------------------------------------------------
 // ---------------------------------------------------------------------------
@@ -135,7 +141,9 @@ AI_FORCE_INLINE bool is_special_float(float in)
  *  @param in Input value */
  *  @param in Input value */
 AI_FORCE_INLINE bool is_special_float(double in)
 AI_FORCE_INLINE bool is_special_float(double in)
 {
 {
-    return (reinterpret_cast<_IEEEDouble*>(&in)->IEEE.Exp == (1u << 11)-1);
+   _IEEESingle temp;
+    memcpy(&temp, &in, sizeof(float));
+    return (temp.IEEE.Exp == (1u << 11)-1);
 }
 }
 
 
 // ---------------------------------------------------------------------------
 // ---------------------------------------------------------------------------