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 <l.s.r@web.de> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Oct 3, 2017 at 16:36 UTC 97487ea11a2c68934927e515616c133e543a72ce
1 file changed +1 -1
t/helper/test-string-list.c
+1 -1
@@ -108,7 +108,7 @@ int cmd_main(int argc, const char **argv)
108 * Split by newline, but don't create a string_list item
109 * for the empty string after the last separator.
110 */
111 - if (sb.buf[sb.len - 1] == '\n')
111 + if (sb.len && sb.buf[sb.len - 1] == '\n')
112 strbuf_setlen(&sb, sb.len - 1);
113 string_list_split_in_place(&list, sb.buf, '\n', -1);
114