Commit 8404b44a authored by Sergei Golubchik's avatar Sergei Golubchik

fix new String:realloc* variants always to zero-terminate the string

parent 818af42f
......@@ -81,7 +81,7 @@ bool String::real_alloc(uint32 length)
@retval true An error occured when attempting to allocate memory.
*/
bool String::realloc(uint32 alloc_length)
bool String::realloc_raw(uint32 alloc_length)
{
if (Alloced_length <= alloc_length)
{
......@@ -109,7 +109,6 @@ bool String::realloc(uint32 alloc_length)
Ptr= new_ptr;
Alloced_length= len;
}
Ptr[alloc_length]=0; // This make other funcs shorter
return FALSE;
}
......
......@@ -255,17 +255,30 @@ public:
return real_alloc(arg_length);
}
bool real_alloc(uint32 arg_length); // Empties old string
bool realloc(uint32 arg_length);
bool realloc_raw(uint32 arg_length);
bool realloc(uint32 arg_length)
{
if (realloc_raw(arg_length))
return TRUE;
Ptr[arg_length]=0; // This make other funcs shorter
return FALSE;
}
bool realloc_with_extra(uint32 arg_length)
{
if (extra_alloc < 4096)
extra_alloc= extra_alloc*2+128;
return realloc(arg_length + extra_alloc);
if (realloc_raw(arg_length + extra_alloc))
return TRUE;
Ptr[arg_length]=0; // This make other funcs shorter
return FALSE;
}
bool realloc_with_extra_if_needed(uint32 arg_length)
{
if (arg_length < Alloced_length)
{
Ptr[arg_length]=0; // behave as if realloc was called.
return 0;
}
return realloc_with_extra(arg_length);
}
inline void shrink(uint32 arg_length) // Shrink buffer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment