ScrollbarThemeComposite::thumbPosition uses the result of a divide by zero
authorleviw@chromium.org <leviw@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Feb 2012 20:57:43 +0000 (20:57 +0000)
committerleviw@chromium.org <leviw@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Feb 2012 20:57:43 +0000 (20:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78910

Reviewed by Eric Seidel.

Adding a check to avoid doing a floating point divide by zero and assigning NaN to an integer.
This causes problems with our conversion to subpixel layout, which asserts when we overflow.

* platform/ScrollbarThemeComposite.cpp:
(WebCore::ScrollbarThemeComposite::thumbPosition):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@108541 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/ScrollbarThemeComposite.cpp

index ed47482..22e18cf 100644 (file)
@@ -1,3 +1,16 @@
+2012-02-22  Levi Weintraub  <leviw@chromium.org>
+
+        ScrollbarThemeComposite::thumbPosition uses the result of a divide by zero
+        https://bugs.webkit.org/show_bug.cgi?id=78910
+
+        Reviewed by Eric Seidel.
+
+        Adding a check to avoid doing a floating point divide by zero and assigning NaN to an integer.
+        This causes problems with our conversion to subpixel layout, which asserts when we overflow.
+
+        * platform/ScrollbarThemeComposite.cpp:
+        (WebCore::ScrollbarThemeComposite::thumbPosition):
+
 2012-02-22  Raymond Liu  <raymond.liu@intel.com>
 
         Have the DynamicsCompressorNode support multi-channel data
index fcbf484..62fd5e5 100644 (file)
@@ -226,7 +226,11 @@ static float usedTotalSize(Scrollbar* scrollbar)
 int ScrollbarThemeComposite::thumbPosition(Scrollbar* scrollbar)
 {
     if (scrollbar->enabled()) {
-        float pos = max(0.0f, scrollbar->currentPos()) * (trackLength(scrollbar) - thumbLength(scrollbar)) / (usedTotalSize(scrollbar) - scrollbar->visibleSize());
+        float size = usedTotalSize(scrollbar) - scrollbar->visibleSize();
+        // Avoid doing a floating point divide by zero and return 1 when usedTotalSize == visibleSize.
+        if (!size)
+            return 1;
+        float pos = max(0.0f, scrollbar->currentPos()) * (trackLength(scrollbar) - thumbLength(scrollbar)) / size;
         return (pos < 1 && pos > 0) ? 1 : pos;
     }
     return 0;