summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2019-06-22 10:03:36 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-06-24 19:34:19 (GMT)
commit664178e8e23fbd6d79b02ea51374015023c02102 (patch)
tree5a3271be87bb31c92ebd97af3e144f3a1d1615de /config.c
parent3fb72c7b4d90fb7f95ca60f448c7739cca6c1846 (diff)
downloadgit-664178e8e23fbd6d79b02ea51374015023c02102.zip
git-664178e8e23fbd6d79b02ea51374015023c02102.tar.gz
git-664178e8e23fbd6d79b02ea51374015023c02102.tar.bz2
config: don't multiply in parse_unit_factor()
parse_unit_factor() multiplies the number that is passed to it with the value of a recognized unit factor (K, M or G for 2^10, 2^20 and 2^30, respectively). All callers pass in 1 as a number, though, which allows them to check the actual multiplication for overflow before they are doing it themselves. Ignore the passed in number and don't multiply, as this feature of parse_unit_factor() is not used anymore. Rename the output parameter to reflect that it's not about the end result anymore, but just about the unit factor. Suggested-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/config.c b/config.c
index 3c00369..a8bd1d8 100644
--- a/config.c
+++ b/config.c
@@ -834,20 +834,22 @@ static int git_parse_source(config_fn_t fn, void *data,
return error_return;
}
-static int parse_unit_factor(const char *end, uintmax_t *val)
+static int parse_unit_factor(const char *end, uintmax_t *factor)
{
- if (!*end)
+ if (!*end) {
+ *factor = 1;
return 1;
+ }
else if (!strcasecmp(end, "k")) {
- *val *= 1024;
+ *factor = 1024;
return 1;
}
else if (!strcasecmp(end, "m")) {
- *val *= 1024 * 1024;
+ *factor = 1024 * 1024;
return 1;
}
else if (!strcasecmp(end, "g")) {
- *val *= 1024 * 1024 * 1024;
+ *factor = 1024 * 1024 * 1024;
return 1;
}
return 0;
@@ -859,7 +861,7 @@ static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max)
char *end;
intmax_t val;
uintmax_t uval;
- uintmax_t factor = 1;
+ uintmax_t factor;
errno = 0;
val = strtoimax(value, &end, 0);
@@ -888,7 +890,7 @@ static int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max)
if (value && *value) {
char *end;
uintmax_t val;
- uintmax_t factor = 1;
+ uintmax_t factor;
errno = 0;
val = strtoumax(value, &end, 0);