Replace our use of strncpy

strncpy will fill the entire buffer with NUL.

In this case we have a 128 byte buffer and write "empty" - 5 bytes -
into it.

So now instead of writing 6 bytes it'll write 128 bytes. Especially
wasteful because we already did memset before
This commit is contained in:
Fabian Boehm 2022-08-27 17:45:52 +02:00
parent 07b2f1054b
commit b08490f051

View file

@ -1683,7 +1683,7 @@ void format_size_safe(char buff[128], unsigned long long sz) {
size_t idx = 0;
const char *const sz_name[] = {"kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", nullptr};
if (sz < 1) {
strncpy(buff, "empty", buff_size);
strcpy(buff, "empty");
} else if (sz < 1024) {
append_ull(buff, sz, &idx, max_len);
append_str(buff, "B", &idx, max_len);