Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cppcheck fix for openjp3d #742

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 51 additions & 11 deletions src/bin/jp3d/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
cmptparm.bigendian = 0;
} else {
fprintf(stdout, "[ERROR] Bad pgx header, please check input file\n");
fclose(f);
return NULL;
}

Expand Down Expand Up @@ -510,9 +511,9 @@ opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *para
/*fscanf(fimg, "Color Map%[ \t]%d%[ \n\t]Dimensions%[ \t]%d%[ \t]%d%[ \t]%d%[ \n\t]",temp,&color_space,temp,temp,&w,temp,&h,temp,&l,temp);*/
/*fscanf(fimg, "Resolution(mm)%[ \t]%d%[ \t]%d%[ \t]%d%[ \n\t]",temp,&subsampling_dx,temp,&subsampling_dy,temp,&subsampling_dz,temp);*/

#ifdef VERBOSE
fprintf(stdout, "[INFO] %d \t %d %d %d \t %3.2f %2.2f %2.2f \t %d \n",color_space,w,h,l,subsampling_dx,subsampling_dy,subsampling_dz,prec);
#endif
#ifdef VERBOSE
fprintf(stdout, "[INFO] %d \t %d %d %d \t %d %d %d \t %d \n",color_space,w,h,l,subsampling_dx,subsampling_dy,subsampling_dz,prec);
#endif
fclose(fimg);

/* initialize volume components */
Expand Down Expand Up @@ -562,6 +563,10 @@ opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *para
/*if (comp->prec <= 8) {
if (!comp->sgnd) {
unsigned char *data = (unsigned char *) malloc(whl * sizeof(unsigned char));
if(data == NULL){
fclose(f);
return NULL;
}
fread(data, 1, whl, f);
for (i = 0; i < whl; i++) {
comp->data[i] = data[i];
Expand All @@ -571,6 +576,10 @@ opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *para
free(data);
} else {
char *data = (char *) malloc(whl);
if(data == NULL){
fclose(f);
return NULL;
}
fread(data, 1, whl, f);
for (i = 0; i < whl; i++) {
comp->data[i] = data[i];
Expand All @@ -582,6 +591,10 @@ opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *para
} else if (comp->prec <= 16) {
if (!comp->sgnd) {
unsigned short *data = (unsigned short *) malloc(whl * sizeof(unsigned short));
if(data == NULL){
fclose(f);
return NULL;
}
int leido = fread(data, 2, whl, f);
if (!leido) {
free(data); fclose(f);
Expand All @@ -600,6 +613,10 @@ opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *para
free(data);
} else {
short *data = (short *) malloc(whl);
if(data == NULL){
fclose(f);
return NULL;
}
int leido = fread(data, 2, whl, f);
if (!leido) {
free(data); fclose(f);
Expand All @@ -619,6 +636,10 @@ opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *para
} else {
if (!comp->sgnd) {
unsigned int *data = (unsigned int *) malloc(whl * sizeof(unsigned int));
if(data == NULL){
fclose(f);
return NULL;
}
int leido = fread(data, 4, whl, f);
if (!leido) {
free(data); fclose(f);
Expand Down Expand Up @@ -687,13 +708,13 @@ int volumetobin(opj_volume_t * volume, char *outfile) {
/* char *imgtemp;*/
char name[256];

fdest = fopen(outfile, "wb");
if (!fdest) {
fprintf(stdout, "[ERROR] Failed to open %s for writing\n", outfile);
return 1;
}

for (compno = 0; compno < 1; compno++) { /*Only one component*/

fdest = fopen(outfile, "wb");
if (!fdest) {
fprintf(stdout, "[ERROR] Failed to open %s for writing\n", outfile);
return 1;
}
fprintf(stdout,"[INFO] Writing outfile %s (%s) \n",outfile, volume->comps[0].bigendian ? "Bigendian" : "Little-endian");

w = int_ceildiv(volume->x1 - volume->x0, volume->comps[compno].dx);
Expand Down Expand Up @@ -871,8 +892,7 @@ opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters) {
f = fopen(filename, "rb");
if (!f) {
fprintf(stderr, "[ERROR] Failed to open %s for reading !!\n", filename);
fclose(f);
return 0;
return NULL;
}

/* BINARY */
Expand All @@ -884,6 +904,10 @@ opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters) {
/*if (comp->prec <= 8) {
if (!comp->sgnd) {
unsigned char *data = (unsigned char *) malloc(whl * sizeof(unsigned char));
if(data == NULL){
fclose(f);
return NULL;
}
fread(data, 1, whl, f);
for (i = 0; i < whl; i++) {
comp->data[i] = data[i];
Expand All @@ -893,6 +917,10 @@ opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters) {
free(data);
} else {
char *data = (char *) malloc(whl);
if(data == NULL){
fclose(f);
return NULL;
}
fread(data, 1, whl, f);
for (i = 0; i < whl; i++) {
comp->data[i] = data[i];
Expand All @@ -904,6 +932,10 @@ opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters) {
} else if (comp->prec <= 16) {
if (!comp->sgnd) {
unsigned short *data = (unsigned short *) malloc(whl * sizeof(unsigned short));
if(data == NULL){
fclose(f);
return NULL;
}
int leido = fread(data, 2, whl, f);
if (!leido) {
free(data); fclose(f);
Expand All @@ -922,6 +954,10 @@ opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters) {
free(data);
} else {
short *data = (short *) malloc(whl);
if(data == NULL){
fclose(f);
return NULL;
}
int leido = fread(data, 2, whl, f);
if (!leido) {
free(data); fclose(f);
Expand All @@ -941,6 +977,10 @@ opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters) {
} else {
if (!comp->sgnd) {
unsigned int *data = (unsigned int *) malloc(whl * sizeof(unsigned int));
if(data == NULL){
fclose(f);
return NULL;
}
int leido = fread(data, 4, whl, f);
if (!leido) {
free(data); fclose(f);
Expand Down
8 changes: 6 additions & 2 deletions src/bin/jp3d/opj_jp3d_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
parameters->tcp_numlayers = numlayers;
matrix_width = parameters->numresolution[0] + parameters->numresolution[1] + parameters->numresolution[2];
parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int));
if(parameters->cp_matrice == NULL){
return 1;
}
s = s + 2;

for (i = 0; i < numlayers; i++) {
Expand Down Expand Up @@ -703,15 +706,15 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
return 1;
}

if (parameters->dcoffset >= 128 && parameters->dcoffset <= -128) {
if (parameters->dcoffset >= 128 || parameters->dcoffset <= -128) {
fprintf(stdout, "[ERROR] -D 'DC offset' argument error ! Value must be -128<=DCO<=128.\n");
return 1;
}

if(parameters->numresolution[2] != 1) {
parameters->transform_format = TRF_3D_DWT;
/*fprintf(stdout, "[Warning] Resolution level in axial dim > 1 : 3D-DWT will be performed... \n");*/
} else if (parameters->numresolution[2] == 1) {
} else {
parameters->transform_format = TRF_2D_DWT;
/*fprintf(stdout, "[Warning] Resolution level in axial dim == 1 : 2D-DWT will be performed... \n");*/
}
Expand Down Expand Up @@ -796,6 +799,7 @@ int main(int argc, char **argv) {

/* parse input and get user encoding parameters */
if(parse_cmdline_encoder(argc, argv, &parameters) == 1) {
if(parameters.cp_matrice) free(parameters.cp_matrice);
return 0;
}

Expand Down
5 changes: 5 additions & 0 deletions src/bin/jp3d/opj_jp3d_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ int main(int argc, char **argv) {
file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET);
src = (unsigned char *) malloc(file_length);
if(src == NULL){
fprintf(stderr, "opj_jp3d_decompress: memory out\n");
fclose(fsrc);
return 1;
}
fread(src, 1, file_length, fsrc);
fclose(fsrc);

Expand Down
Loading