Skip to content

Commit

Permalink
git_config_*: don't assume we are parsing a config file
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Feb 21, 2008
1 parent 9a13ba1 commit c1867ce
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,26 @@ int git_parse_ulong(const char *value, unsigned long *ret)
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)
{
long 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;
}

unsigned long git_config_ulong(const char *name, const char *value)
{
unsigned long 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;
}

Expand Down

0 comments on commit c1867ce

Please sign in to comment.