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

[PATCH 3/3] stop_progress_msg: convert xsnprintf to git_psprintf

From
Maxim Moseychuk <franchesko.salias.hudro.pedros@gmail.com>
Date
Feb 16, 2017, 11:28 UTC
Message-ID
<20170216112829.18079-4-franchesko.salias.hudro.pedros@gmail.com>
In-Reply-To
<20170216112829.18079-1-franchesko.salias.hudro.pedros@gmail.com>
Replace local safe string buffer allocation by git_psprintf.
Signed-off-by: Maxim Moseychuk <franchesko.salias.hudro.pedros@gmail.com>
---
 progress.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/progress.c b/progress.c
index 76a88c573..989d65504 100644
--- a/progress.c
+++ b/progress.c
@@ -243,21 +243,18 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
 	*p_progress = NULL;
 	if (progress->last_value != -1) {
 		/* Force the last update */
-		char buf[128], *bufp;
-		size_t len = strlen(msg) + 5;
+		char *bufp;
 		struct throughput *tp = progress->throughput;
 
-		bufp = (len < sizeof(buf)) ? buf : xmallocz(len);
 		if (tp) {
 			unsigned int rate = !tp->avg_misecs ? 0 :
 					tp->avg_bytes / tp->avg_misecs;
 			throughput_string(&tp->display, tp->curr_total, rate);
 		}
 		progress_update = 1;
-		xsnprintf(bufp, len + 1, ", %s.\n", msg);
+		bufp = git_psprintf(", %s.\n", msg);
 		display(progress, progress->last_value, bufp);
-		if (buf != bufp)
-			free(bufp);
+		free(bufp);
 	}
 	clear_progress_signal();
 	if (progress->throughput)
-- 
2.11.1
Previous: Jeff KingNext: Jeff King
Message 5 of 9 in “Fix l10n”
  1. 0/3 Fix l10nMaxim Moseychuk, Feb 16, 2017
  2. 1/3 add git_psprintf helper functionMaxim Moseychuk, Feb 16, 2017
  3. Jonathan TanFeb 16, 2017
  4. Jeff KingFeb 16, 2017
  5. 3/3 stop_progress_msg: convert xsnprintf to git_psprintfMaxim Moseychuk, Feb 16, 2017
  6. Jeff KingFeb 16, 2017
  7. 2/3 bisect_next_all: convert xsnprintf to git_psprintfMaxim Moseychuk, Feb 16, 2017
  8. Jeff KingFeb 16, 2017
  9. Jeff KingFeb 16, 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.