]> git.ipfire.org Git - thirdparty/git.git/commit - remote.c
use xstrfmt in favor of manual size calculations
authorJeff King <peff@peff.net>
Wed, 18 Jun 2014 20:02:13 +0000 (16:02 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 19 Jun 2014 19:25:17 +0000 (12:25 -0700)
commitfa3f60b783b42e0d07c667a8f582c3df12791cec
treefab9253df02e858467cf98ede8c1bebfe75be11e
parent30a0ddb705678d512185e359831479a6b3567147
use xstrfmt in favor of manual size calculations

In many parts of the code, we do an ugly and error-prone
malloc like:

  const char *fmt = "something %s";
  buf = xmalloc(strlen(foo) + 10 + 1);
  sprintf(buf, fmt, foo);

This makes the code brittle, and if we ever get the
allocation wrong, is a potential heap overflow. Let's
instead favor xstrfmt, which handles the allocation
automatically, and makes the code shorter and more readable.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c
unpack-trees.c