Project

General

Profile

possible Bug in WTableView::resize(..) in progressive bootstrap mode without javascript

Added by Daniel Walter almost 13 years ago

Hi,

i maybe found a bug in WTableView. I am running the following code in progressive bootstrap mode and i disabled javascript in my browser.

//m_model.rowCount() is for example 2

WTableView* table = new WTableView;
table->setModel(&m_model);
table->clicked().connect(this, &CatView::selected);
table->setAlternatingRowColors(true);
table->setSelectionMode(Wt::SingleSelection);

//crash in progressive bootstrap mode
//m_model.rowCount()*20 = 40

//table->resize(770, 40); //CRASH
table->resize(770, 80); //NO CRASH

table->setDragEnabled(false);
table->setLineHeight(20);
table->setColumnWidth(0, 596);
table->setColumnWidth(1, 160);
table->setColumnAlignment(1, AlignRight);

The crash is an arithmetic exception in WTableView.C on line 1527:

int WTableView::currentPage() const
{
  return renderedFirstRow_ / pageSize();
}

I am using the latest version from git (03019b17a1fde192836ce834f084a03e6178bb44). Is this my fault or a bug in wt?

Regards,

Daniel


Replies (1)

RE: possible Bug in WTableView::resize(..) in progressive bootstrap mode without javascript - Added by Daniel Walter almost 13 years ago

i digged a bit deeper to this and found the real bug in the function

int WTableView::pageSize() const
{
  if (height().isAuto())
    return 10000;
  else {
    const int navigationBarHeight = 25; // set in wt.css

    return static_cast<int>
      ((height().toPixels() - headerHeight().toPixels() - navigationBarHeight)
       / rowHeight().toPixels());
  }
}

the main problem here is the cast to int, so if we take the following calculation

(40 - 20 - 25) / 20 = -0.25

the int cast makes the function return 0 and in the next step we have a division by zero.

i filled a bug report for this http://redmine.emweb.be/issues/811

Regards,

Daniel

    (1-1/1)