diff options
author | Lennart Weller <lhw@ring0.de> | 2017-09-17 22:17:45 +0000 |
---|---|---|
committer | Lennart Weller <lhw@ring0.de> | 2017-09-17 22:17:45 +0000 |
commit | 7ee3962eaca4214264964ae32c86de457a90e382 (patch) | |
tree | 5a784485351593ac6d74fa9fd9bbd8fe7c9c3fe0 /src/web_buffer.c | |
parent | maintscript eludes me (diff) | |
parent | New upstream version 1.8.0+dfsg (diff) | |
download | netdata-7ee3962eaca4214264964ae32c86de457a90e382.tar.xz netdata-7ee3962eaca4214264964ae32c86de457a90e382.zip |
Updated version 1.8.0+dfsg from 'upstream/1.8.0+dfsg'
with Debian dir 412de09d9bca38fe00146ef090f9e53f76493882
Diffstat (limited to '')
-rw-r--r-- | src/web_buffer.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/web_buffer.c b/src/web_buffer.c index 9f9ceda63..f5452452f 100644 --- a/src/web_buffer.c +++ b/src/web_buffer.c @@ -84,6 +84,19 @@ inline char *print_number_llu_r(char *str, unsigned long long uvalue) { return wstr; } +inline char *print_number_llu_r_smart(char *str, unsigned long long uvalue) { +#ifdef ENVIRONMENT32 + if(uvalue > (unsigned long long)0xffffffff) + str = print_number_llu_r(str, uvalue); + else + str = print_number_lu_r(str, uvalue); +#else + do *str++ = (char)('0' + (uvalue % 10)); while(uvalue /= 10); +#endif + + return str; +} + void buffer_print_llu(BUFFER *wb, unsigned long long uvalue) { buffer_need_bytes(wb, 50); @@ -201,29 +214,25 @@ void buffer_sprintf(BUFFER *wb, const char *fmt, ...) { if(unlikely(!fmt || !*fmt)) return; - buffer_need_bytes(wb, 2); - - size_t len = wb->size - wb->len - 1; - size_t wrote; - va_list args; - va_start(args, fmt); - wrote = (size_t) vsnprintfz(&wb->buffer[wb->len], len, fmt, args); - va_end(args); + size_t wrote = 0, need = 2, multiplier = 0, len; + + do { + need += wrote + multiplier * WEB_DATA_LENGTH_INCREASE_STEP; + multiplier++; - if(unlikely(wrote >= len)) { - // truncated - buffer_overflow_check(wb); + debug(D_WEB_BUFFER, "web_buffer_sprintf(): increasing web_buffer at position %zu, size = %zu, by %zu bytes (wrote = %zu)\n", wb->len, wb->size, need, wrote); + buffer_need_bytes(wb, need); - debug(D_WEB_BUFFER, "web_buffer_sprintf(): increasing web_buffer at position %zu, size = %zu\n", wb->len, wb->size); - buffer_need_bytes(wb, len + WEB_DATA_LENGTH_INCREASE_STEP); + len = wb->size - wb->len - 1; va_start(args, fmt); - buffer_vsprintf(wb, fmt, args); + wrote = (size_t) vsnprintfz(&wb->buffer[wb->len], len, fmt, args); va_end(args); - } - else - wb->len += wrote; + + } while(wrote >= len); + + wb->len += wrote; // the buffer is \0 terminated by vsnprintf } |