diff --git a/src/bin/jp2/convertbmp.c b/src/bin/jp2/convertbmp.c index 78ca4af5..910574b8 100644 --- a/src/bin/jp2/convertbmp.c +++ b/src/bin/jp2/convertbmp.c @@ -903,6 +903,10 @@ int imagetobmp(opj_image_t * image, const char *outfile) { <<-- <<-- <<-- <<-- */ fdest = fopen(outfile, "wb"); + if (!fdest) { + fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile); + return 1; + } w = (int)image->comps[0].w; h = (int)image->comps[0].h; diff --git a/src/bin/jp2/convertpng.c b/src/bin/jp2/convertpng.c index 5a72d9fe..0999edbf 100644 --- a/src/bin/jp2/convertpng.c +++ b/src/bin/jp2/convertpng.c @@ -486,7 +486,7 @@ fin: } fclose(writer); - if(fails) remove(write_idf); + if(fails) (void)remove(write_idf); /* ignore return value */ return fails; }/* imagetopng() */ diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index d3dc62ff..e5f98532 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -456,7 +456,7 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c if (parameters->decod_format == -1) return 1; sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename); - strncpy(parameters->infile, infilename, sizeof(infilename)); + strncpy(parameters->infile, infilename, sizeof(infilename) - 1U); /*Set output file*/ strcpy(temp_ofname,get_file_name(image_filename)); @@ -466,7 +466,7 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c } if(img_fol->set_out_format==1){ sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format); - strncpy(parameters->outfile, outfilename, sizeof(outfilename)); + strncpy(parameters->outfile, outfilename, sizeof(outfilename) - 1U); } return 0; } @@ -612,6 +612,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param substr2++; /* skip '@' character */ } substr1 = (char*) malloc((len+1)*sizeof(char)); + if (substr1 == NULL) { + return 1; + } memcpy(substr1,opj_optarg,len); substr1[len] = '\0'; if (sscanf(substr1, "%d,%d,%d,%d,%c", &width, &height, &ncomp, &bitdepth, &signo) == 5) { @@ -663,7 +666,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param } } } - if (substr1) free(substr1); + free(substr1); if (wrong) { fprintf(stderr,"\nError: invalid raw image parameters\n"); fprintf(stderr,"Please use the Format option -F:\n"); diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index da566ac2..bd755c82 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -1550,7 +1550,7 @@ int main(int argc, char **argv) /* destroy the codestream index */ opj_destroy_cstr_index(&cstr_index); - if(failed) remove(parameters.outfile); + if(failed) (void)remove(parameters.outfile); /* ignore return value */ } destroy_parameters(¶meters); if (numDecompressedImages) { diff --git a/src/bin/jp2/opj_dump.c b/src/bin/jp2/opj_dump.c index a85cfe90..4005f1c2 100644 --- a/src/bin/jp2/opj_dump.c +++ b/src/bin/jp2/opj_dump.c @@ -134,6 +134,7 @@ static int get_num_images(char *imgdirpath){ continue; num_images++; } + closedir(dir); return num_images; } @@ -160,6 +161,7 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){ strcpy(dirptr->filename[i],content->d_name); i++; } + closedir(dir); return 0; }