Skip to content

Commit 24041d6

Browse files
committed
setup.c: do not feed NULL to "%.*s" even with precision 0
A recent update 75faa45 (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 <[email protected]> Helped-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 75faa45 commit 24041d6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ char *prefix_path_gently(const char *prefix, int len,
9999
return NULL;
100100
}
101101
} else {
102-
sanitized = xstrfmt("%.*s%s", len, prefix, path);
102+
sanitized = xstrfmt("%.*s%s", len, len ? prefix : "", path);
103103
if (remaining_prefix)
104104
*remaining_prefix = len;
105105
if (normalize_path_copy_len(sanitized, sanitized, remaining_prefix)) {

0 commit comments

Comments
 (0)