From 3f8e8805a223a77a7337cf6ed2f526f3c820355d Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 3 Jun 2023 23:51:31 +0200 Subject: [PATCH] fixed uninitialized memory read in FileDetail struct causing weird dates in search dialog --- .../src/gui/FileTransfer/SearchDialog.cpp | 16 +++++++++------- retroshare-gui/src/gui/RSHumanReadableDelegate.h | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp index 2ecf442e4..7c495dd5b 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp @@ -265,6 +265,8 @@ void SearchDialog::handleEvent_main_thread(std::shared_ptr event) f.hash = fe->mResults[i].fHash; f.name = fe->mResults[i].fName; f.size = fe->mResults[i].fSize; + f.mtime = 0; // zero what's not available, otherwise we'll get some random values displayed. + f.rank = 0; updateFiles(fe->mRequestId,f); } @@ -1320,8 +1322,8 @@ void SearchDialog::insertFile(qulonglong searchId, const FileDetail& file, int s item->setText(SR_SIZE_COL, QString::number(file.size)); item->setData(SR_SIZE_COL, ROLE_SORT, (qulonglong) file.size); - item->setText(SR_AGE_COL, QString::number(file.age)); - item->setData(SR_AGE_COL, ROLE_SORT, file.age); + item->setText(SR_AGE_COL, QString::number(file.mtime)); + item->setData(SR_AGE_COL, ROLE_SORT, file.mtime); item->setTextAlignment( SR_SIZE_COL, Qt::AlignRight ); int friendSource = 0; int anonymousSource = 0; @@ -1396,21 +1398,21 @@ void SearchDialog::resultsToTree(const QString& txt,qulonglong searchId, const s std::list::const_iterator it; for(it = results.begin(); it != results.end(); ++it) - if (it->type == DIR_TYPE_FILE) { + if (it->type == DIR_TYPE_FILE) + { FileDetail fd; fd.id = it->id; fd.name = it->name; fd.hash = it->hash; fd.path = it->path; fd.size = it->size; - fd.age = it->mtime; + fd.mtime= it->mtime; fd.rank = 0; insertFile(searchId,fd, FRIEND_SEARCH); - } else if (it->type == DIR_TYPE_DIR) { -// insertDirectory(txt, searchId, *it, NULL); + } + else if (it->type == DIR_TYPE_DIR) insertDirectory(txt, searchId, *it); - } ui.searchResultWidget->setSortingEnabled(true); } diff --git a/retroshare-gui/src/gui/RSHumanReadableDelegate.h b/retroshare-gui/src/gui/RSHumanReadableDelegate.h index 3e9a3e412..18943c1dc 100644 --- a/retroshare-gui/src/gui/RSHumanReadableDelegate.h +++ b/retroshare-gui/src/gui/RSHumanReadableDelegate.h @@ -91,7 +91,8 @@ class RSHumanReadableAgeDelegate: public RSHumanReadableDelegate QStyleOptionViewItem opt(option) ; setPainterOptions(painter,opt,index) ; - painter->drawText(opt.rect, Qt::AlignCenter, misc::timeRelativeToNow(index.data().toLongLong())) ; + if(index.data().toLongLong() > 0) // no date is present. + painter->drawText(opt.rect, Qt::AlignCenter, misc::timeRelativeToNow(index.data().toLongLong())) ; } };