archive: simplify archive format guessing
commitfe12d8e84f745303d64757307e9a6a81a6608018
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Sun, 7 Feb 2010 23:30:20 +0000 (8 00:30 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 7 Feb 2010 23:40:27 +0000 (7 15:40 -0800)
tree0e0fbad1cb5efcb49c893c5a94f2bcbdc15754af
parent2b26e0e18907132eaac2a8163de0cac552217082
archive: simplify archive format guessing

The code to guess an output archive's format consumed any --format
options and built a new one.  Jonathan noticed that it does so in an
unsafe way, risking to overflow the static buffer fmt_opt.

Change the code to keep the existing --format options intact and to only
add a new one if a format could be guessed based on the output file name.
The new option is added as the first one, allowing the existing ones to
overrule it, i.e. explicit --format options given on the command line win
over format guesses, as before.

To simplify the code further, format_from_name() is changed to return the
full --format option, thus no potentially dangerous sprintf() calls are
needed any more.

Reported-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-archive.c
t/t5000-tar-tree.sh