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>

René Scharfe committed Jun 22, 2019 at 12:03 UTC 664178e8e23fbd6d79b02ea51374015023c02102
1 file changed +9 -7
config.c
+9 -7
@@ -834,20 +834,22 @@ static int git_parse_source(config_fn_t fn, void *data,
834 return error_return;
835 }
836
837 -static int parse_unit_factor(const char *end, uintmax_t *val)
837 +static int parse_unit_factor(const char *end, uintmax_t *factor)
838 {
839 - if (!*end)
839 + if (!*end) {
840 + *factor = 1;
841 return 1;
842 + }
843 else if (!strcasecmp(end, "k")) {
842 - *val *= 1024;
844 + *factor = 1024;
845 return 1;
846 }
847 else if (!strcasecmp(end, "m")) {
846 - *val *= 1024 * 1024;
848 + *factor = 1024 * 1024;
849 return 1;
850 }
851 else if (!strcasecmp(end, "g")) {
850 - *val *= 1024 * 1024 * 1024;
852 + *factor = 1024 * 1024 * 1024;
853 return 1;
854 }
855 return 0;
@@ -859,7 +861,7 @@ static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max)
861 char *end;
862 intmax_t val;
863 uintmax_t uval;
862 - uintmax_t factor = 1;
864 + uintmax_t factor;
865
866 errno = 0;
867 val = strtoimax(value, &end, 0);
@@ -888,7 +890,7 @@ static int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max)
890 if (value && *value) {
891 char *end;
892 uintmax_t val;
891 - uintmax_t factor = 1;
893 + uintmax_t factor;
894
895 errno = 0;
896 val = strtoumax(value, &end, 0);