diff --git a/intern/clog/clog.c b/intern/clog/clog.c index 9202861a589..c96b74e09f7 100644 --- a/intern/clog/clog.c +++ b/intern/clog/clog.c @@ -175,9 +175,8 @@ static void clg_str_vappendf(CLogStringBuf *cstr, const char *fmt, va_list args) { /* Use limit because windows may use '-1' for a formatting error. */ const uint len_max = 65535; + uint len_avail = cstr->len_alloc - cstr->len; while (true) { - uint len_avail = cstr->len_alloc - cstr->len; - va_list args_cpy; va_copy(args_cpy, args); int retval = vsnprintf(cstr->data + cstr->len, len_avail, fmt, args_cpy); @@ -188,22 +187,23 @@ static void clg_str_vappendf(CLogStringBuf *cstr, const char *fmt, va_list args) * message. */ break; } - else if ((uint)retval <= len_avail) { + + if ((uint)retval <= len_avail) { /* Copy was successful. */ cstr->len += (uint)retval; break; } - else { - /* vsnprintf was not successful, due to lack of allocated space, retval contains expected - * length of the formatted string, use it to allocate required amount of memory. */ - uint len_alloc = cstr->len + (uint)retval; - if (len_alloc >= len_max) { - /* Safe upper-limit, just in case... */ - break; - } - clg_str_reserve(cstr, len_alloc); - len_avail = cstr->len_alloc - cstr->len; + + /* `vsnprintf` was not successful, due to lack of allocated space, `retval` contains expected + * length of the formatted string, use it to allocate required amount of memory. */ + uint len_alloc = cstr->len + (uint)retval; + if (len_alloc >= len_max) { + /* Safe upper-limit, just in case... */ + break; } + + clg_str_reserve(cstr, len_alloc); + len_avail = cstr->len_alloc - cstr->len; } }