diff -r cf19b7820ff0 -r 94360453bce4 src/json.c --- a/src/json.c Thu Dec 25 12:07:37 2025 +0100 +++ b/src/json.c Sun Dec 28 14:10:14 2025 +0100 @@ -96,20 +96,16 @@ } static CxJsonToken token_create(CxJson *json, bool isstring, size_t start, size_t end) { - cxmutstr buf_str = cx_mutstrn(json->buffer.space + start, end - start); - cxmutstr str; - bool allocated; + cxmutstr str = cx_mutstrn(json->buffer.space + start, end - start); + bool allocated = false; if (json->uncompleted_tokentype != CX_JSON_NO_TOKEN) { allocated = true; - str = json->uncompleted_content; - if (cx_strcat(&str, 1, buf_str)) { - return (CxJsonToken){CX_JSON_NO_TOKEN, false, {NULL, 0}}; // LCOV_EXCL_LINE + str = cx_strcat(json->uncompleted_content, 1, str); + if (str.ptr == NULL) { + return (CxJsonToken){CX_JSON_NO_TOKEN, false, CX_NULLSTR}; // LCOV_EXCL_LINE } - json->uncompleted_content = (cxmutstr){NULL, 0}; + json->uncompleted_content = CX_NULLSTR; json->uncompleted_tokentype = CX_JSON_NO_TOKEN; - } else { - allocated = false; - str = buf_str; } CxJsonTokenType ttype; if (isstring) { @@ -126,7 +122,7 @@ if (allocated) { cx_strfree(&str); } - return (CxJsonToken){CX_JSON_TOKEN_ERROR, false, {NULL, 0}}; + return (CxJsonToken){CX_JSON_TOKEN_ERROR, false, CX_NULLSTR}; } return (CxJsonToken){ttype, allocated, str}; } @@ -193,7 +189,7 @@ } else if (ctype != CX_JSON_NO_TOKEN) { // single-char token json->buffer.pos = i + 1; - *result = (CxJsonToken){ctype, false, {NULL, 0}}; + *result = (CxJsonToken){ctype, false, CX_NULLSTR}; return CX_JSON_NO_ERROR; } else { ttype = CX_JSON_TOKEN_LITERAL; // number or literal @@ -245,11 +241,13 @@ } json->uncompleted_tokentype = ttype; } else { - // previously we also had an uncompleted token + // previously we already had an uncompleted token // combine the uncompleted token with the current token - if (cx_strcat(&json->uncompleted_content, 1, uncompleted)) { + cxmutstr s = cx_strcat(json->uncompleted_content, 1, uncompleted); + if (s.ptr == NULL) { return CX_JSON_BUFFER_ALLOC_FAILED; // LCOV_EXCL_LINE } + json->uncompleted_content = s; } // advance the buffer position - we saved the stuff in the uncompleted token json->buffer.pos += uncompleted.length; @@ -1429,14 +1427,14 @@ CxBuffer buffer; if (cxBufferInit(&buffer, allocator, NULL, 128, CX_BUFFER_AUTO_EXTEND | CX_BUFFER_DO_NOT_FREE)) { - return (cxmutstr){NULL, 0}; + return CX_NULLSTR; } if (cx_json_write_rec(&buffer, value, cxBufferWriteFunc, writer, 0) || cxBufferTerminate(&buffer)) { // LCOV_EXCL_START buffer.flags &= ~CX_BUFFER_DO_NOT_FREE; cxBufferDestroy(&buffer); - return (cxmutstr){NULL, 0}; + return CX_NULLSTR; // LCOV_EXCL_STOP } else { cxmutstr str = cx_bstr_m(&buffer);