Add a sanity check for AdjustPagebreak() implementation

Verify that this function never adjusts page break so far back that it
comes before the previous one (or even at the same position).

This avoids infinite loops in CountPages() even if a custom cell class
implements its overridden AdjustPagebreak() incorrectly.
This commit is contained in:
Vadim Zeitlin
2018-05-24 17:51:40 +02:00
parent 63add2cd19
commit 71948018f4

View File

@@ -151,9 +151,16 @@ int wxHtmlDCRenderer::FindNextPageBreak(const wxArrayInt& known_pagebreaks,
if ( pos != 0 && pos >= GetTotalHeight() )
return wxNOT_FOUND;
pos += m_Height;
m_Cells->AdjustPagebreak(&pos, known_pagebreaks, m_Height);
return pos;
int posNext = pos + m_Height;
if ( m_Cells->AdjustPagebreak(&posNext, known_pagebreaks, m_Height) )
{
// Check that AdjustPagebreak() returns the page break at a strictly
// greater position than that of the previous page, otherwise
// CountPages() would enter into an infinite loop.
wxCHECK_MSG( posNext > pos, wxNOT_FOUND, "Bug in AdjustPagebreak()" );
}
return posNext;
}
void wxHtmlDCRenderer::Render(int x, int y, int from, int to)