]> git.ipfire.org Git - thirdparty/git.git/commit - http.c
use strip_suffix and xstrfmt to replace suffix
authorJeff King <peff@peff.net>
Thu, 24 Sep 2015 21:07:09 +0000 (17:07 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 25 Sep 2015 17:18:18 +0000 (10:18 -0700)
commit9ae97018fb2e7f30ab92fdc2965d1dcff2c5c296
tree651d9b03d68a22759fa0ec862c11e91e17b9362c
parent2805bb59708e1cf049445fb8b21de1a710a3a16c
use strip_suffix and xstrfmt to replace suffix

When we want to convert "foo.pack" to "foo.idx", we do it by
duplicating the original string and then munging the bytes
in place. Let's use strip_suffix and xstrfmt instead, which
has several advantages:

  1. It's more clear what the intent is.

  2. It does not implicitly rely on the fact that
     strlen(".idx") <= strlen(".pack") to avoid an overflow.

  3. We communicate the assumption that the input file ends
     with ".pack" (and get a run-time check that this is so).

  4. We drop calls to strcpy, which makes auditing the code
     base easier.

Likewise, we can do this to convert ".pack" to ".bitmap",
avoiding some manual memory computation.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
http.c
pack-bitmap.c
sha1_file.c