diff --git a/layout/tables/FixedTableLayoutStrategy.cpp b/layout/tables/FixedTableLayoutStrategy.cpp index 19f800b03529..59a44fe4db90 100644 --- a/layout/tables/FixedTableLayoutStrategy.cpp +++ b/layout/tables/FixedTableLayoutStrategy.cpp @@ -168,6 +168,18 @@ FixedTableLayoutStrategy::MarkIntrinsicWidthsDirty() mLastCalcWidth = nscoord_MIN; } +static inline nscoord +AllocateUnassigned(nscoord aUnassignedSpace, float aShare) +{ + if (aShare == 1.0f) { + // This happens when the numbers we're dividing to get aShare + // are equal. We want to return unassignedSpace exactly, even + // if it can't be precisely round-tripped through float. + return aUnassignedSpace; + } + return NSToCoordRound(float(aUnassignedSpace) * aShare); +} + /* virtual */ void FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowState) { @@ -357,8 +369,8 @@ FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowSt if (colFrame->GetPrefPercent() == 0.0f) { NS_ASSERTION(colFrame->GetFinalWidth() <= specUndist, "widths don't add up"); - nscoord toAdd = NSToCoordRound(float(unassignedSpace) * - (float(colFrame->GetFinalWidth()) / float(specUndist))); + nscoord toAdd = AllocateUnassigned(unassignedSpace, + float(colFrame->GetFinalWidth()) / float(specUndist)); specUndist -= colFrame->GetFinalWidth(); colFrame->SetFinalWidth(colFrame->GetFinalWidth() + toAdd); unassignedSpace -= toAdd; @@ -386,8 +398,8 @@ FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowSt "widths don't add up"); pctUndist = colFrame->GetPrefPercent(); } - nscoord toAdd = NSToCoordRound(float(unassignedSpace) * - (colFrame->GetPrefPercent() / pctUndist)); + nscoord toAdd = AllocateUnassigned(unassignedSpace, + colFrame->GetPrefPercent() / pctUndist); colFrame->SetFinalWidth(colFrame->GetFinalWidth() + toAdd); unassignedSpace -= toAdd; pctUndist -= colFrame->GetPrefPercent(); @@ -406,12 +418,13 @@ FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowSt continue; } NS_ASSERTION(colFrame->GetFinalWidth() == 0, "yikes"); - nscoord toAdd = NSToCoordRound(float(unassignedSpace) / - float(colsLeft)); + nscoord toAdd = AllocateUnassigned(unassignedSpace, + 1.0f / float(colsLeft)); colFrame->SetFinalWidth(toAdd); unassignedSpace -= toAdd; --colsLeft; } + NS_ASSERTION(unassignedSpace == 0, "failed to redistribute"); } } for (PRInt32 col = 0; col < colCount; ++col) { diff --git a/layout/tables/crashtests/467141-1.html b/layout/tables/crashtests/467141-1.html new file mode 100644 index 000000000000..5a6d3df5ac0f --- /dev/null +++ b/layout/tables/crashtests/467141-1.html @@ -0,0 +1,8 @@ + + + + + +
+ + diff --git a/layout/tables/crashtests/crashtests.list b/layout/tables/crashtests/crashtests.list index d561115af8de..b980ef7f4378 100644 --- a/layout/tables/crashtests/crashtests.list +++ b/layout/tables/crashtests/crashtests.list @@ -56,3 +56,4 @@ load 416845-3.html load 423514-1.xhtml load 456041.html load 457115.html +load 467141-1.html