Skip to contentSkip to conversation

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

PATCH New Gao Xiang 1 participant 1 message Feb 14, 2025

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

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

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")
---
 mkfs/main.c | 3 +++
 1 file changed, 3 insertions(+)
mkfs/main.c +3 -0
index a0fce35..9d6a0f2 100644
@@ -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",
Signature · 1 line
2.43.5