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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user