37 lines
1.8 KiB
Diff
37 lines
1.8 KiB
Diff
# UNDF: UNDF-2026-000000838
|
|
# UNDF: (leave blank)
|
|
# Defect: kdenlive-0008
|
|
# Component: src/assets/view/widgets/urllistparamwidget.cpp
|
|
# Pattern: CWE-407 — std::find iterating QMap values in loop over directory entries
|
|
# Severity: MEDIUM — O(E*M) where E=directory entries, M=existing map values
|
|
# Fix: Build QSet<QString> of existing values before the loop for O(1) lookup
|
|
--- a/src/assets/view/widgets/urllistparamwidget.cpp
|
|
+++ b/src/assets/view/widgets/urllistparamwidget.cpp
|
|
@@ addItemsInSameFolder
|
|
void UrlListParamWidget::addItemsInSameFolder(const QString currentValue, QMap<QString, QString> *listValues)
|
|
{
|
|
QDir dir = QFileInfo(currentValue).absoluteDir();
|
|
if (dir.exists()) {
|
|
+ // Build a set of existing values for O(1) membership tests
|
|
+ QSet<QString> existingValues;
|
|
+ for (auto it = listValues->cbegin(); it != listValues->cend(); ++it) {
|
|
+ existingValues.insert(it.value());
|
|
+ }
|
|
QStringList entries = dir.entryList(m_fileExt, QDir::Files);
|
|
for (const auto &filename : std::as_const(entries)) {
|
|
const QString path = dir.absoluteFilePath(filename);
|
|
- if (std::find((*listValues).cbegin(), (*listValues).cend(), path) == (*listValues).cend()) {
|
|
+ if (!existingValues.contains(path)) {
|
|
(*listValues).insert(QFileInfo(filename).baseName(), path);
|
|
+ existingValues.insert(path);
|
|
}
|
|
}
|
|
// make sure the current value is added. If it is a duplicate we remove it later
|
|
- if (std::find((*listValues).cbegin(), (*listValues).cend(), currentValue) == (*listValues).cend()) {
|
|
+ if (!existingValues.contains(currentValue)) {
|
|
if (QFileInfo::exists(currentValue)) {
|
|
(*listValues).insert(QFileInfo(currentValue).baseName(), currentValue);
|
|
}
|
|
}
|
|
}
|
|
}
|