hash-object: fix buffer reuse with --path in a subdirectory
commita1be47e4ca65718ec239e4b86a44e45220237aee
authorJeff King <peff@peff.net>
Tue, 21 Mar 2017 01:20:42 +0000 (20 21:20 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 Mar 2017 18:12:52 +0000 (21 11:12 -0700)
tree688e23ca3b924b229dbc2a8a94fdf4dab88ae294
parentc0f9c705890ac30871c70219c4b08d740fb40e2e
hash-object: fix buffer reuse with --path in a subdirectory

The hash-object command uses prefix_filename() without
duplicating its return value. Since that function returns a
static buffer, the value is overwritten by subsequent calls.

This can cause incorrect results when we use --path along
with hashing a file by its relative path, both of which need
to call prefix_filename(). We overwrite the filename
computed for --path, effectively ignoring it.

We can fix this by calling xstrdup on the return value. Note
that we don't bother freeing the "vpath" instance, as it
remains valid until the program exit.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/hash-object.c
t/t1007-hash-object.sh