mirror of
https://github.com/yuzu-emu/breakpad.git
synced 2024-11-24 09:15:43 +01:00
NULL-check the entry in NonAllocatingMap before setting on it.
Using just an assert will still cause a crash in a release build. BUG=http://code.google.com/p/chromium/issues/detail?id=238757 R=mark@chromium.org Review URL: https://breakpad.appspot.com/593003 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1174 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
parent
b45b97b2fd
commit
df6f45b04b
@ -156,7 +156,8 @@ class NonAllocatingMap {
|
|||||||
|
|
||||||
// Stores |value| into |key|, replacing the existing value if |key| is
|
// Stores |value| into |key|, replacing the existing value if |key| is
|
||||||
// already present. |key| must not be NULL. If |value| is NULL, the key is
|
// already present. |key| must not be NULL. If |value| is NULL, the key is
|
||||||
// removed from the map.
|
// removed from the map. If there is no more space in the map, then the
|
||||||
|
// operation silently fails.
|
||||||
void SetKeyValue(const char* key, const char* value) {
|
void SetKeyValue(const char* key, const char* value) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
RemoveKey(key);
|
RemoveKey(key);
|
||||||
@ -191,7 +192,8 @@ class NonAllocatingMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the map is out of space, entry will be NULL.
|
// If the map is out of space, entry will be NULL.
|
||||||
assert(entry);
|
if (!entry)
|
||||||
|
return;
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// Sanity check that the key only appears once.
|
// Sanity check that the key only appears once.
|
||||||
|
@ -278,15 +278,18 @@ TEST(NonAllocatingMapTest, Serialize) {
|
|||||||
EXPECT_STREQ("hig", deserialized.GetValueForKey("tre"));
|
EXPECT_STREQ("hig", deserialized.GetValueForKey("tre"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
// Running out of space shouldn't crash.
|
||||||
|
|
||||||
TEST(NonAllocatingMapTest, OutOfSpace) {
|
TEST(NonAllocatingMapTest, OutOfSpace) {
|
||||||
NonAllocatingMap<3, 2, 2> map;
|
NonAllocatingMap<3, 2, 2> map;
|
||||||
map.SetKeyValue("a", "1");
|
map.SetKeyValue("a", "1");
|
||||||
map.SetKeyValue("b", "2");
|
map.SetKeyValue("b", "2");
|
||||||
ASSERT_DEATH(map.SetKeyValue("c", "3"), "");
|
map.SetKeyValue("c", "3");
|
||||||
|
EXPECT_EQ(2u, map.GetCount());
|
||||||
|
EXPECT_FALSE(map.GetValueForKey("c"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
|
||||||
TEST(NonAllocatingMapTest, KeyTooLong) {
|
TEST(NonAllocatingMapTest, KeyTooLong) {
|
||||||
NonAllocatingMap<3, 10, 12> map;
|
NonAllocatingMap<3, 10, 12> map;
|
||||||
map.SetKeyValue("ab", "cdefghi");
|
map.SetKeyValue("ab", "cdefghi");
|
||||||
|
Loading…
Reference in New Issue
Block a user