Bug 1687838: Calculate array lengths using ArrayLength() in non-native theming code. r=emilio
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Thu, 21 Jan 2021 16:46:33 +0000
changeset 564140 a2934c39cf550ba016dca4987a1cf56f4ef22179
parent 564139 0c5204e9a61a94a6ef6297da50b47687599cfe99
child 564141 78b33bc1dbd1797e746f99440a6aa932a50730aa
push id134692
push userspohl@mozilla.com
push dateThu, 21 Jan 2021 16:55:23 +0000
treeherderautoland@a2934c39cf55 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1687838
milestone86.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 1687838: Calculate array lengths using ArrayLength() in non-native theming code. r=emilio Differential Revision: https://phabricator.services.mozilla.com/D102522
widget/android/nsNativeThemeAndroid.cpp
widget/nsNativeBasicTheme.cpp
--- a/widget/android/nsNativeThemeAndroid.cpp
+++ b/widget/android/nsNativeThemeAndroid.cpp
@@ -382,17 +382,17 @@ static void PaintMenulistArrowButton(nsI
 
   if (!isHTML && nsNativeTheme::CheckBooleanAttr(aFrame, nsGkAtoms::open)) {
     isHovered = false;
   }
 
   const int32_t arrowSize = 8;
   int32_t arrowPolygonX[] = {-4, -2, 0};
   int32_t arrowPolygonY[] = {-1, 1, -1};
-  const int32_t arrowNumPoints = sizeof(arrowPolygonX) / sizeof(int32_t);
+  const int32_t arrowNumPoints = ArrayLength(arrowPolygonX);
 
   PaintArrow(aDrawTarget, aRect, arrowPolygonX, arrowPolygonY, arrowNumPoints,
              arrowSize,
              isPressed   ? sActiveColor
              : isHovered ? sBorderHoverColor
                          : sBorderColor,
              aDpi);
 }
@@ -403,17 +403,17 @@ static void PaintSpinnerButton(DrawTarge
   bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
   bool isPressed = !isDisabled && aState.HasAllStates(NS_EVENT_STATE_HOVER |
                                                       NS_EVENT_STATE_ACTIVE);
   bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
 
   const int32_t arrowSize = 8;
   int32_t arrowPolygonX[] = {0, 2, 4};
   int32_t arrowPolygonY[] = {-3, -1, -3};
-  const int32_t arrowNumPoints = sizeof(arrowPolygonX) / sizeof(int32_t);
+  const int32_t arrowNumPoints = ArrayLength(arrowPolygonX);
 
   if (aAppearance == StyleAppearance::SpinnerUpbutton) {
     for (int32_t i = 0; i < arrowNumPoints; i++) {
       arrowPolygonY[i] *= -1;
     }
   }
 
   PaintArrow(aDrawTarget, aRect, arrowPolygonX, arrowPolygonY, arrowNumPoints,
@@ -501,17 +501,17 @@ static void PaintScrollbarbutton(DrawTar
   aDrawTarget->FillRect(
       aRect, ColorPattern(ToDeviceColor(isActive ? sScrollbarButtonActiveColor
                                         : isHovered ? sScrollbarButtonHoverColor
                                                     : sScrollbarColor)));
 
   // Start with Up arrow.
   int32_t arrowPolygonX[] = {3, 0, -3};
   int32_t arrowPolygonY[] = {2, -1, 2};
-  const int32_t arrowNumPoints = sizeof(arrowPolygonX) / sizeof(int32_t);
+  const int32_t arrowNumPoints = ArrayLength(arrowPolygonX);
   const int32_t arrowSize = 14;
 
   switch (aAppearance) {
     case StyleAppearance::ScrollbarbuttonUp:
       break;
     case StyleAppearance::ScrollbarbuttonDown:
       for (int32_t i = 0; i < arrowNumPoints; i++) {
         arrowPolygonY[i] *= -1;
--- a/widget/nsNativeBasicTheme.cpp
+++ b/widget/nsNativeBasicTheme.cpp
@@ -715,17 +715,17 @@ void nsNativeBasicTheme::PaintArrow(Draw
 void nsNativeBasicTheme::PaintMenulistArrowButton(nsIFrame* aFrame,
                                                   DrawTarget* aDrawTarget,
                                                   const LayoutDeviceRect& aRect,
                                                   const EventStates& aState) {
   const float arrowPolygonX[] = {-3.5f, -0.5f, 0.5f,  3.5f,  3.5f,
                                  3.0f,  0.5f,  -0.5f, -3.0f, -3.5f};
   const float arrowPolygonY[] = {-0.5f, 2.5f, 2.5f, -0.5f, -2.0f,
                                  -2.0f, 1.0f, 1.0f, -2.0f, -2.0f};
-  const int32_t arrowNumPoints = sizeof(arrowPolygonX) / sizeof(float);
+  const int32_t arrowNumPoints = ArrayLength(arrowPolygonX);
   sRGBColor arrowColor = ComputeMenulistArrowButtonColor(aState);
   PaintArrow(aDrawTarget, aRect, arrowPolygonX, arrowPolygonY, arrowNumPoints,
              arrowColor);
 }
 
 void nsNativeBasicTheme::PaintSpinnerButton(nsIFrame* aFrame,
                                             DrawTarget* aDrawTarget,
                                             const LayoutDeviceRect& aRect,
@@ -753,17 +753,17 @@ void nsNativeBasicTheme::PaintSpinnerBut
   aDrawTarget->Stroke(path, ColorPattern(ToDeviceColor(borderColor)),
                       StrokeOptions(kSpinnerBorderWidth * aDpiRatio));
 
   const float arrowPolygonX[] = {-3.5f, -0.5f, 0.5f,  3.5f,  3.5f,
                                  3.0f,  0.5f,  -0.5f, -3.0f, -3.5f};
   float arrowPolygonY[] = {-3.5f, -0.5f, -0.5f, -3.5f, -5.0f,
                            -5.0f, -2.0f, -2.0f, -5.0f, -5.0f};
 
-  const int32_t arrowNumPoints = sizeof(arrowPolygonX) / sizeof(float);
+  const int32_t arrowNumPoints = ArrayLength(arrowPolygonX);
   const float scale = ScaleToWidgetRect(aRect);
 
   if (aAppearance == StyleAppearance::SpinnerUpbutton) {
     for (int32_t i = 0; i < arrowNumPoints; i++) {
       arrowPolygonY[i] *= -1;
     }
   }
 
@@ -1090,17 +1090,17 @@ void nsNativeBasicTheme::PaintScrollbarB
       aFrame, aAppearance, aStyle, aElementState, aDocumentState);
   aDrawTarget->FillRect(aRect.ToUnknownRect(),
                         ColorPattern(ToDeviceColor(buttonColor)));
 
   // Start with Up arrow.
   float arrowPolygonX[] = {-3.0f, 0.0f, 3.0f, 3.0f, 0.0f, -3.0f};
   float arrowPolygonY[] = {0.4f, -3.1f, 0.4f, 2.7f, -0.8f, 2.7f};
 
-  const int32_t arrowNumPoints = sizeof(arrowPolygonX) / sizeof(float);
+  const int32_t arrowNumPoints = ArrayLength(arrowPolygonX);
   switch (aAppearance) {
     case StyleAppearance::ScrollbarbuttonUp:
       break;
     case StyleAppearance::ScrollbarbuttonDown:
       for (int32_t i = 0; i < arrowNumPoints; i++) {
         arrowPolygonY[i] *= -1;
       }
       break;