Allow appending NULL to strings.
This commit is contained in:
parent
8f99011887
commit
05d2e13e6d
2 changed files with 11 additions and 3 deletions
|
@ -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);
|
||||
|
|
10
src/string.c
10
src/string.c
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue