Skip to content

Commit 97487ea

Browse files
rscharfegitster
authored andcommitted
test-stringlist: avoid buffer underrun when sorting nothing
Check if the strbuf containing data to sort is empty before attempting to trim a trailing newline character. Signed-off-by: Rene Scharfe <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 83fc4d6 commit 97487ea

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

t/helper/test-string-list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int cmd_main(int argc, const char **argv)
108108
* Split by newline, but don't create a string_list item
109109
* for the empty string after the last separator.
110110
*/
111-
if (sb.buf[sb.len - 1] == '\n')
111+
if (sb.len && sb.buf[sb.len - 1] == '\n')
112112
strbuf_setlen(&sb, sb.len - 1);
113113
string_list_split_in_place(&list, sb.buf, '\n', -1);
114114

0 commit comments

Comments
 (0)