add_packed_git: convert strcpy into xsnprintf

We have the path "foo.idx", and we create a buffer big
enough to hold "foo.pack" and "foo.keep", and then strcpy
straight into it. This isn't a bug (we have enough space),
but it's very hard to tell from the strcpy that this is so.

Let's instead use strip_suffix to take off the ".idx",
record the size of our allocation, and use xsnprintf to make
sure we don't violate our assumptions.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King
2015-09-24 17:06:55 -04:00
committed by Junio C Hamano
parent 330c8e2670
commit 48bcc1c3cc
2 changed files with 14 additions and 9 deletions

View File

@ -1309,7 +1309,7 @@ extern void close_pack_windows(struct packed_git *);
extern void unuse_pack(struct pack_window **);
extern void free_pack_by_name(const char *);
extern void clear_delta_base_cache(void);
extern struct packed_git *add_packed_git(const char *, int, int);
extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
/*
* Return the SHA-1 of the nth object within the specified packfile.