[thin_metadata_size] Fix potential string overflow

This commit is contained in:
Ming-Hung Tsai 2021-06-02 11:39:01 +08:00
parent 759407445f
commit 3145a1f4de
1 changed files with 7 additions and 3 deletions

View File

@ -192,9 +192,13 @@ static void printf_aligned(struct global *g, char const *a, char const *b, char
{
char buf[80];
strcpy(buf, b);
if (units)
strcat(buf, mandatory ? "{" :"["), strcat(buf, g->unit.chars), strcat(buf, mandatory ? "}" : "]");
if (units) {
char left_bracket = mandatory ? '{' : '[';
char right_bracket = mandatory ? '}' : ']';
snprintf(buf, 80, "%s%c%s%c", b, left_bracket, g->unit.chars, right_bracket);
} else {
snprintf(buf, 80, "%s", b);
}
printf("\t%-4s%-44s%s\n", a, buf, c);
}