btrfs-progs: reset errno before strtoull()

strtoull may return the boundary values, if the callers could expect
that and verify it then the errno must be reset before the call.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2023-12-01 02:10:23 +01:00
parent e9a66cde91
commit a0468efe86
2 changed files with 3 additions and 0 deletions

View File

@ -158,6 +158,7 @@ u64 parse_size_from_string(const char *s)
error("size value '%s' is less equal than 0", s);
exit(1);
}
errno = 0;
ret = strtoull(s, &endptr, 10);
if (endptr == s) {
error("size value '%s' is invalid", s);

View File

@ -108,6 +108,7 @@ int sysfs_read_file_u64(const char *name, u64 *value)
if (ret < 0)
goto out;
/* Raw value in any numeric format should work, followed by a newline. */
errno = 0;
*value = strtoull(str, NULL, 0);
out:
close(fd);
@ -127,6 +128,7 @@ int sysfs_read_fsid_file_u64(int fd, const char *name, u64 *value)
if (ret < 0)
goto out;
/* Raw value in any numeric format should work, followed by a newline. */
errno = 0;
*value = strtoull(str, NULL, 0);
out:
close(fd);