diff options
author | Thomas Voss <thomasvoss@live.com> | 2022-02-02 18:32:31 +0100 |
---|---|---|
committer | Thomas Voss <thomasvoss@live.com> | 2022-02-02 18:32:31 +0100 |
commit | 3e243f31d8a261004f3e311c7ec5cb278d892a18 (patch) | |
tree | 86093bf3f8ded32b135db368d737c79e568c4fe2 | |
parent | d36d861ffb0635563c056ffcfe8119b423714db9 (diff) |
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)'.
-rw-r--r-- | mstatus.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -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, " "); |