From 3e243f31d8a261004f3e311c7ec5cb278d892a18 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 2 Feb 2022 18:32:31 +0100 Subject: Use `stpcpy(3)' for concatination The compiler (clang 13.0.0) warns about using `sprintf(3)' because it was being used to write a string into itself. In order to avoid this potentially causing issues in the future I have switched to using `stpcpy(3)'. --- mstatus.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mstatus.c b/mstatus.c index 376c608..f95f993 100644 --- a/mstatus.c +++ b/mstatus.c @@ -147,17 +147,19 @@ update_bar:; char buf[sb.length + (sb.count - 1) * seperator.len + 2]; memset(buf, '\0', sizeof(buf)); - /* Double for loops so that the seperator isnt printed to the left of the first block */ + /* Double loops so that the seperator isnt printed to the left of the first block */ int i; + char *bufptr = buf; for (i = 0; i < sb.count; i++) { if (sb.blocks[i]) { - strcpy(buf, sb.blocks[i]); + bufptr = stpcpy(buf, sb.blocks[i]); break; } } - for (i++; i < sb.count; i++) + while (++i < sb.count) { if (sb.blocks[i]) - sprintf(buf, "%s%s%s", buf, seperator.str, sb.blocks[i]); + bufptr = stpcpy(stpcpy(bufptr, seperator.str), sb.blocks[i]); + } if (rflag) strcat(buf, " "); -- cgit v1.2.3