In fact we also guard for value="" as it doesn't make more sense
for the variables here.
We do that by using a new function 'xstrdup_confval' to avoid code
duplication.
By the way this changes a 'strdup' into 'xstrdup'.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
diff.c | 23 +++++++++++++----------
1 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/diff.c b/diff.c
index 5b8afdc..d51aecb 100644
--- a/diff.c
+++ b/diff.c
@@ -60,6 +60,14 @@ static struct ll_diff_driver {
char *cmd;
} *user_diff, **user_diff_tail;
+static int xstrdup_confval(const char *dest, const char *var, const char *value)
+{
+ if (!value || !*value)
+ return error("%s: lacks value", var);
+ dest = xstrdup(value);
+ return 0;
+}
+
/*
* Currently there is only "diff.<drivername>.command" variable;
* because there are "diff.color.<slot>" variables, we are parsing
@@ -86,10 +94,7 @@ static int parse_lldiff_command(const char *var, const char *ep, const char *val
user_diff_tail = &(drv->next);
}
- if (!value)
- return error("%s: lacks value", var);
- drv->cmd = strdup(value);
- return 0;
+ return xstrdup_confval(drv->cmd, var, value);
}
/*
@@ -123,8 +128,8 @@ static int parse_funcname_pattern(const char *var, const char *ep, const char *v
}
if (pp->pattern)
free(pp->pattern);
- pp->pattern = xstrdup(value);
- return 0;
+
+ return xstrdup_confval(pp->pattern, var, value);
}
/*
@@ -157,10 +162,8 @@ int git_diff_ui_config(const char *var, const char *value)
diff_auto_refresh_index = git_config_bool(var, value);
return 0;
}
- if (!strcmp(var, "diff.external")) {
- external_diff_cmd_cfg = xstrdup(value);
- return 0;
- }
+ if (!strcmp(var, "diff.external"))
+ return xstrdup_confval(external_diff_cmd_cfg, var, value);
if (!prefixcmp(var, "diff.")) {
const char *ep = strrchr(var, '.');
--
1.5.4.35.g3360
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html| Natalie Protasevich | [BUG] New Kernel Bugs |
| Greg KH | [GIT PATCH] driver core patches against 2.6.24 |
| Bart Van Assche | Integration of SCST in the mainstream Linux kernel |
| Andi Kleen | [PATCH x86] [0/16] Various i386/x86-64 changes |
git: | |
| Gerrit Renker | [PATCH 27/37] dccp: Integration of dynamic feature activation - part 2 (server side) |
| Jarek Poplawski | [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| Linus Torvalds | Re: [GIT]: Networking |
| Jeff Kirsher | [net-next PATCH 1/7] e1000e: enable CRC stripping by default |
| Jukka Andberg | ata/wdc vs gcc3 on amiga |
| YAMAMOTO Takashi | Re: wd.c patch to reduce kernel stack usage |
| Jason Thorpe | Re: ksyms patches. |
| rick | NFS transport |
