Index: src/stream.c ================================================================== --- src/stream.c +++ src/stream.c @@ -118,11 +118,11 @@ free(ret_str); return NULL; } 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; memcpy(new_cache, stream->cache + i + 1, stream->cache_len - i - 1); @@ -205,11 +205,11 @@ free(ret_str); return NULL; } 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); return NULL; } Index: src/string.c ================================================================== --- src/string.c +++ src/string.c @@ -217,10 +217,13 @@ bool 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; memcpy(new + str->len, append->data, append->len); @@ -233,12 +236,17 @@ } 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; memcpy(new + str->len, append, append_len);