From: Philippe Antoine Date: Thu, 7 Oct 2021 12:30:56 +0000 (+0200) Subject: util: avoid calling snprintf in PrintStringsToBuffer X-Git-Tag: suricata-7.0.0-beta1~1295 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b34c025b5280cd9e708f1a2a3ee9e06fd90ada39;p=thirdparty%2Fsuricata.git util: avoid calling snprintf in PrintStringsToBuffer As we print only one character --- 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;