Added import of limits.h, revised overflow check, Redefined Return value for get_num_images
This commit is contained in:
parent
081bc3e096
commit
e011787bb1
|
@ -44,6 +44,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "windirent.h"
|
#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) {
|
if (strcmp(".", content->d_name) == 0 || strcmp("..", content->d_name) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
num_images++;
|
if (num_images == UINT_MAX) {
|
||||||
if (num_images == 0) {
|
|
||||||
fprintf(stderr, "Too many files in folder %s\n", imgdirpath);
|
fprintf(stderr, "Too many files in folder %s\n", imgdirpath);
|
||||||
}
|
}
|
||||||
|
num_images++;
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
return num_images;
|
return num_images;
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "windirent.h"
|
#include "windirent.h"
|
||||||
|
@ -160,7 +161,7 @@ typedef struct opj_decompress_params {
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* Declarations */
|
/* Declarations */
|
||||||
int get_num_images(char *imgdirpath);
|
unsigned int get_num_images(char *imgdirpath);
|
||||||
int load_images(dircnt_t *dirptr, char *imgdirpath);
|
int load_images(dircnt_t *dirptr, char *imgdirpath);
|
||||||
int get_file_format(const char *filename);
|
int get_file_format(const char *filename);
|
||||||
char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol,
|
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;
|
DIR *dir;
|
||||||
struct dirent* content;
|
struct dirent* content;
|
||||||
|
@ -388,10 +389,11 @@ int get_num_images(char *imgdirpath)
|
||||||
if (strcmp(".", content->d_name) == 0 || strcmp("..", content->d_name) == 0) {
|
if (strcmp(".", content->d_name) == 0 || strcmp("..", content->d_name) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
num_images++;
|
if (num_images == UINT_MAX) {
|
||||||
if (num_images == 0) {
|
|
||||||
fprintf(stderr, "Too many files in folder %s\n", imgdirpath);
|
fprintf(stderr, "Too many files in folder %s\n", imgdirpath);
|
||||||
}
|
}
|
||||||
|
num_images++;
|
||||||
|
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
return num_images;
|
return num_images;
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "windirent.h"
|
#include "windirent.h"
|
||||||
|
@ -82,7 +83,7 @@ typedef struct img_folder {
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* Declarations */
|
/* 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 load_images(dircnt_t *dirptr, char *imgdirpath);
|
||||||
static int get_file_format(const char *filename);
|
static int get_file_format(const char *filename);
|
||||||
static char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol,
|
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;
|
DIR *dir;
|
||||||
struct dirent* content;
|
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) {
|
if (strcmp(".", content->d_name) == 0 || strcmp("..", content->d_name) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
num_images++;
|
if (num_images == UINT_MAX) {
|
||||||
if (num_images == 0) {
|
|
||||||
fprintf(stderr, "Too many files in folder %s\n", imgdirpath);
|
fprintf(stderr, "Too many files in folder %s\n", imgdirpath);
|
||||||
}
|
}
|
||||||
|
num_images++;
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
return num_images;
|
return num_images;
|
||||||
|
|
Loading…
Reference in New Issue