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 --- osc.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'osc.c') diff --git a/osc.c b/osc.c index d24a4603..0e658ce6 100644 --- a/osc.c +++ b/osc.c @@ -17,6 +17,7 @@ #include "uri.h" #include "vt.h" #include "xmalloc.h" +#include "xsnprintf.h" #define UNHANDLED() LOG_DBG("unhandled: OSC: %.*s", (int)term->vt.osc.idx, term->vt.osc.data) @@ -522,9 +523,9 @@ osc_dispatch(struct terminal *term) uint8_t b = (color >> 0) & 0xff; char reply[32]; - snprintf(reply, sizeof(reply), "\033]4;%u;rgb:%02x/%02x/%02x\033\\", + size_t n = xsnprintf(reply, sizeof(reply), "\033]4;%u;rgb:%02x/%02x/%02x\033\\", idx, r, g, b); - term_to_slave(term, reply, strlen(reply)); + term_to_slave(term, reply, n); } else { @@ -568,11 +569,11 @@ osc_dispatch(struct terminal *term) * E.g. for color 0xdcdccc we reply "\033]10;rgb:dc/dc/cc\033\\" */ char reply[32]; - snprintf( + size_t n = xsnprintf( reply, sizeof(reply), "\033]%u;rgb:%02x/%02x/%02x\033\\", param, r, g, b); - term_to_slave(term, reply, strlen(reply)); + term_to_slave(term, reply, n); break; } @@ -602,8 +603,8 @@ osc_dispatch(struct terminal *term) uint8_t b = (term->cursor_color.cursor >> 0) & 0xff; char reply[32]; - snprintf(reply, sizeof(reply), "\033]12;rgb:%02x/%02x/%02x\033\\", r, g, b); - term_to_slave(term, reply, strlen(reply)); + size_t n = xsnprintf(reply, sizeof(reply), "\033]12;rgb:%02x/%02x/%02x\033\\", r, g, b); + term_to_slave(term, reply, n); break; } -- cgit v1.3