git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] git_config_*: don't assume we are parsing a config file

From
Jeff King <peff@peff.net>
Date
Feb 21, 2008, 00:00 UTC
Message-ID
<20080221000032.GA6429@coredump.intra.peff.net>
In-Reply-To
<20080220235944.GA6278@coredump.intra.peff.net>

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>
---
 config.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/config.c b/config.c
index 8064cae..cba2bcf 100644
--- a/config.c
+++ b/config.c
@@ -280,11 +280,18 @@ 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;
 }
 
@@ -292,7 +299,7 @@ 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;
 }
 
-- 
1.5.4.2.247.g107bd
Previous: Jeff KingNext: Jeff King
Message 2 of 28 in “solaris test results”
  1. 0/3 solaris test resultsJeff King, Feb 20, 2008
  2. 1/3 git_config_*: don't assume we are parsing a config fileJeff King, Feb 21, 2008
  3. 2/3 t3404: use configured shell instead of /bin/shJeff King, Feb 21, 2008
  4. Johannes SixtFeb 23, 2008
  5. Junio C HamanoFeb 23, 2008
  6. Junio C HamanoFeb 23, 2008
  7. Johannes SixtFeb 23, 2008
  8. Jeff KingFeb 23, 2008
  9. Junio C HamanoFeb 23, 2008
  10. Jeff KingFeb 23, 2008
  11. Junio C HamanoFeb 23, 2008
  12. Jeff KingFeb 23, 2008
  13. Junio C HamanoFeb 23, 2008
  14. Jeff KingFeb 23, 2008
  15. Junio C HamanoFeb 24, 2008
  16. Jeff KingFeb 24, 2008
  17. Jeff KingFeb 23, 2008
  18. Junio C HamanoFeb 23, 2008
  19. Jeff KingFeb 23, 2008
  20. Jeff KingFeb 23, 2008
  21. Junio C HamanoFeb 23, 2008
  22. Jeff KingFeb 23, 2008
  23. 3/3 diff: fix java funcname pattern for solarisJeff King, Feb 21, 2008
  24. Junio C HamanoFeb 21, 2008
  25. Jeff KingFeb 21, 2008
  26. Junio C HamanoFeb 22, 2008
  27. Junio C HamanoFeb 22, 2008
  28. Jeff KingFeb 22, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.