[PATCH] erofs-utils: mkfs: add missing `errno = 0` before strto[u]l

Gao Xiang hsiangkao at linux.alibaba.com
Fri Feb 14 14:06:29 AEDT 2025


strtoull(3) says:

```
Since strtoul() can legitimately return 0 or ULONG_MAX (ULLONG_MAX for
strtoull()) on both success and failure, the calling program should set
errno to 0 before the call, and then determine if an error occurred by
checking whether errno has a nonzero value after the call.
```

Othewise, `--workers=` could exit with `invalid worker number`.

Fixes: 7894301e1a80 ("erofs-utils: mkfs: add `--workers=#` parameter")
Fixes: 0132cb5ea7d0 ("erofs-utils: mkfs: add `--zfeature-bits` option")
Fixes: 7550a30c332c ("erofs-utils: enable incremental builds")
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 mkfs/main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mkfs/main.c b/mkfs/main.c
index a0fce35..9d6a0f2 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -817,6 +817,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 		case 520: {
 			unsigned int processors;
 
+			errno = 0;
 			cfg.c_mt_workers = strtoul(optarg, &endptr, 0);
 			if (errno || *endptr != '\0') {
 				erofs_err("invalid worker number %s", optarg);
@@ -831,6 +832,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 		}
 #endif
 		case 521:
+			errno = 0;
 			i = strtol(optarg, &endptr, 0);
 			if (errno || *endptr != '\0') {
 				erofs_err("invalid zfeature bits %s", optarg);
@@ -847,6 +849,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 			} else if (!strcmp(optarg, "rvsp")) {
 				dataimport_mode = EROFS_MKFS_DATA_IMPORT_RVSP;
 			} else {
+				errno = 0;
 				dataimport_mode = strtol(optarg, &endptr, 0);
 				if (errno || *endptr != '\0') {
 					erofs_err("invalid --%s=%s",
-- 
2.43.5



More information about the Linux-erofs mailing list