Revised to casts, deleted all other changes

This commit is contained in:
Eharve14 2022-01-13 12:48:58 -05:00
parent 968cf54a95
commit efa9c7e76b
3 changed files with 4 additions and 20 deletions

View File

@ -1957,11 +1957,6 @@ int main(int argc, char **argv)
/* Read directory if necessary */ /* Read directory if necessary */
if (img_fol.set_imgdir == 1) { if (img_fol.set_imgdir == 1) {
num_images = get_num_images(img_fol.imgdirpath); num_images = get_num_images(img_fol.imgdirpath);
if(num_images > SIZE_MAX/(OPJ_PATH_LEN * sizeof(char)) || num_images < 0){
fprintf(stdout, "Max images exceeded\n");
ret = 0;
goto fin;
} else {
dirptr = (dircnt_t*)malloc(sizeof(dircnt_t)); dirptr = (dircnt_t*)malloc(sizeof(dircnt_t));
if (dirptr) { if (dirptr) {
dirptr->filename_buf = (char*)calloc(num_images, OPJ_PATH_LEN * sizeof( dirptr->filename_buf = (char*)calloc(num_images, OPJ_PATH_LEN * sizeof(
@ -1972,14 +1967,13 @@ int main(int argc, char **argv)
goto fin; goto fin;
} }
for (i = 0; i < num_images; i++) { for (i = 0; i < num_images; i++) {
dirptr->filename[i] = dirptr->filename_buf + i * OPJ_PATH_LEN; dirptr->filename[i] = dirptr->filename_buf + (size_t)i * OPJ_PATH_LEN;
} }
} }
if (load_images(dirptr, img_fol.imgdirpath) == 1) { if (load_images(dirptr, img_fol.imgdirpath) == 1) {
ret = 0; ret = 0;
goto fin; goto fin;
} }
}
if (num_images == 0) { if (num_images == 0) {
fprintf(stdout, "Folder is empty\n"); fprintf(stdout, "Folder is empty\n");
ret = 0; ret = 0;

View File

@ -1367,11 +1367,7 @@ int main(int argc, char **argv)
if (img_fol.set_imgdir == 1) { if (img_fol.set_imgdir == 1) {
int it_image; int it_image;
num_images = get_num_images(img_fol.imgdirpath); num_images = get_num_images(img_fol.imgdirpath);
if( num_images > SIZE_MAX/(sizeof(char)* OPJ_PATH_LEN) || num_images < 0){
fprintf(stderr, "Max number of images exceeded\n");
failed = 1;
goto fin;
} else {
dirptr = (dircnt_t*)calloc(1, sizeof(dircnt_t)); dirptr = (dircnt_t*)calloc(1, sizeof(dircnt_t));
if (!dirptr) { if (!dirptr) {
destroy_parameters(&parameters); destroy_parameters(&parameters);
@ -1391,14 +1387,13 @@ int main(int argc, char **argv)
goto fin; goto fin;
} }
for (it_image = 0; it_image < num_images; it_image++) { for (it_image = 0; it_image < num_images; it_image++) {
dirptr->filename[it_image] = dirptr->filename_buf + it_image * OPJ_PATH_LEN; dirptr->filename[it_image] = dirptr->filename_buf + (size_t)it_image * OPJ_PATH_LEN;
} }
if (load_images(dirptr, img_fol.imgdirpath) == 1) { if (load_images(dirptr, img_fol.imgdirpath) == 1) {
failed = 1; failed = 1;
goto fin; goto fin;
} }
}
if (num_images == 0) { if (num_images == 0) {
fprintf(stderr, "Folder is empty\n"); fprintf(stderr, "Folder is empty\n");
failed = 1; failed = 1;

View File

@ -516,10 +516,6 @@ int main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/* Stores at max 10 image file names*/ /* Stores at max 10 image file names*/
if(num_images> SIZE_MAX/(OPJ_PATH_LEN * sizeof(char)) || num_images < 0){
free(dirptr);
return EXIT_FAILURE;
}else{
dirptr->filename_buf = (char*) calloc((size_t) num_images, dirptr->filename_buf = (char*) calloc((size_t) num_images,
OPJ_PATH_LEN * sizeof(char)); OPJ_PATH_LEN * sizeof(char));
if (!dirptr->filename_buf) { if (!dirptr->filename_buf) {
@ -533,13 +529,12 @@ int main(int argc, char *argv[])
} }
for (it_image = 0; it_image < num_images; it_image++) { for (it_image = 0; it_image < num_images; it_image++) {
dirptr->filename[it_image] = dirptr->filename_buf + it_image * OPJ_PATH_LEN; dirptr->filename[it_image] = dirptr->filename_buf + (size_t)it_image * OPJ_PATH_LEN;
} }
if (load_images(dirptr, img_fol.imgdirpath) == 1) { if (load_images(dirptr, img_fol.imgdirpath) == 1) {
goto fails; goto fails;
} }
}
if (num_images == 0) { if (num_images == 0) {
fprintf(stdout, "Folder is empty\n"); fprintf(stdout, "Folder is empty\n");
goto fails; goto fails;