diff mbox series

[4/7] Use strtoumax instead of strtoull.

Message ID 20200518100356.29292-4-dtucker@dtucker.net (mailing list archive)
State New, archived
Headers show
Series [1/7] Redirect grep's stderr top null too. | expand

Commit Message

Darren Tucker May 18, 2020, 10:03 a.m. UTC
strtoumax is in the compat library so this works on platforms that don't
have a native strtoull.

Signed-off-by: Darren Tucker <dtucker@dtucker.net>
---
 t/helper/test-progress.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Junio C Hamano May 18, 2020, 6:29 p.m. UTC | #1
Darren Tucker <dtucker@dtucker.net> writes:

> strtoumax is in the compat library so this works on platforms that don't
> have a native strtoull.

The above description (even though is a good one) alone would leave
the reader wondering if this patch now has removed the last use of
strtoull(), removing the need to have NO_STRTOULL in the Makefile
and configure.ac, and also wonder why the patch does not touch
Makefile etc.  Something like

	We still use strtoull() as a part of the compatibility
	implementation of strtoumax(), so we cannot remove the
	support to detect/configure the use of the function in the
	Makefile and autoconf, though.

may deserve to be made into the second paragraph that follows the
above description.

Shouldn't the type of some variables in the codepath also be changed
to make sure we receive the return value from the function in a
variable that is large enough?

Thanks.

> Signed-off-by: Darren Tucker <dtucker@dtucker.net>
> ---
>  t/helper/test-progress.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c
> index 5d05cbe789..3e9eb2abe3 100644
> --- a/t/helper/test-progress.c
> +++ b/t/helper/test-progress.c
> @@ -47,7 +47,7 @@ int cmd__progress(int argc, const char **argv)
>  		char *end;
>  
>  		if (skip_prefix(line.buf, "progress ", (const char **) &end)) {
> -			uint64_t item_count = strtoull(end, &end, 10);
> +			uint64_t item_count = strtoumax(end, &end, 10);
>  			if (*end != '\0')
>  				die("invalid input: '%s'\n", line.buf);
>  			display_progress(progress, item_count);
> @@ -55,10 +55,10 @@ int cmd__progress(int argc, const char **argv)
>  				       (const char **) &end)) {
>  			uint64_t byte_count, test_ms;
>  
> -			byte_count = strtoull(end, &end, 10);
> +			byte_count = strtoumax(end, &end, 10);
>  			if (*end != ' ')
>  				die("invalid input: '%s'\n", line.buf);
> -			test_ms = strtoull(end + 1, &end, 10);
> +			test_ms = strtoumax(end + 1, &end, 10);
>  			if (*end != '\0')
>  				die("invalid input: '%s'\n", line.buf);
>  			progress_test_ns = test_ms * 1000 * 1000;
diff mbox series

Patch

diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c
index 5d05cbe789..3e9eb2abe3 100644
--- a/t/helper/test-progress.c
+++ b/t/helper/test-progress.c
@@ -47,7 +47,7 @@  int cmd__progress(int argc, const char **argv)
 		char *end;
 
 		if (skip_prefix(line.buf, "progress ", (const char **) &end)) {
-			uint64_t item_count = strtoull(end, &end, 10);
+			uint64_t item_count = strtoumax(end, &end, 10);
 			if (*end != '\0')
 				die("invalid input: '%s'\n", line.buf);
 			display_progress(progress, item_count);
@@ -55,10 +55,10 @@  int cmd__progress(int argc, const char **argv)
 				       (const char **) &end)) {
 			uint64_t byte_count, test_ms;
 
-			byte_count = strtoull(end, &end, 10);
+			byte_count = strtoumax(end, &end, 10);
 			if (*end != ' ')
 				die("invalid input: '%s'\n", line.buf);
-			test_ms = strtoull(end + 1, &end, 10);
+			test_ms = strtoumax(end + 1, &end, 10);
 			if (*end != '\0')
 				die("invalid input: '%s'\n", line.buf);
 			progress_test_ns = test_ms * 1000 * 1000;