Skip to content

Commit 664178e

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3fb72c7 commit 664178e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

config.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -834,20 +834,22 @@ static int git_parse_source(config_fn_t fn, void *data,
834834
return error_return;
835835
}
836836

837-
static int parse_unit_factor(const char *end, uintmax_t *val)
837+
static int parse_unit_factor(const char *end, uintmax_t *factor)
838838
{
839-
if (!*end)
839+
if (!*end) {
840+
*factor = 1;
840841
return 1;
842+
}
841843
else if (!strcasecmp(end, "k")) {
842-
*val *= 1024;
844+
*factor = 1024;
843845
return 1;
844846
}
845847
else if (!strcasecmp(end, "m")) {
846-
*val *= 1024 * 1024;
848+
*factor = 1024 * 1024;
847849
return 1;
848850
}
849851
else if (!strcasecmp(end, "g")) {
850-
*val *= 1024 * 1024 * 1024;
852+
*factor = 1024 * 1024 * 1024;
851853
return 1;
852854
}
853855
return 0;
@@ -859,7 +861,7 @@ static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max)
859861
char *end;
860862
intmax_t val;
861863
uintmax_t uval;
862-
uintmax_t factor = 1;
864+
uintmax_t factor;
863865

864866
errno = 0;
865867
val = strtoimax(value, &end, 0);
@@ -888,7 +890,7 @@ static int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max)
888890
if (value && *value) {
889891
char *end;
890892
uintmax_t val;
891-
uintmax_t factor = 1;
893+
uintmax_t factor;
892894

893895
errno = 0;
894896
val = strtoumax(value, &end, 0);

0 commit comments

Comments
 (0)