Bug 1411584 - avoid using memset on a non-trivial type object. r?kip
MozReview-Commit-ID: CW1OChvGoE9
--- 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