Time preferences: use std::nothrow variant of new operator

Also make sure to avoid an eventual negative array size. CID 10934.
This commit is contained in:
Philippe Saint-Pierre
2012-01-02 13:54:39 -05:00
parent 9668d19918
commit e9132cc34c
+9 -8
View File
@@ -167,23 +167,24 @@ Settings::SettingsChanged()
ssize_t oldSize = fOldMessage.FlattenedSize();
ssize_t newSize = fMessage.FlattenedSize();
if (oldSize != newSize)
if (oldSize != newSize || oldSize < 0 || newSize < 0)
return true;
char* oldBytes = new char[oldSize];
char* oldBytes = new (std::nothrow) char[oldSize];
if (oldBytes == NULL)
return true;
fOldMessage.Flatten(oldBytes, oldSize);
char* newBytes = new char[newSize];
char* newBytes = new (std::nothrow) char[newSize];
if (newBytes == NULL)
return true;
fMessage.Flatten(newBytes, newSize);
int result = memcmp(oldBytes, newBytes, oldSize);
int result = memcmp(oldBytes, newBytes, oldSize);
delete[] oldBytes;
delete[] newBytes;
if (result != 0)
return true;
else
return false;
return result != 0;
}