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

Re: [PATCH 06/10] diff.c: convert trivial snprintf calls to xsnprintf

From
Jeff King <peff@peff.net>
Date
Jun 3, 2016, 09:03 UTC
Message-ID
<20160603090320.GE28401@sigill.intra.peff.net>
In-Reply-To
<20160603074724.12173-6-gitter.spiros@gmail.com>
On Fri, Jun 03, 2016 at 07:47:20AM +0000, Elia Pinto wrote:
Show 16 quoted lines
>  diff.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/diff.c b/diff.c
> index d3734d3..fb61539 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -4491,7 +4491,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
>  		len1 = remove_space(p->one->path, strlen(p->one->path));
>  		len2 = remove_space(p->two->path, strlen(p->two->path));
>  		if (p->one->mode == 0)
> -			len1 = snprintf(buffer, sizeof(buffer),
> +			len1 = xsnprintf(buffer, sizeof(buffer),
>  					"diff--gita/%.*sb/%.*s"
>  					"newfilemode%06o"
>  					"---/dev/null"

More that assume that PATH_MAX is plenty big for any patch we would see. I'd argue these should be on the heap, which removes that restriction, and gets rid of the "PATH_MAX * 4 + 20" magic at the top of the function.

It looks like the buffer just gets fed into sha1, so I was also tempted to suggest we simply feed the bits of string in directly. But we are using the format string here to handle the mode, so you'd still have to deal with that.

-Peff
Previous: Elia PintoNext: Elia Pinto
Message 13 of 21 in “builtin/commit.c: convert trivial snprintf calls to xsnprintf”
  1. 01/10 builtin/commit.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  2. 02/10 builtin/index-pack.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  3. Jeff KingJun 3, 2016
  4. Ramsay JonesJun 3, 2016
  5. Jeff KingJun 3, 2016
  6. 03/10 builtin/tag.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  7. Jeff KingJun 3, 2016
  8. Ramsay JonesJun 3, 2016
  9. 04/10 combine-diff.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  10. Jeff KingJun 3, 2016
  11. 05/10 compat/inet_ntop.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  12. 06/10 diff.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  13. Jeff KingJun 3, 2016
  14. 07/10 fast-import.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  15. 08/10 refs.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  16. 09/10 transport-helper.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  17. 10/10 wrapper.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  18. Jeff KingJun 3, 2016
  19. Jeff KingJun 3, 2016
  20. Jeff KingJun 3, 2016
  21. Ramsay JonesJun 3, 2016

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.