Skip to content

Commit 461bff5

Browse files
Humberto RondónDuncaen
authored andcommitted
bin/xbps-query: fix off-by-one error adding ellipsis
Last line `sd->linebuf[sd->maxcols]` is writing beyond the bounds of the array. Also, adding a null terminator is not neccesary because `snprintf` already does that.
1 parent 63494b7 commit 461bff5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

bin/xbps-query/search.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ print_results(struct xbps_handle *xhp, struct search_ctx *sd)
7676
align, pkgver, desc);
7777
/* add ellipsis if the line was truncated */
7878
if (len >= sd->maxcols && sd->maxcols > 4) {
79-
for (unsigned int j = 0; j < 3; j++)
80-
sd->linebuf[sd->maxcols-j-1] = '.';
81-
sd->linebuf[sd->maxcols] = '\0';
79+
sd->linebuf[sd->maxcols - 4] = '.';
80+
sd->linebuf[sd->maxcols - 3] = '.';
81+
sd->linebuf[sd->maxcols - 2] = '.';
8282
}
8383
puts(sd->linebuf);
8484
}

0 commit comments

Comments
 (0)