From b34c025b5280cd9e708f1a2a3ee9e06fd90ada39 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 7 Oct 2021 14:30:56 +0200 Subject: [PATCH] util: avoid calling snprintf in PrintStringsToBuffer As we print only one character --- src/util-print.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/util-print.c b/src/util-print.c index fadd4e2fbf..1f772a267d 100644 --- a/src/util-print.c +++ b/src/util-print.c @@ -229,12 +229,13 @@ void PrintStringsToBuffer(uint8_t *dst_buf, uint32_t *dst_buf_offset_ptr, uint32 const uint8_t *src_buf, const uint32_t src_buf_len) { uint32_t ch = 0; - for (ch = 0; ch < src_buf_len; ch++) { - PrintBufferData((char *)dst_buf, dst_buf_offset_ptr, dst_buf_size, - "%c", - (isprint((uint8_t)src_buf[ch]) || - src_buf[ch] == '\n' || - src_buf[ch] == '\r') ? (uint8_t)src_buf[ch] : '.'); + for (ch = 0; ch < src_buf_len && *dst_buf_offset_ptr < dst_buf_size; + ch++, (*dst_buf_offset_ptr)++) { + if (isprint((uint8_t)src_buf[ch]) || src_buf[ch] == '\n' || src_buf[ch] == '\r') { + dst_buf[*dst_buf_offset_ptr] = src_buf[ch]; + } else { + dst_buf[*dst_buf_offset_ptr] = '.'; + } } dst_buf[dst_buf_size - 1] = 0; -- 2.47.2