From dfe6ac1a8fb6b2e2b1913ca0deabe5867fa808d6 Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Wed, 18 Jan 2012 20:04:53 +0100 Subject: [PATCH] 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. --- bacula/src/qt-console/medialist/mediaview.cpp | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) 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; } -- 2.39.5