summaryrefslogtreecommitdiff
path: root/src/remote.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2012-11-13 14:43:23 -0800
committerCarlos Martín Nieto <cmn@elego.de>2012-11-13 14:49:16 -0800
commit0da81d2b39290fe4d444953acb6d68795ed1ef42 (patch)
tree70f00cde763374e35bf214bcd50e5a39b3b098c7 /src/remote.c
parent47db054df053fb09c8c92edaa0238af2a2605e65 (diff)
downloadlibgit2-0da81d2b39290fe4d444953acb6d68795ed1ef42.tar.gz
config: return an emtpy string when there is no value
Returning NULL for the string when we haven't signaled an error condition is counter-intuitive and causes unnecessary edge cases. Return an empty string when asking for a string value for a configuration variable such as '[section] var' to avoid these edge cases. If the distinction between no value and an empty value is needed, this can be retrieved from the entry directly. As a side-effect, this change stops the int parsing functions from segfaulting on such a variable.
Diffstat (limited to 'src/remote.c')
-rw-r--r--src/remote.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/remote.c b/src/remote.c
index 70a615246..4a4d160eb 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -136,7 +136,7 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
if ((error = git_config_get_string(&val, config, git_buf_cstr(&buf))) < 0)
goto cleanup;
- if (!val || strlen(val) == 0) {
+ if (strlen(val) == 0) {
giterr_set(GITERR_INVALID, "Malformed remote '%s' - missing URL", name);
error = -1;
goto cleanup;
@@ -153,8 +153,10 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
}
error = git_config_get_string(&val, config, git_buf_cstr(&buf));
- if (error == GIT_ENOTFOUND)
+ if (error == GIT_ENOTFOUND) {
+ val = NULL;
error = 0;
+ }
if (error < 0) {
error = -1;