Bug 1400148 - Don't use -1 to represent an unset nsCursor. r=karlt.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 15 Sep 2017 14:34:37 +1000
changeset 430947 ff9e183ca0fe4d0f4afde67a56777769357477b8
parent 430946 f8c3e7d5f10df3296e0547284ec97fe74852a0bd
child 430948 ffe6cc09ccf38cca6f0e727837bbc6cb722d1e71
child 430966 c5d8edcea43b1d186f467f5138c825d80705e109
push id7775
push userryanvm@gmail.com
push dateTue, 19 Sep 2017 01:22:09 +0000
treeherdermozilla-beta@a0f805dbe65d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1400148
milestone57.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 1400148 - Don't use -1 to represent an unset nsCursor. r=karlt. Because UBSan complains about casting -1: > runtime error: load of value 4294967295, which is not a valid value for type 'nsCursor'
dom/ipc/TabParent.cpp
widget/PuppetWidget.cpp
widget/gtk/nsWindow.cpp
widget/nsIWidget.h
widget/windows/nsWindow.cpp
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -159,17 +159,17 @@ TabParent::TabParent(nsIContentParent* a
   , mDocShellIsActive(false)
   , mMarkedDestroying(false)
   , mIsDestroyed(false)
   , mChromeFlags(aChromeFlags)
   , mDragValid(false)
   , mInitedByParent(false)
   , mTabId(aTabId)
   , mCreatingWindow(false)
-  , mCursor(nsCursor(-1))
+  , mCursor(eCursorInvalid)
   , mTabSetsCursor(false)
   , mHasContentOpener(false)
 #ifdef DEBUG
   , mActiveSupressDisplayportCount(0)
 #endif
   , mLayerTreeEpoch(0)
   , mPreserveLayers(false)
   , mHasPresented(false)
@@ -1126,17 +1126,17 @@ TabParent::SendRealMouseEvent(WidgetMous
   if (widget) {
     // When we mouseenter the tab, the tab's cursor should
     // become the current cursor.  When we mouseexit, we stop.
     if (eMouseEnterIntoWidget == aEvent.mMessage) {
       mTabSetsCursor = true;
       if (mCustomCursor) {
         widget->SetCursor(mCustomCursor,
                           mCustomCursorHotspotX, mCustomCursorHotspotY);
-      } else if (mCursor != nsCursor(-1)) {
+      } else if (mCursor != eCursorInvalid) {
         widget->SetCursor(mCursor);
       }
     } else if (eMouseExitFromWidget == aEvent.mMessage) {
       mTabSetsCursor = false;
     }
   }
   if (!mIsReadyToHandleInputEvents) {
     if (eMouseEnterIntoWidget == aEvent.mMessage) {
@@ -1782,17 +1782,17 @@ TabParent::RecvSetCustomCursor(const nsC
                                const uint32_t& aWidth,
                                const uint32_t& aHeight,
                                const uint32_t& aStride,
                                const uint8_t& aFormat,
                                const uint32_t& aHotspotX,
                                const uint32_t& aHotspotY,
                                const bool& aForce)
 {
-  mCursor = nsCursor(-1);
+  mCursor = eCursorInvalid;
 
   nsCOMPtr<nsIWidget> widget = GetWidget();
   if (widget) {
     if (aForce) {
       widget->ClearCachedCursor();
     }
 
     if (mTabSetsCursor) {
--- a/widget/PuppetWidget.cpp
+++ b/widget/PuppetWidget.cpp
@@ -1007,17 +1007,17 @@ PuppetWidget::SetCursor(imgIContainer* a
   nsDependentCString cursorData(surfaceData.get(), length);
   mozilla::gfx::IntSize size = dataSurface->GetSize();
   if (!mTabChild->SendSetCustomCursor(cursorData, size.width, size.height, stride,
                                       static_cast<uint8_t>(dataSurface->GetFormat()),
                                       aHotspotX, aHotspotY, mUpdateCursor)) {
     return NS_ERROR_FAILURE;
   }
 
-  mCursor = nsCursor(-1);
+  mCursor = eCursorInvalid;
   mCustomCursor = aCursor;
   mCursorHotspotX = aHotspotX;
   mCursorHotspotY = aHotspotY;
   mUpdateCursor = false;
 
   return NS_OK;
 }
 
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -1618,17 +1618,17 @@ nsWindow::SetCursor(imgIContainer* aCurs
     if (!mContainer && mGdkWindow) {
         nsWindow *window = GetContainerWindow();
         if (!window)
             return NS_ERROR_FAILURE;
 
         return window->SetCursor(aCursor, aHotspotX, aHotspotY);
     }
 
-    mCursor = nsCursor(-1);
+    mCursor = eCursorInvalid;
 
     // Get the image's current frame
     GdkPixbuf* pixbuf = nsImageToPixbuf::ImageToPixbuf(aCursor);
     if (!pixbuf)
         return NS_ERROR_NOT_AVAILABLE;
 
     int width = gdk_pixbuf_get_width(pixbuf);
     int height = gdk_pixbuf_get_height(pixbuf);
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -206,18 +206,22 @@ enum nsCursor {   ///(normal cursor,    
                 eCursor_no_drop,
                 eCursor_vertical_text,
                 eCursor_all_scroll,
                 eCursor_nesw_resize,
                 eCursor_nwse_resize,
                 eCursor_ns_resize,
                 eCursor_ew_resize,
                 eCursor_none,
-                // This one better be the last one in this list.
-                eCursorCount
+                // This one is used for array sizing, and so better be the last
+                // one in this list...
+                eCursorCount,
+
+                // ...except for this one.
+                eCursorInvalid = eCursorCount + 1
                 };
 
 enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
   eZPlacementBottom = 0,  // bottom of the window stack
   eZPlacementBelow,       // just below another widget
   eZPlacementTop          // top of the window stack
 };
 
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -3015,17 +3015,17 @@ nsWindow::SetCursor(imgIContainer* aCurs
     return NS_ERROR_NOT_AVAILABLE;
 
   HCURSOR cursor;
   double scale = GetDefaultScale().scale;
   IntSize size = RoundedToInt(Size(width * scale, height * scale));
   rv = nsWindowGfx::CreateIcon(aCursor, true, aHotspotX, aHotspotY, size, &cursor);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  mCursor = nsCursor(-1);
+  mCursor = eCursorInvalid;
   ::SetCursor(cursor);
 
   NS_IF_RELEASE(sCursorImgContainer);
   sCursorImgContainer = aCursor;
   NS_ADDREF(sCursorImgContainer);
 
   if (sHCursor != nullptr)
     ::DestroyIcon(sHCursor);
@@ -7174,17 +7174,17 @@ void nsWindow::OnDestroy()
 
   // Free GDI window class objects
   if (mBrush) {
     VERIFY(::DeleteObject(mBrush));
     mBrush = nullptr;
   }
 
   // Destroy any custom cursor resources.
-  if (mCursor == -1)
+  if (mCursor == eCursorInvalid)
     SetCursor(eCursor_standard);
 
   if (mCompositorWidgetDelegate) {
     mCompositorWidgetDelegate->OnDestroyWindow();
   }
   mBasicLayersSurface = nullptr;
 
   // Finalize panning feedback to possibly restore window displacement