From 05d2e13e6dddf5039904e34d7512df4380bae092 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sun, 30 Sep 2012 05:40:38 +0200 Subject: [PATCH] Allow appending NULL to strings. --- src/stream.c | 4 ++-- src/string.c | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/stream.c b/src/stream.c index 72054ca..5bc2318 100644 --- a/src/stream.c +++ b/src/stream.c @@ -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); diff --git a/src/string.c b/src/string.c index cb32628..9fdab5e 100644 --- a/src/string.c +++ b/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;