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

Re: [PATCH] progress.c: avoid use of dynamic-sized array

From
Alex Riesen <raa.lkml@gmail.com>
Date
Jun 8, 2008, 21:34 UTC
Message-ID
<20080608213438.GA3073@steel.home>
In-Reply-To
<Pine.LNX.4.64.0806080924330.18454@xenau.zenez.com>
Boyd Lynn Gerber, Sun, Jun 08, 2008 17:26:15 +0200:
Show 7 quoted lines
>  		/* Force the last update */
> -		char buf[strlen(msg) + 5];
> +		char buf[128], *bufp;
> +		size_t len = strlen(msg) + 5;
>  		struct throughput *tp = progress->throughput;
> +
> +		bufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);

It is just a temporary buffer, there is no urgent need to micro-optimize the allocation like that. Maybe just leave one of the buffers, the one on stack? It is just a progress message, snprintf will cut it, yes, but it is unlikely to cause any harm (unless you forget to \n-terminate it).

Previous: Boyd Lynn GerberNext: しらいしななこ
Message 4 of 7 in “progress.c: avoid use of dynamic-sized array”
  1. progress.c: avoid use of dynamic-sized arrayBoyd Lynn Gerber, Jun 8, 2008
  2. Johannes SchindelinJun 8, 2008
  3. Boyd Lynn GerberJun 8, 2008
  4. Alex RiesenJun 8, 2008
  5. しらいしななこJun 8, 2008
  6. Junio C HamanoJun 8, 2008
  7. Boyd Lynn GerberJun 8, 2008

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.