Switch table indexing to unsigned
https://bugs.webkit.org/show_bug.cgi?id=72083

Reviewed by Darin Adler.

No expected change in behavior.

All of the code is now using unsigned for indexing!

* rendering/FixedTableLayout.cpp:
(WebCore::FixedTableLayout::layout):
* rendering/RenderTable.cpp:
(WebCore::RenderTable::colElement):
(WebCore::RenderTable::cellAbove):
* rendering/RenderTableSection.cpp:
(WebCore::RenderTableSection::splitColumn):
Added some ASSERTs to make sure we don't underflow. Looking at how
the different variables are populated, they should not be reached.

* rendering/RenderTableCell.cpp:
(WebCore::RenderTableCell::colSpan):
(WebCore::RenderTableCell::rowSpan):
Those 2 functions promotes HTMLTableCellElement's int to unsigned
which should be fine as we make sure their are positive. Also HTML5
makes those 2 fields "unsigned long" which goes in the same direction.

* rendering/AutoTableLayout.cpp:
(WebCore::AutoTableLayout::layout):
* rendering/RenderTableSection.cpp:
(WebCore::RenderTableSection::nodeAtPoint):
Rewrote a couple of reverse iterating to be able to use unsigned
without overflowing.

* rendering/AutoTableLayout.cpp:
(WebCore::AutoTableLayout::recalcColumn):
(WebCore::AutoTableLayout::fullRecalc):
(WebCore::AutoTableLayout::calcEffectiveLogicalWidth):
(WebCore::AutoTableLayout::insertSpanCell):
* rendering/AutoTableLayout.h:
* rendering/FixedTableLayout.cpp:
(WebCore::FixedTableLayout::calcWidthArray):
* rendering/RenderTable.cpp:
(WebCore::RenderTable::splitColumn):
(WebCore::RenderTable::appendColumn):
(WebCore::RenderTable::recalcSections):
* rendering/RenderTable.h:
(WebCore::RenderTable::getColumnPos):
(WebCore::RenderTable::spanOfEffCol):
(WebCore::RenderTable::effColToCol):
* rendering/RenderTableCell.cpp:
(WebCore::RenderTableCell::styleOrColLogicalWidth):
(WebCore::CollapsedBorders::nextBorder):
* rendering/RenderTableCell.h:
* rendering/RenderTableCol.cpp:
(WebCore::RenderTableCol::updateFromElement):
* rendering/RenderTableCol.h:
(WebCore::RenderTableCol::span):
(WebCore::RenderTableCol::setSpan):
* rendering/RenderTableSection.cpp:
(WebCore::RenderTableSection::addCell):
(WebCore::RenderTableSection::setCellLogicalWidths):
(WebCore::RenderTableSection::layoutRows):
(WebCore::RenderTableSection::calcOuterBorderBefore):
(WebCore::RenderTableSection::calcOuterBorderAfter):
(WebCore::RenderTableSection::calcOuterBorderStart):
(WebCore::RenderTableSection::calcOuterBorderEnd):
(WebCore::RenderTableSection::paintObject):
(WebCore::RenderTableSection::appendColumn):
* rendering/RenderTableSection.h:
(WebCore::RenderTableSection::cellAt):
(WebCore::RenderTableSection::primaryCellAt):
(WebCore::RenderTableSection::getBaseline):
Mechanical change int -> unsigned.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@100386 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/rendering/RenderTableSection.cpp b/Source/WebCore/rendering/RenderTableSection.cpp
index 10e9647..dbf518e 100644
--- a/Source/WebCore/rendering/RenderTableSection.cpp
+++ b/Source/WebCore/rendering/RenderTableSection.cpp
@@ -193,8 +193,8 @@
     if (needsCellRecalc())
         return;
 
-    int rSpan = cell->rowSpan();
-    int cSpan = cell->colSpan();
+    unsigned rSpan = cell->rowSpan();
+    unsigned cSpan = cell->colSpan();
     Vector<RenderTable::ColumnStruct>& columns = table()->columns();
     unsigned nCols = columns.size();
     // addCell should be called only after m_cRow has been incremented.
@@ -241,16 +241,16 @@
     // tell the cell where it is
     bool inColSpan = false;
     while (cSpan) {
-        int currentSpan;
+        unsigned currentSpan;
         if (m_cCol >= nCols) {
             table()->appendColumn(cSpan);
             currentSpan = cSpan;
         } else {
-            if (cSpan < (int)columns[m_cCol].span)
+            if (cSpan < columns[m_cCol].span)
                 table()->splitColumn(m_cCol, cSpan);
             currentSpan = columns[m_cCol].span;
         }
-        for (int r = 0; r < rSpan; r++) {
+        for (unsigned r = 0; r < rSpan; r++) {
             CellStruct& c = cellAt(insertionRow + r, m_cCol);
             ASSERT(cell);
             c.cells.append(cell);
@@ -283,7 +283,7 @@
             if (!cell || current.inColSpan)
               continue;
             unsigned endCol = j;
-            int cspan = cell->colSpan();
+            unsigned cspan = cell->colSpan();
             while (cspan && endCol < cols) {
                 ASSERT(endCol < table()->columns().size());
                 cspan -= table()->columns()[endCol].span;
@@ -438,7 +438,7 @@
     ASSERT(!needsLayout());
 
     LayoutUnit rHeight;
-    int rindx;
+    unsigned rindx;
     unsigned totalRows = m_grid.size();
 
     // Set the width of our section now.  The rows will also be this width.
@@ -509,7 +509,7 @@
 
     LayoutUnit hspacing = table()->hBorderSpacing();
     LayoutUnit vspacing = table()->vBorderSpacing();
-    LayoutUnit nEffCols = table()->numEffCols();
+    unsigned nEffCols = table()->numEffCols();
 
     LayoutStateMaintainer statePusher(view(), this, LayoutSize(x(), y()), style()->isFlippedBlocksWritingMode());
 
@@ -522,7 +522,7 @@
             rowRenderer->updateLayerTransform();
         }
 
-        for (int c = 0; c < nEffCols; c++) {
+        for (unsigned c = 0; c < nEffCols; c++) {
             CellStruct& cs = cellAt(r, c);
             RenderTableCell* cell = cs.primaryCell();
 
@@ -679,7 +679,7 @@
 #endif
     // Now that our height has been determined, add in overflow from cells.
     for (unsigned r = 0; r < totalRows; r++) {
-        for (int c = 0; c < nEffCols; c++) {
+        for (unsigned c = 0; c < nEffCols; c++) {
             CellStruct& cs = cellAt(r, c);
             RenderTableCell* cell = cs.primaryCell();
             if (!cell || cs.inColSpan)
@@ -710,7 +710,7 @@
 
 LayoutUnit RenderTableSection::calcOuterBorderBefore() const
 {
-    int totalCols = table()->numEffCols();
+    unsigned totalCols = table()->numEffCols();
     if (!m_grid.size() || !totalCols)
         return 0;
 
@@ -729,7 +729,7 @@
         borderWidth = rb.width();
 
     bool allHidden = true;
-    for (int c = 0; c < totalCols; c++) {
+    for (unsigned c = 0; c < totalCols; c++) {
         const CellStruct& current = cellAt(0, c);
         if (current.inColSpan || !current.hasCells())
             continue;
@@ -761,7 +761,7 @@
 
 LayoutUnit RenderTableSection::calcOuterBorderAfter() const
 {
-    int totalCols = table()->numEffCols();
+    unsigned totalCols = table()->numEffCols();
     if (!m_grid.size() || !totalCols)
         return 0;
 
@@ -780,7 +780,7 @@
         borderWidth = rb.width();
 
     bool allHidden = true;
-    for (int c = 0; c < totalCols; c++) {
+    for (unsigned c = 0; c < totalCols; c++) {
         const CellStruct& current = cellAt(m_grid.size() - 1, c);
         if (current.inColSpan || !current.hasCells())
             continue;
@@ -812,7 +812,7 @@
 
 LayoutUnit RenderTableSection::calcOuterBorderStart() const
 {
-    int totalCols = table()->numEffCols();
+    unsigned totalCols = table()->numEffCols();
     if (!m_grid.size() || !totalCols)
         return 0;
 
@@ -856,7 +856,7 @@
 
 LayoutUnit RenderTableSection::calcOuterBorderEnd() const
 {
-    int totalCols = table()->numEffCols();
+    unsigned totalCols = table()->numEffCols();
     if (!m_grid.size() || !totalCols)
         return 0;
 
@@ -1106,9 +1106,7 @@
             else
                 std::sort(cells.begin(), cells.end(), compareCellPositionsWithOverflowingCells);
 
-            int size = cells.size();
-            // Paint the cells.
-            for (int i = 0; i < size; ++i)
+            for (unsigned i = 0; i < cells.size(); ++i)
                 paintCell(cells[i], paintInfo, paintOffset);
         }
     }
@@ -1184,7 +1182,7 @@
     return result + 1;
 }
 
-void RenderTableSection::appendColumn(int pos)
+void RenderTableSection::appendColumn(unsigned pos)
 {
     ASSERT(!m_needsCellRecalc);
 
@@ -1192,7 +1190,7 @@
         m_grid[row].row.resize(pos + 1);
 }
 
-void RenderTableSection::splitColumn(unsigned pos, int first)
+void RenderTableSection::splitColumn(unsigned pos, unsigned first)
 {
     ASSERT(!m_needsCellRecalc);
 
@@ -1205,7 +1203,8 @@
             r[pos + 1].cells.append(r[pos].cells);
             RenderTableCell* cell = r[pos].primaryCell();
             ASSERT(cell);
-            int colleft = cell->colSpan() - r[pos].inColSpan;
+            ASSERT(cell->colSpan() >= (r[pos].inColSpan ? 1 : 0));
+            unsigned colleft = cell->colSpan() - r[pos].inColSpan;
             if (first > colleft)
               r[pos + 1].inColSpan = 0;
             else
@@ -1279,7 +1278,8 @@
     if (!current.hasCells())
         return false;
 
-    for (int i = current.cells.size() - 1; i >= 0; --i) {
+    for (unsigned i = current.cells.size() ; i; ) {
+        --i;
         RenderTableCell* cell = current.cells[i];
         LayoutPoint cellPoint = flipForWritingModeForChild(cell, adjustedLocation);
         if (static_cast<RenderObject*>(cell)->nodeAtPoint(request, result, pointInContainer, cellPoint, action)) {