diff --git a/src/stdio.c b/src/stdio.c index d8d53e3..687686b 100644 --- a/src/stdio.c +++ b/src/stdio.c @@ -9,25 +9,19 @@ static int32_t rtstring_output_handler(void *user, const char *data, size_t size) { - string_descriptor_t *str_descriptor = (string_descriptor_t*)user; + string_descriptor_t* str_descriptor = (string_descriptor_t*)user; - size_t len = size; + size_t len = size < (str_descriptor->len - 1) ? size : (str_descriptor->len - 1); - if (str_descriptor->len > 0) + if (len) { - if (len > (str_descriptor->len - 1)) - len = str_descriptor->len - 1; - str_descriptor->len -= len; - } - if (str_descriptor->ptr && len) - { memcpy(str_descriptor->ptr, data, len); str_descriptor->ptr += len; *str_descriptor->ptr = 0; } - + return size; } diff --git a/src/stdio_internal.h b/src/stdio_internal.h index 17ee84a..4eb3d25 100644 --- a/src/stdio_internal.h +++ b/src/stdio_internal.h @@ -7,7 +7,7 @@ typedef struct { - char *ptr; + char* ptr; size_t len; }string_descriptor_t;