summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormayeut <mayeut@users.noreply.github.com>2016-04-30 01:50:33 +0200
committermayeut <mayeut@users.noreply.github.com>2016-04-30 01:50:33 +0200
commitf40a2ff2ad821cf6492761c01de136ac2bf48b4a (patch)
treef60b7c76700aaced3ca7d718c52a1c44b99066c1 /src
parentbe42e72d220ffa89b33c8d24d0c0d4c8de8533cf (diff)
Fix bad call to fclose with NULL pointer
Diffstat (limited to 'src')
-rw-r--r--src/bin/jp2/convert.c79
1 files changed, 39 insertions, 40 deletions
diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c
index 940ac2fa..c130b3bf 100644
--- a/src/bin/jp2/convert.c
+++ b/src/bin/jp2/convert.c
@@ -1762,7 +1762,7 @@ int imagetopnm(opj_image_t * image, const char *outfile, int force_split)
const char *tmp = outfile;
char *destname;
- alpha = NULL;
+ alpha = NULL;
if((prec = (int)image->comps[0].prec) > 16)
{
@@ -1842,7 +1842,7 @@ int imagetopnm(opj_image_t * image, const char *outfile, int force_split)
if(two)
{
v = *red + adjustR; ++red;
-if(v > 65535) v = 65535; else if(v < 0) v = 0;
+ if(v > 65535) v = 65535; else if(v < 0) v = 0;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
@@ -1850,13 +1850,13 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0;
if(triple)
{
v = *green + adjustG; ++green;
-if(v > 65535) v = 65535; else if(v < 0) v = 0;
+ if(v > 65535) v = 65535; else if(v < 0) v = 0;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
v = *blue + adjustB; ++blue;
-if(v > 65535) v = 65535; else if(v < 0) v = 0;
+ if(v > 65535) v = 65535; else if(v < 0) v = 0;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
@@ -1866,7 +1866,7 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0;
if(has_alpha)
{
v = *alpha + adjustA; ++alpha;
- if(v > 65535) v = 65535; else if(v < 0) v = 0;
+ if(v > 65535) v = 65535; else if(v < 0) v = 0;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
@@ -1876,28 +1876,28 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0;
} /* if(two) */
/* prec <= 8: */
- v = *red++;
- if(v > 255) v = 255; else if(v < 0) v = 0;
+ v = *red++;
+ if(v > 255) v = 255; else if(v < 0) v = 0;
- fprintf(fdest, "%c", (unsigned char)v);
+ fprintf(fdest, "%c", (unsigned char)v);
if(triple)
- {
- v = *green++;
- if(v > 255) v = 255; else if(v < 0) v = 0;
+ {
+ v = *green++;
+ if(v > 255) v = 255; else if(v < 0) v = 0;
- fprintf(fdest, "%c", (unsigned char)v);
- v = *blue++;
- if(v > 255) v = 255; else if(v < 0) v = 0;
+ fprintf(fdest, "%c", (unsigned char)v);
+ v = *blue++;
+ if(v > 255) v = 255; else if(v < 0) v = 0;
- fprintf(fdest, "%c", (unsigned char)v);
- }
+ fprintf(fdest, "%c", (unsigned char)v);
+ }
if(has_alpha)
- {
- v = *alpha++;
- if(v > 255) v = 255; else if(v < 0) v = 0;
+ {
+ v = *alpha++;
+ if(v > 255) v = 255; else if(v < 0) v = 0;
- fprintf(fdest, "%c", (unsigned char)v);
- }
+ fprintf(fdest, "%c", (unsigned char)v);
+ }
} /* for(i */
fclose(fdest); return 0;
@@ -1911,22 +1911,21 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0;
fprintf(stderr," is written to the file\n");
}
destname = (char*)malloc(strlen(outfile) + 8);
- if(destname == NULL){
- fprintf(stderr, "imagetopnm: memory out\n");
- fclose(fdest);
- return 1;
- }
+ if(destname == NULL){
+ fprintf(stderr, "imagetopnm: memory out\n");
+ return 1;
+ }
for (compno = 0; compno < ncomp; compno++)
{
- if (ncomp > 1)
- {
- /*sprintf(destname, "%d.%s", compno, outfile);*/
- const size_t olen = strlen(outfile);
- const size_t dotpos = olen - 4;
-
- strncpy(destname, outfile, dotpos);
- sprintf(destname+dotpos, "_%u.pgm", compno);
- }
+ if (ncomp > 1)
+ {
+ /*sprintf(destname, "%d.%s", compno, outfile);*/
+ const size_t olen = strlen(outfile);
+ const size_t dotpos = olen - 4;
+
+ strncpy(destname, outfile, dotpos);
+ sprintf(destname+dotpos, "_%u.pgm", compno);
+ }
else
sprintf(destname, "%s", outfile);
@@ -1953,7 +1952,7 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0;
for (i = 0; i < wr * hr; i++)
{
v = *red + adjustR; ++red;
-if(v > 65535) v = 65535; else if(v < 0) v = 0;
+ if(v > 65535) v = 65535; else if(v < 0) v = 0;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
@@ -1961,7 +1960,7 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0;
if(has_alpha)
{
v = *alpha++;
-if(v > 65535) v = 65535; else if(v < 0) v = 0;
+ if(v > 65535) v = 65535; else if(v < 0) v = 0;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
@@ -1972,10 +1971,10 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0;
{
for(i = 0; i < wr * hr; ++i)
{
- v = *red + adjustR; ++red;
- if(v > 255) v = 255; else if(v < 0) v = 0;
+ v = *red + adjustR; ++red;
+ if(v > 255) v = 255; else if(v < 0) v = 0;
- fprintf(fdest, "%c", (unsigned char)v);
+ fprintf(fdest, "%c", (unsigned char)v);
}
}
fclose(fdest);