This function is just calling arg_strtou64() and then do extra UINT32_MAX check.
Signed-off-by: Qu Wenruo <[email protected]> --- utils-lib.c | 15 +++++++++++++++ utils.h | 1 + 2 files changed, 16 insertions(+) diff --git a/utils-lib.c b/utils-lib.c index 044f93fc..544f6750 100644 --- a/utils-lib.c +++ b/utils-lib.c @@ -44,6 +44,21 @@ u64 arg_strtou64(const char *str) } /* + * u32 version of arg_strtou*() + */ +u32 arg_strtou32(const char *str) +{ + u64 tmp; + + tmp = arg_strtou64(str); + if (tmp >= UINT32_MAX) { + fprintf(stderr, "ERROR: %s is too large.\n", str); + exit(1); + } + return (u32)tmp; +} + +/* * For a given: * - file or directory return the containing tree root id * - subvolume return its own tree id diff --git a/utils.h b/utils.h index 24d0a200..f6deb26c 100644 --- a/utils.h +++ b/utils.h @@ -94,6 +94,7 @@ const char *pretty_size_mode(u64 size, unsigned mode); u64 parse_size(char *s); u64 parse_qgroupid(const char *p); u64 arg_strtou64(const char *str); +u32 arg_strtou32(const char *str); int arg_copy_path(char *dest, const char *src, int destlen); int open_file_or_dir(const char *fname, DIR **dirstream); int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags); -- 2.12.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
