git: 06758ab1340e - main - Use expand_number(3) for less confusing argument processing

From: Poul-Henning Kamp <phk_at_FreeBSD.org>
Date: Thu, 08 Aug 2024 21:23:16 UTC
The branch main has been updated by phk:

URL: https://cgit.FreeBSD.org/src/commit/?id=06758ab1340e652930b573f8fd3d858f064d9204

commit 06758ab1340e652930b573f8fd3d858f064d9204
Author:     Poul-Henning Kamp <phk@FreeBSD.org>
AuthorDate: 2024-08-08 21:22:39 +0000
Commit:     Poul-Henning Kamp <phk@FreeBSD.org>
CommitDate: 2024-08-08 21:22:39 +0000

    Use expand_number(3) for less confusing argument processing
---
 usr.bin/tcopy/Makefile |  1 +
 usr.bin/tcopy/tcopy.c  | 10 ++++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/usr.bin/tcopy/Makefile b/usr.bin/tcopy/Makefile
index 86eb0dd42165..73dcd45b2e0f 100644
--- a/usr.bin/tcopy/Makefile
+++ b/usr.bin/tcopy/Makefile
@@ -1,3 +1,4 @@
 PROG=	tcopy
+LIBADD=      util
 
 .include <bsd.prog.mk>
diff --git a/usr.bin/tcopy/tcopy.c b/usr.bin/tcopy/tcopy.c
index aa39bce77845..39eae4126324 100644
--- a/usr.bin/tcopy/tcopy.c
+++ b/usr.bin/tcopy/tcopy.c
@@ -37,6 +37,7 @@
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <libutil.h>
 #include <paths.h>
 #include <sys/sysctl.h>
 #include <signal.h>
@@ -71,6 +72,7 @@ main(int argc, char *argv[])
 	const char *inf;
 	unsigned long maxphys = 0;
 	size_t l_maxphys = sizeof maxphys;
+	uint64_t tmp;
 
 	if (!sysctlbyname("kern.maxphys", &maxphys, &l_maxphys, NULL, 0))
 		maxblk = maxphys;
@@ -84,8 +86,12 @@ main(int argc, char *argv[])
 			op = COPYVERIFY;
 			break;
 		case 's':
-			maxblk = atoi(optarg);
-			if (maxblk <= 0) {
+			if (expand_number(optarg, &tmp)) {
+				warnx("illegal block size");
+				usage();
+			}
+			maxblk = tmp;
+			if (maxblk == 0) {
 				warnx("illegal block size");
 				usage();
 			}