aboutsummaryrefslogtreecommitdiffhomepage
path: root/env.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-06-16 13:05:58 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-06-16 13:05:58 -0700
commitafd8d2f9bae14cb3c263987a01aedb748b975176 (patch)
tree5f9172370b54ce4f79d9fdc7b441033d8f3b1c17 /env.cpp
parent1d54bff385240d9f7fd1d3ad6df56e74ddd5ef49 (diff)
Don't use std::map::insert when we need to overwrite values
Diffstat (limited to 'env.cpp')
-rw-r--r--env.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/env.cpp b/env.cpp
index dd44b33c..6e6a8d74 100644
--- a/env.cpp
+++ b/env.cpp
@@ -901,8 +901,7 @@ int env_set(const wcstring &key, const wchar_t *val, int var_mode)
}
entry->val = val;
-
- node->env.insert(std::pair<wcstring, var_entry_t*>(key, entry));
+ node->env[key] = entry;
if( entry->exportv )
{
@@ -1397,7 +1396,8 @@ static void get_exported( const env_node_t *n, std::map<wcstring, wcstring> &h )
var_entry_t *val_entry = iter->second;
if( val_entry->exportv && (val_entry->val != ENV_NULL ) )
{
- h.insert(std::pair<wcstring, wcstring>(key, val_entry->val));
+ // Don't use std::map::insert here, since we need to overwrite existing values from previous scopes
+ h[key] = val_entry->val;
}
}
}
@@ -1455,12 +1455,11 @@ static void update_export_array_if_necessary(bool recalc) {
const wcstring &key = uni.at(i);
const wchar_t *val = env_universal_get( key.c_str() );
- std::map<wcstring, wcstring>::iterator result = vals.find( key );
- if( wcscmp( val, ENV_NULL) && ( result == vals.end() ) )
- {
+ if (wcscmp( val, ENV_NULL)) {
+ // Note that std::map::insert does NOT overwrite a value already in the map,
+ // which we depend on here
vals.insert(std::pair<wcstring, wcstring>(key, val));
}
-
}
std::vector<std::string> local_export_buffer;