Fix initial buffer overflow
This commit is contained in:
parent
d6f9054bc0
commit
165852bf65
1 changed files with 13 additions and 20 deletions
33
file.c
33
file.c
|
@ -105,25 +105,18 @@ char *get_line(ArrayList *list, long index, int detail, int icons)
|
||||||
{
|
{
|
||||||
file f = list->items[index];
|
file f = list->items[index];
|
||||||
|
|
||||||
size_t length = strlen(f.name) + 1;
|
size_t length = strlen(f.name) + 1;
|
||||||
if (detail) {
|
length += detail ? strlen(f.stats) + 1 : 0;
|
||||||
length += strlen(f.stats) + 1; /* 1 for space */
|
length += icons ? strlen(f.icon) + 1 : 0;
|
||||||
}
|
|
||||||
if (icons) {
|
|
||||||
length += 5; /* 4 for icon, 1 for space */
|
|
||||||
}
|
|
||||||
|
|
||||||
char *line = memalloc(length);
|
char *line = memalloc(length);
|
||||||
line[0] = '\0';
|
|
||||||
if (detail) {
|
snprintf(line, length, "%s%s%s%s%s",
|
||||||
strcat(line, f.stats);
|
detail ? f.stats : "",
|
||||||
strcat(line, " ");
|
detail ? " " : "",
|
||||||
}
|
icons ? f.icon : "",
|
||||||
if (icons) {
|
icons ? " " : "",
|
||||||
strcat(line, f.icon);
|
f.name);
|
||||||
strcat(line, " ");
|
|
||||||
}
|
return line;
|
||||||
strcat(line, f.name);
|
|
||||||
line[length] = '\0';
|
|
||||||
return line;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue