git_config_*: don't assume we are parsing a config file
These functions get called by other code, including parsing config options from the command line. In that case, config_file_name is NULL, leading to an ugly message or even a segfault on some implementations of printf. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
9a13ba1bed
commit
c1867cea90
11
config.c
11
config.c
|
@ -280,11 +280,18 @@ int git_parse_ulong(const char *value, unsigned long *ret)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void die_bad_config(const char *name)
|
||||||
|
{
|
||||||
|
if (config_file_name)
|
||||||
|
die("bad config value for '%s' in %s", name, config_file_name);
|
||||||
|
die("bad config value for '%s'", name);
|
||||||
|
}
|
||||||
|
|
||||||
int git_config_int(const char *name, const char *value)
|
int git_config_int(const char *name, const char *value)
|
||||||
{
|
{
|
||||||
long ret;
|
long ret;
|
||||||
if (!git_parse_long(value, &ret))
|
if (!git_parse_long(value, &ret))
|
||||||
die("bad config value for '%s' in %s", name, config_file_name);
|
die_bad_config(name);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +299,7 @@ unsigned long git_config_ulong(const char *name, const char *value)
|
||||||
{
|
{
|
||||||
unsigned long ret;
|
unsigned long ret;
|
||||||
if (!git_parse_ulong(value, &ret))
|
if (!git_parse_ulong(value, &ret))
|
||||||
die("bad config value for '%s' in %s", name, config_file_name);
|
die_bad_config(name);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue