fixed uninitialized memory read in FileDetail struct causing weird dates in search dialog

This commit is contained in:
csoler 2023-06-03 23:51:31 +02:00
parent ad9d566767
commit 3f8e8805a2
2 changed files with 11 additions and 8 deletions

View file

@ -265,6 +265,8 @@ void SearchDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
f.hash = fe->mResults[i].fHash; f.hash = fe->mResults[i].fHash;
f.name = fe->mResults[i].fName; f.name = fe->mResults[i].fName;
f.size = fe->mResults[i].fSize; 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); 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->setText(SR_SIZE_COL, QString::number(file.size));
item->setData(SR_SIZE_COL, ROLE_SORT, (qulonglong) file.size); item->setData(SR_SIZE_COL, ROLE_SORT, (qulonglong) file.size);
item->setText(SR_AGE_COL, QString::number(file.age)); item->setText(SR_AGE_COL, QString::number(file.mtime));
item->setData(SR_AGE_COL, ROLE_SORT, file.age); item->setData(SR_AGE_COL, ROLE_SORT, file.mtime);
item->setTextAlignment( SR_SIZE_COL, Qt::AlignRight ); item->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
int friendSource = 0; int friendSource = 0;
int anonymousSource = 0; int anonymousSource = 0;
@ -1396,21 +1398,21 @@ void SearchDialog::resultsToTree(const QString& txt,qulonglong searchId, const s
std::list<DirDetails>::const_iterator it; std::list<DirDetails>::const_iterator it;
for(it = results.begin(); it != results.end(); ++it) for(it = results.begin(); it != results.end(); ++it)
if (it->type == DIR_TYPE_FILE) { if (it->type == DIR_TYPE_FILE)
{
FileDetail fd; FileDetail fd;
fd.id = it->id; fd.id = it->id;
fd.name = it->name; fd.name = it->name;
fd.hash = it->hash; fd.hash = it->hash;
fd.path = it->path; fd.path = it->path;
fd.size = it->size; fd.size = it->size;
fd.age = it->mtime; fd.mtime= it->mtime;
fd.rank = 0; fd.rank = 0;
insertFile(searchId,fd, FRIEND_SEARCH); insertFile(searchId,fd, FRIEND_SEARCH);
} else if (it->type == DIR_TYPE_DIR) {
// insertDirectory(txt, searchId, *it, NULL);
insertDirectory(txt, searchId, *it);
} }
else if (it->type == DIR_TYPE_DIR)
insertDirectory(txt, searchId, *it);
ui.searchResultWidget->setSortingEnabled(true); ui.searchResultWidget->setSortingEnabled(true);
} }

View file

@ -91,6 +91,7 @@ class RSHumanReadableAgeDelegate: public RSHumanReadableDelegate
QStyleOptionViewItem opt(option) ; QStyleOptionViewItem opt(option) ;
setPainterOptions(painter,opt,index) ; setPainterOptions(painter,opt,index) ;
if(index.data().toLongLong() > 0) // no date is present.
painter->drawText(opt.rect, Qt::AlignCenter, misc::timeRelativeToNow(index.data().toLongLong())) ; painter->drawText(opt.rect, Qt::AlignCenter, misc::timeRelativeToNow(index.data().toLongLong())) ;
} }
}; };