Bug 1532868 - Use multiplication rather than left-shift to avoid potential UB in FontPropertyValue constructor. r=jwatt
authorJonathan Kew <jkew@mozilla.com>
Mon, 18 Mar 2019 16:26:56 +0000
changeset 464922 2db1d305083d4ee0d08104786507706ca8c5ad90
parent 464915 70baa37ae1eb12e2dec584fecf82453d6f4b17b4
child 464923 07a1ab95598e298d92faf62534869ea45e8cd979
push id35729
push useropoprus@mozilla.com
push dateTue, 19 Mar 2019 16:30:13 +0000
treeherdermozilla-central@1d783ed68779 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1532868
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1532868 - Use multiplication rather than left-shift to avoid potential UB in FontPropertyValue constructor. r=jwatt Differential Revision: https://phabricator.services.mozilla.com/D22999
gfx/src/FontPropertyTypes.h
--- a/gfx/src/FontPropertyTypes.h
+++ b/gfx/src/FontPropertyTypes.h
@@ -93,32 +93,32 @@ class FontPropertyValue {
  protected:
   // Construct from a floating-point or integer value, checking that it is
   // within the allowed range and converting to fixed-point representation.
   explicit constexpr FontPropertyValue(float aValue)
       : mValue(std::round(aValue * kScale)) {
     MOZ_ASSERT(aValue >= kMin && aValue <= kMax);
   }
   explicit constexpr FontPropertyValue(int aValue)
-      : mValue(aValue << kFractionBits) {
+      : mValue(aValue * kScale) {
     MOZ_ASSERT(aValue >= Min && aValue <= Max);
   }
 
   // Construct directly from a fixed-point value of type T, with no check;
   // note that there may be special "flag" values that are outside the normal
   // min/max range (e.g. for font-style:italic, distinct from oblique angle).
   explicit constexpr FontPropertyValue(InternalType aValue) : mValue(aValue) {}
 
   // This is protected as it may not be the most appropriate accessor for a
   // given instance to expose. It's up to each individual property to provide
   // public accessors that forward to this as required.
   float ToFloat() const { return mValue * kInverseScale; }
   int ToIntRounded() const { return (mValue + kPointFive) >> FractionBits; }
 
-  static constexpr float kScale = float(1u << FractionBits);
+  static constexpr int kScale = 1 << FractionBits;
   static constexpr float kInverseScale = 1.0f / kScale;
   static const unsigned kFractionBits = FractionBits;
 
   // Constant representing 0.5 in the internal representation (note this
   // assumes that kFractionBits is greater than zero!)
   static const InternalType kPointFive = 1u << (kFractionBits - 1);
 
   InternalType mValue;