]> git.ipfire.org Git - thirdparty/git.git/commit - setup.c
setup.c: do not feed NULL to "%.*s" even with precision 0
authorJunio C Hamano <gitster@pobox.com>
Thu, 7 Apr 2016 19:38:18 +0000 (12:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 Apr 2016 19:40:15 +0000 (12:40 -0700)
commit24041d6be54d89b5fb0b2bbf70df04bbbff6ba9e
tree9cfe7120b6ca7b97aac2542c99b5f95690c8812b
parent75faa45ae0230b321bf72027b2274315d7e14e34
setup.c: do not feed NULL to "%.*s" even with precision 0

A recent update 75faa45a (replace trivial malloc + sprintf / strcpy
calls with xstrfmt, 2015-09-24) rewrote

prepare an empty buffer
if (len)
         append the first len bytes of "prefix" to the buffer
append "path" to the buffer

that computed "path", optionally prefixed by "prefix", into

xstrfmt("%.*s%s", len, prefix, path);

However, passing a NULL pointer to the printf(3) family of functions
to format it with %s conversion, even with the precision set to 0,
i.e.

xstrfmt("%.*s", 0, NULL)

yields undefined results, at least on some platforms.

Avoid this problem by substituting prefix with "" when len==0, as
prefix can legally be NULL in that case.  This would mimick the
intent of the original code better.

Reported-by: Tom G. Christensen <tgc@jupiterrise.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c