From 3f4cfa338b5035b3789ea414eab9f139a18d140b Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Thu, 14 Jan 2021 21:30:06 +0000 Subject: Add xsnprintf() and remove some unnecessary strlen(3) calls --- sixel.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'sixel.c') diff --git a/sixel.c b/sixel.c index cfca4d4a..96d2aba2 100644 --- a/sixel.c +++ b/sixel.c @@ -10,6 +10,7 @@ #include "hsl.h" #include "util.h" #include "xmalloc.h" +#include "xsnprintf.h" static size_t count; @@ -1101,8 +1102,8 @@ void sixel_colors_report_current(struct terminal *term) { char reply[24]; - snprintf(reply, sizeof(reply), "\033[?1;0;%uS", term->sixel.palette_size); - term_to_slave(term, reply, strlen(reply)); + size_t n = xsnprintf(reply, sizeof(reply), "\033[?1;0;%uS", term->sixel.palette_size); + term_to_slave(term, reply, n); LOG_DBG("query response for current color count: %u", term->sixel.palette_size); } @@ -1135,8 +1136,8 @@ void sixel_colors_report_max(struct terminal *term) { char reply[24]; - snprintf(reply, sizeof(reply), "\033[?1;0;%uS", SIXEL_MAX_COLORS); - term_to_slave(term, reply, strlen(reply)); + size_t n = xsnprintf(reply, sizeof(reply), "\033[?1;0;%uS", SIXEL_MAX_COLORS); + term_to_slave(term, reply, n); LOG_DBG("query response for max color count: %u", SIXEL_MAX_COLORS); } @@ -1144,10 +1145,10 @@ void sixel_geometry_report_current(struct terminal *term) { char reply[64]; - snprintf(reply, sizeof(reply), "\033[?2;0;%u;%uS", + size_t n = xsnprintf(reply, sizeof(reply), "\033[?2;0;%u;%uS", min(term->cols * term->cell_width, term->sixel.max_width), min(term->rows * term->cell_height, term->sixel.max_height)); - term_to_slave(term, reply, strlen(reply)); + term_to_slave(term, reply, n); LOG_DBG("query response for current sixel geometry: %ux%u", term->sixel.max_width, term->sixel.max_height); @@ -1178,8 +1179,8 @@ sixel_geometry_report_max(struct terminal *term) unsigned max_height = term->rows * term->cell_height; char reply[64]; - snprintf(reply, sizeof(reply), "\033[?2;0;%u;%uS", max_width, max_height); - term_to_slave(term, reply, strlen(reply)); + size_t n = xsnprintf(reply, sizeof(reply), "\033[?2;0;%u;%uS", max_width, max_height); + term_to_slave(term, reply, n); LOG_DBG("query response for max sixel geometry: %ux%u", max_width, max_height); -- cgit v1.3