Allow appending NULL to strings.

This commit is contained in:
Jonathan Schleifer 2012-09-30 05:40:38 +02:00
parent 8f99011887
commit 05d2e13e6d
2 changed files with 11 additions and 3 deletions

View file

@ -120,7 +120,7 @@ cfw_stream_read_line(void *ptr)
}
cfw_string_set_nocopy(ret, ret_str, ret_len);
if (stream->cache_len - i - 1 > 0) {
if (stream->cache_len > i + 1) {
if ((new_cache = malloc(
stream->cache_len - i - 1)) == NULL)
return NULL;
@ -207,7 +207,7 @@ cfw_stream_read_line(void *ptr)
}
cfw_string_set_nocopy(ret, ret_str, ret_len);
if (buf_len - i - 1 > 0) {
if (buf_len > i + 1) {
new_cache = malloc(buf_len - i - 1);
if (new_cache == NULL) {
free(buf);

View file

@ -220,6 +220,9 @@ cfw_string_append(CFWString *str, CFWString *append)
{
char *new;
if (append == NULL)
return true;
if ((new = realloc(str->data, str->len + append->len + 1)) == NULL)
return false;
@ -235,8 +238,13 @@ cfw_string_append(CFWString *str, CFWString *append)
bool
cfw_string_append_c(CFWString *str, const char *append)
{
size_t append_len = strlen(append);
char *new;
size_t append_len;
if (append == NULL)
return true;
append_len = strlen(append);
if ((new = realloc(str->data, str->len + append_len + 1)) == NULL)
return false;