Don't dereference an invalid pointer if string is empty.

llvm-svn: 46781
This commit is contained in:
Anton Korobeynikov 2008-02-05 23:34:40 +00:00
parent 487e527fcf
commit c107b133ba
1 changed files with 4 additions and 4 deletions

View File

@ -273,7 +273,7 @@ public:
return find(Key, Key + strlen(Key));
}
iterator find(const std::string &Key) {
const char* key_start = &Key[0];
const char* key_start = (Key.empty() ? NULL : &Key[0]);
return find(key_start, key_start + Key.size());
}
@ -286,7 +286,7 @@ public:
return find(Key, Key + strlen(Key));
}
const_iterator find(const std::string &Key) const {
const char* key_start = &Key[0];
const char* key_start = (Key.empty() ? NULL : &Key[0]);
return find(key_start, key_start + Key.size());
}
@ -295,7 +295,7 @@ public:
return entry.getValue();
}
ValueTy& operator[](const std::string &Key) {
const char* key_start = &Key[0];
const char* key_start = (Key.empty() ? NULL : &Key[0]);
value_type& entry = GetOrCreateValue(key_start, key_start + Key.size());
return entry.getValue();
}
@ -307,7 +307,7 @@ public:
return count(Key, Key + strlen(Key));
}
size_type count(const std::string &Key) const {
const char* key_start = &Key[0];
const char* key_start = (Key.empty() ? NULL : &Key[0]);
return count(key_start, key_start + Key.size());
}