git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] test-stringlist: avoid buffer underrun when sorting nothing
@ 2017-10-03 14:36 René Scharfe
  2017-10-03 22:59 ` Jonathan Nieder
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2017-10-03 14:36 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

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>
---
 t/helper/test-string-list.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/helper/test-string-list.c b/t/helper/test-string-list.c
index c502fa16d3..829ec3d7d2 100644
--- a/t/helper/test-string-list.c
+++ b/t/helper/test-string-list.c
@@ -108,7 +108,7 @@ int cmd_main(int argc, const char **argv)
 		 * Split by newline, but don't create a string_list item
 		 * for the empty string after the last separator.
 		 */
-		if (sb.buf[sb.len - 1] == '\n')
+		if (sb.len && sb.buf[sb.len - 1] == '\n')
 			strbuf_setlen(&sb, sb.len - 1);
 		string_list_split_in_place(&list, sb.buf, '\n', -1);
 
-- 
2.14.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] test-stringlist: avoid buffer underrun when sorting nothing
  2017-10-03 14:36 [PATCH] test-stringlist: avoid buffer underrun when sorting nothing René Scharfe
@ 2017-10-03 22:59 ` Jonathan Nieder
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Nieder @ 2017-10-03 22:59 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Junio C Hamano

René Scharfe wrote:

> 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>
> ---
>  t/helper/test-string-list.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Thanks for fixing it.
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-03 22:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-03 14:36 [PATCH] test-stringlist: avoid buffer underrun when sorting nothing René Scharfe
2017-10-03 22:59 ` Jonathan Nieder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).