aboutsummaryrefslogtreecommitdiff
path: root/bin/gensquashfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-07-01 12:41:56 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-07-03 00:57:06 +0200
commita64417804f4c2b0425e167851d10854cf1f23e99 (patch)
tree663cbafb8f30df0d82a289c69a4ace43656bd154 /bin/gensquashfs
parenta201669daff7e64255148404a27bed6c0df1eaa4 (diff)
Consolidate some of the stray integer parsers
There are several ad-hoc int/uint parsers scattered around the code, add a single helper function for that task and replace the multiple instances. A simple white-box test case is added for the utility function. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/gensquashfs')
-rw-r--r--bin/gensquashfs/src/sort_by_file.c28
1 files changed, 6 insertions, 22 deletions
diff --git a/bin/gensquashfs/src/sort_by_file.c b/bin/gensquashfs/src/sort_by_file.c
index f543767..1ca5aa7 100644
--- a/bin/gensquashfs/src/sort_by_file.c
+++ b/bin/gensquashfs/src/sort_by_file.c
@@ -9,27 +9,14 @@
static int decode_priority(const char *filename, size_t line_no,
char *line, sqfs_s64 *priority)
{
- bool negative = false;
- size_t i = 0;
+ size_t i;
+ int ret;
- if (line[0] == '-') {
- negative = true;
- i = 1;
- }
-
- if (!isdigit(line[i]))
+ ret = parse_int(line, strlen(line), &i, 0, 0, priority);
+ if (ret == SQFS_ERROR_CORRUPTED)
goto fail_number;
-
- *priority = 0;
-
- for (; isdigit(line[i]); ++i) {
- sqfs_s64 x = line[i] - '0';
-
- if ((*priority) >= ((0x7FFFFFFFFFFFFFFFL - x) / 10L))
- goto fail_ov;
-
- (*priority) = (*priority) * 10 + x;
- }
+ if (ret != 0)
+ goto fail_ov;
if (!isspace(line[i]))
goto fail_filename;
@@ -40,9 +27,6 @@ static int decode_priority(const char *filename, size_t line_no,
if (line[i] == '\0')
goto fail_filename;
- if (negative)
- (*priority) = -(*priority);
-
memmove(line, line + i, strlen(line + i) + 1);
return 0;
fail_number: