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>
Jeff King committed
Feb 20, 2008 at 19:00 UTC
c1867cea90f8e7ee8e1be3fc07a402dde1b2666d
1 file changed
+9
-2
config.c
+9
-2
@@ -280,11 +280,18 @@ int git_parse_ulong(const char *value, unsigned long *ret)
280
return 0;
281
}
282
283
+static void die_bad_config(const char *name)
284
+{
285
+ if (config_file_name)
286
+ die("bad config value for '%s' in %s", name, config_file_name);
287
+ die("bad config value for '%s'", name);
288
+}
289
+
290
int git_config_int(const char *name, const char *value)
291
{
292
long ret;
293
if (!git_parse_long(value, &ret))
287
- die("bad config value for '%s' in %s", name, config_file_name);
294
+ die_bad_config(name);
295
return ret;
296
}
297
@@ -292,7 +299,7 @@ unsigned long git_config_ulong(const char *name, const char *value)
299
{
300
unsigned long ret;
301
if (!git_parse_ulong(value, &ret))
295
- die("bad config value for '%s' in %s", name, config_file_name);
302
+ die_bad_config(name);
303
return ret;
304
}
305