git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] test-stringlist: avoid buffer underrun when sorting nothing

From
René Scharfe <l.s.r@web.de>
Date
Oct 3, 2017, 14:36 UTC
Message-ID
<16d3a84c-b695-a55d-0263-885d0d34ae95@web.de>

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
Next: Jonathan Nieder
Message 1 of 2 in “test-stringlist: avoid buffer underrun when sorting nothing”
  1. test-stringlist: avoid buffer underrun when sorting nothingRené Scharfe, Oct 3, 2017
  2. Jonathan NiederOct 3, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.