From cf4a20ee0b9fc46670e77a8bba26cd173ce5bc19 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 6 Mar 2021 13:40:21 -0800 Subject: [PATCH] remove some unnecessary intermediate buffers in lefty --- cmd/lefty/str.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/cmd/lefty/str.c b/cmd/lefty/str.c index 1c0d70384..03a0f91f0 100644 --- a/cmd/lefty/str.c +++ b/cmd/lefty/str.c @@ -443,26 +443,18 @@ static void appends (char *s) { } static void appendi (long i) { - char buf[40]; - int n; - - sprintf (buf, "%ld", i); - n = strlen (buf) + 1; + int n = snprintf(NULL, 0, "%ld", i) + 1; if (sbufi + n > sbufn) growsbuf (n); - strcpy (&sbufp[sbufi], buf); + sprintf(&sbufp[sbufi], "%ld", i); sbufi += (n - 1); } static void appendd (double d) { - char buf[40]; - int n; - - sprintf (buf, "%lf", d); - n = strlen (buf) + 1; + int n = snprintf(NULL, 0, "%lf", d) + 1; if (sbufi + n > sbufn) growsbuf (n); - strcpy (&sbufp[sbufi], buf); + sprintf(&sbufp[sbufi], "%lf", d); sbufi += (n - 1); } -- 2.40.0