undf: assign 935-937; cataclysm-dda 3 CWE-407 defects
cataclysm-0001: overmap_ui search dedup vector O(P*M), 79x cataclysm-0002: dependency_tree dedup vector O(N^2), 2x cataclysm-0003: surroundings_menu item/terfurn dedup O(N^2), 9x
This commit is contained in:
parent
3c1ab5459c
commit
8ea8ad434f
7 changed files with 448 additions and 1 deletions
45
defects/cataclysm-0003/patch/cataclysm-0003.patch
Normal file
45
defects/cataclysm-0003/patch/cataclysm-0003.patch
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# UNDF: UNDF-2026-000000937
|
||||
--- a/src/surroundings_menu.cpp
|
||||
+++ b/src/surroundings_menu.cpp
|
||||
@@ -1,5 +1,6 @@
|
||||
// ... (includes)
|
||||
#include <algorithm>
|
||||
+#include <unordered_set>
|
||||
|
||||
// In item_tab_data::add_item_recursive()
|
||||
// BEFORE (CWE-407): item_order is std::vector<std::string> with std::find
|
||||
@@ -241,7 +242,8 @@
|
||||
void item_tab_data::add_item_recursive( std::vector<std::string> &item_order, const item *it,
|
||||
const tripoint_rel_ms &relative_pos )
|
||||
{
|
||||
+ // Also pass item_order_set for O(1) membership check
|
||||
const std::string name = it->tname();
|
||||
|
||||
- if( std::find( item_order.begin(), item_order.end(), name ) == item_order.end() ) {
|
||||
+ if( item_order_set.find( name ) == item_order_set.end() ) {
|
||||
item_order.push_back( name );
|
||||
+ item_order_set.insert( name );
|
||||
|
||||
items[name] = map_entity_stack<item>( it, relative_pos, it->count() );
|
||||
} else {
|
||||
@@ -259,6 +261,7 @@
|
||||
void item_tab_data::find_nearby_items( const Character &you, map &m )
|
||||
{
|
||||
std::vector<std::string> item_order;
|
||||
+ // Add std::unordered_set<std::string> item_order_set as class member
|
||||
|
||||
// Similarly in terfurn_tab_data::add_terfurn()
|
||||
// BEFORE:
|
||||
@@ -585,7 +588,8 @@
|
||||
void terfurn_tab_data::add_terfurn( std::vector<std::string> &item_order,
|
||||
const map_data_common_t *terfurn, const tripoint_rel_ms &relative_pos )
|
||||
{
|
||||
const std::string name = terfurn->name();
|
||||
|
||||
- if( std::find( item_order.begin(), item_order.end(), name ) == item_order.end() ) {
|
||||
+ if( item_order_set.find( name ) == item_order_set.end() ) {
|
||||
item_order.push_back( name );
|
||||
+ item_order_set.insert( name );
|
||||
|
||||
terfurns[name] = map_entity_stack<map_data_common_t>( terfurn, relative_pos );
|
||||
} else {
|
||||
Loading…
Add table
Add a link
Reference in a new issue