From e011787bb18cfa573e7f809302632f981927c295 Mon Sep 17 00:00:00 2001 From: Eharve14 <71228603+Eharve14@users.noreply.github.com> Date: Fri, 14 Jan 2022 15:23:36 -0500 Subject: [PATCH] Added import of limits.h, revised overflow check, Redefined Return value for get_num_images --- src/bin/jp2/opj_compress.c | 5 +++-- src/bin/jp2/opj_decompress.c | 10 ++++++---- src/bin/jp2/opj_dump.c | 9 +++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index b940d4e5..28d1815c 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -44,6 +44,7 @@ #include #include #include +#include #ifdef _WIN32 #include "windirent.h" @@ -485,10 +486,10 @@ static unsigned int get_num_images(char *imgdirpath) if (strcmp(".", content->d_name) == 0 || strcmp("..", content->d_name) == 0) { continue; } - num_images++; - if (num_images == 0) { + if (num_images == UINT_MAX) { fprintf(stderr, "Too many files in folder %s\n", imgdirpath); } + num_images++; } closedir(dir); return num_images; diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index 11e85012..eb0597a5 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -44,6 +44,7 @@ #include #include #include +#include #ifdef _WIN32 #include "windirent.h" @@ -160,7 +161,7 @@ typedef struct opj_decompress_params { /* -------------------------------------------------------------------------- */ /* Declarations */ -int get_num_images(char *imgdirpath); +unsigned int get_num_images(char *imgdirpath); int load_images(dircnt_t *dirptr, char *imgdirpath); int get_file_format(const char *filename); char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol, @@ -370,7 +371,7 @@ static OPJ_BOOL parse_precision(const char* option, /* -------------------------------------------------------------------------- */ -int get_num_images(char *imgdirpath) +unsigned int get_num_images(char *imgdirpath) { DIR *dir; struct dirent* content; @@ -388,10 +389,11 @@ int get_num_images(char *imgdirpath) if (strcmp(".", content->d_name) == 0 || strcmp("..", content->d_name) == 0) { continue; } - num_images++; - if (num_images == 0) { + if (num_images == UINT_MAX) { fprintf(stderr, "Too many files in folder %s\n", imgdirpath); } + num_images++; + } closedir(dir); return num_images; diff --git a/src/bin/jp2/opj_dump.c b/src/bin/jp2/opj_dump.c index 9489afad..fdead430 100644 --- a/src/bin/jp2/opj_dump.c +++ b/src/bin/jp2/opj_dump.c @@ -36,6 +36,7 @@ #include #include #include +#include #ifdef _WIN32 #include "windirent.h" @@ -82,7 +83,7 @@ typedef struct img_folder { /* -------------------------------------------------------------------------- */ /* Declarations */ -static int get_num_images(char *imgdirpath); +static unsigned int get_num_images(char *imgdirpath); static int load_images(dircnt_t *dirptr, char *imgdirpath); static int get_file_format(const char *filename); static char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol, @@ -122,7 +123,7 @@ static void decode_help_display(void) } /* -------------------------------------------------------------------------- */ -static int get_num_images(char *imgdirpath) +static unsigned int get_num_images(char *imgdirpath) { DIR *dir; struct dirent* content; @@ -140,10 +141,10 @@ static int get_num_images(char *imgdirpath) if (strcmp(".", content->d_name) == 0 || strcmp("..", content->d_name) == 0) { continue; } - num_images++; - if (num_images == 0) { + if (num_images == UINT_MAX) { fprintf(stderr, "Too many files in folder %s\n", imgdirpath); } + num_images++; } closedir(dir); return num_images;