Bug 1411584 - avoid using memset on a non-trivial type object. r?kip draft
authorAndi-Bogdan Postelnicu <bpostelnicu@mozilla.com>
Thu, 26 Oct 2017 11:41:22 +0300
changeset 686694 b5f58c4f34436848d6bf6b2e06c49580afbb7406
parent 686540 64bab5cbb9b63808d04babfbcfba3175fd99f69d
child 737437 9d693cf7c4ef47ebf271a54633cb7dababb721c0
push id86257
push userbmo:bpostelnicu@mozilla.com
push dateThu, 26 Oct 2017 08:41:50 +0000
reviewerskip
bugs1411584
milestone58.0a1
Bug 1411584 - avoid using memset on a non-trivial type object. r?kip MozReview-Commit-ID: CW1OChvGoE9
dom/gamepad/GamepadPoseState.h
--- a/dom/gamepad/GamepadPoseState.h
+++ b/dom/gamepad/GamepadPoseState.h
@@ -41,18 +41,26 @@ struct GamepadPoseState
   float angularVelocity[3];
   float angularAcceleration[3];
   float linearVelocity[3];
   float linearAcceleration[3];
   bool isPositionValid;
   bool isOrientationValid;
 
   GamepadPoseState()
+    : flags(GamepadCapabilityFlags::Cap_None)
+    , orientation{ 0, 0, 0, 0 }
+    , position{ 0, 0, 0}
+    , angularVelocity{ 0, 0, 0}
+    , angularAcceleration{ 0, 0, 0}
+    , linearVelocity{ 0, 0, 0}
+    , linearAcceleration{ 0, 0, 0}
+    , isPositionValid(false)
+    , isOrientationValid(false)
   {
-    Clear();
   }
 
   bool operator==(const GamepadPoseState& aPose) const
   {
     return flags == aPose.flags
            && orientation[0] == aPose.orientation[0]
            && orientation[1] == aPose.orientation[1]
            && orientation[2] == aPose.orientation[2]
@@ -77,16 +85,19 @@ struct GamepadPoseState
   }
 
   bool operator!=(const GamepadPoseState& aPose) const
   {
     return !(*this == aPose);
   }
 
   void Clear() {
-    memset(this, 0, sizeof(GamepadPoseState));
+    memset(&flags,
+           0,
+           reinterpret_cast<char*>(&isOrientationValid) +
+             sizeof(isOrientationValid) - reinterpret_cast<char*>(&flags));
   }
 };
 
 }// namespace dom
 }// namespace mozilla
 
 #endif // mozilla_dom_gamepad_GamepadPoseState_h_
\ No newline at end of file