[haiku-commits] haiku: hrev48748 - src/servers/app/decorator

  • From: jscipione@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 29 Jan 2015 22:40:01 +0100 (CET)

hrev48748 adds 2 changesets to branch 'master'
old head: 78a5e0daeeecf27cda89fef95ed742be144d679a
new head: b0a56fc5db6c5597e1f7ed7cae1fa2386d6f43c0
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=b0a56fc5db6c+%5E78a5e0daeeec

----------------------------------------------------------------------------

4ac21cd37da3: Issue 11111 - Division by zero in TabDecorator
  
  Signed-off-by: John Scipione <jscipione@xxxxxxxxx>

                               [ Sambuddha Basu <sambuddhabasu1@xxxxxxxxx> ]

b0a56fc5db6c: _DistributeTabSize cleanup
  
  * use ceilf() over ceil() and floorf() over floor()
  * rename prevTab to previousTab
  * check that tab pointer is valid in each loop
  * use tabCount variable in each loop to check the end condition

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

----------------------------------------------------------------------------

1 file changed, 22 insertions(+), 12 deletions(-)
src/servers/app/decorator/TabDecorator.cpp | 34 +++++++++++++++++---------

############################################################################

Commit:      4ac21cd37da3c8ff3ca049312213c090efc154cb
URL:         http://cgit.haiku-os.org/haiku/commit/?id=4ac21cd37da3
Author:      Sambuddha Basu <sambuddhabasu1@xxxxxxxxx>
Date:        Thu Jan 29 17:24:42 2015 UTC
Committer:   John Scipione <jscipione@xxxxxxxxx>
Commit-Date: Thu Jan 29 21:15:33 2015 UTC

Issue 11111 - Division by zero in TabDecorator

Signed-off-by: John Scipione <jscipione@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/servers/app/decorator/TabDecorator.cpp 
b/src/servers/app/decorator/TabDecorator.cpp
index 0d295a0..6852ea6 100644
--- a/src/servers/app/decorator/TabDecorator.cpp
+++ b/src/servers/app/decorator/TabDecorator.cpp
@@ -406,13 +406,17 @@ TabDecorator::_DoTabLayout()
 void
 TabDecorator::_DistributeTabSize(float delta)
 {
-       ASSERT(CountTabs() > 1);
+       int32 tabCount = fTabList.CountItems();
+       ASSERT(tabCount > 1);
 
        float maxTabSize = 0;
        float secMaxTabSize = 0;
        int32 nTabsWithMaxSize = 0;
-       for (int32 i = 0; i < fTabList.CountItems(); i++) {
+       for (int32 i = 0; i < tabCount; i++) {
                Decorator::Tab* tab = fTabList.ItemAt(i);
+               if (tab == NULL)
+                       continue;
+
                float tabWidth = tab->tabRect.Width();
                if (int_equal(maxTabSize, tabWidth)) {
                        nTabsWithMaxSize++;

############################################################################

Revision:    hrev48748
Commit:      b0a56fc5db6c5597e1f7ed7cae1fa2386d6f43c0
URL:         http://cgit.haiku-os.org/haiku/commit/?id=b0a56fc5db6c
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Thu Jan 29 21:23:27 2015 UTC

_DistributeTabSize cleanup

* use ceilf() over ceil() and floorf() over floor()
* rename prevTab to previousTab
* check that tab pointer is valid in each loop
* use tabCount variable in each loop to check the end condition

----------------------------------------------------------------------------

diff --git a/src/servers/app/decorator/TabDecorator.cpp 
b/src/servers/app/decorator/TabDecorator.cpp
index 6852ea6..4435206 100644
--- a/src/servers/app/decorator/TabDecorator.cpp
+++ b/src/servers/app/decorator/TabDecorator.cpp
@@ -430,22 +430,25 @@ TabDecorator::_DistributeTabSize(float delta)
                        secMaxTabSize = tabWidth;
        }
 
-       float minus = ceil(std::min(maxTabSize - secMaxTabSize, delta));
+       float minus = ceilf(std::min(maxTabSize - secMaxTabSize, delta));
        delta -= minus;
        minus /= nTabsWithMaxSize;
 
-       Decorator::Tab* prevTab = NULL;
-       for (int32 i = 0; i < fTabList.CountItems(); i++) {
+       Decorator::Tab* previousTab = NULL;
+       for (int32 i = 0; i < tabCount; i++) {
                Decorator::Tab* tab = fTabList.ItemAt(i);
+               if (tab == NULL)
+                       continue;
+
                if (int_equal(maxTabSize, tab->tabRect.Width()))
                        tab->tabRect.right -= minus;
 
-               if (prevTab) {
-                       tab->tabRect.OffsetBy(prevTab->tabRect.right - 
tab->tabRect.left,
-                               0);
+               if (previousTab != NULL) {
+                       float offsetX = previousTab->tabRect.right - 
tab->tabRect.left;
+                       tab->tabRect.OffsetBy(offsetX, 0);
                }
 
-               prevTab = tab;
+               previousTab = tab;
        }
 
        if (delta > 0) {
@@ -454,10 +457,13 @@ TabDecorator::_DistributeTabSize(float delta)
        }
 
        // done
-       prevTab->tabRect.right = floor(fFrame.right + fBorderWidth);
+       previousTab->tabRect.right = floorf(fFrame.right + fBorderWidth);
+
+       for (int32 i = 0; i < tabCount; i++) {
+               Decorator::Tab* tab = fTabList.ItemAt(i);
+               if (tab == NULL)
+                       continue;
 
-       for (int32 i = 0; i < fTabList.CountItems(); i++) {
-               Decorator::Tab* tab = _TabAt(i);
                tab->tabOffset = uint32(tab->tabRect.left - fLeftBorder.left);
        }
 }


Other related posts: