Make sure there is only one empty string

This commit is contained in:
Michal Moskal 2016-08-30 15:30:01 +02:00
parent 7c020d14bc
commit 1942b2840b

View file

@ -210,6 +210,11 @@ ManagedString::ManagedString(const ManagedString &s1, const ManagedString &s2)
*/
ManagedString::ManagedString(PacketBuffer buffer)
{
if (buffer.length() == 0) {
initEmpty();
return;
}
// Allocate a new buffer ( just in case the data is not NULL terminated).
ptr = (StringData*) malloc(4+buffer.length()+1);
ptr->init();
@ -238,7 +243,7 @@ ManagedString::ManagedString(PacketBuffer buffer)
ManagedString::ManagedString(const char *str, const int16_t length)
{
// Sanity check. Return EmptyString for anything distasteful
if (str == NULL || *str == 0 || (uint16_t)length > strlen(str)) // XXX length should be unsigned on the interface
if (str == NULL || *str == 0 || length == 0 || (uint16_t)length > strlen(str)) // XXX length should be unsigned on the interface
{
initEmpty();
return;