From: Marco van Wieringen Date: Wed, 18 Jan 2012 19:04:53 +0000 (+0100) Subject: Fix MediaView::getSelection X-Git-Tag: Release-7.0.0~320 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b98a5070cea39199ebf46cee9bd0a2787e2c843d;p=bacula%2Fbacula Fix MediaView::getSelection The selection in MediaView::getSelection doesn't work ok as the internal table is sized using the number of selected items and not the number of rows in the total table. But the table is indexed using a row number which can be any rownr of the total of the table. Things seen is that 3 rows are selected but the selection only returns 2. This is probably a side effect because the code could also just have crashed as nb = 16 and rownr = 29-31 e.g. addressed outside the bounds of the array. Changed the internal array to use bools instead of ints so its also somewhat smaller. --- diff --git a/bacula/src/qt-console/medialist/mediaview.cpp b/bacula/src/qt-console/medialist/mediaview.cpp index e872876d80..6f8f28240d 100644 --- a/bacula/src/qt-console/medialist/mediaview.cpp +++ b/bacula/src/qt-console/medialist/mediaview.cpp @@ -115,25 +115,37 @@ void MediaView::purgePushed() bool MediaView::getSelection(QStringList &list) { - QList items = m_tableMedia->selectedItems(); + int i, nb, nr_rows, row; + bool *tab; QTableWidgetItem *it; - int row; - int *tab; - int nb = items.count(); + QList items = m_tableMedia->selectedItems(); + + /* + * See if anything is selected. + */ + nb = items.count(); if (!nb) { return false; } - tab = (int *) malloc (nb * sizeof(int)); - memset(tab, 0, sizeof(int)*nb); - for (int i = 0; i < nb; ++i) { + + /* + * Create a nibble map for each row so we can see if its + * selected or not. + */ + nr_rows = m_tableMedia->rowCount(); + tab = (bool *)malloc (nr_rows * sizeof(bool)); + memset(tab, 0, sizeof(bool) * nr_rows); + + for (i = 0; i < nb; ++i) { row = items[i]->row(); if (!tab[row]) { - tab[row]=1; + tab[row] = true; it = m_tableMedia->item(row, 0); list.append(it->text()); } } free(tab); + return list.count() > 0; }