gif: move fopen down to avoid possible FILE leak, props Andre Maute

This commit is contained in:
gitlost 2020-12-17 17:18:43 +00:00
parent 3e93968781
commit acdfc73cce

View File

@ -310,22 +310,6 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
lzwoutbuf = (char *) _alloca(lzoutbufSize); lzwoutbuf = (char *) _alloca(lzoutbufSize);
#endif /* _MSC_VER */ #endif /* _MSC_VER */
/* Open output file in binary mode */
if ((symbol->output_options & BARCODE_STDOUT) != 0) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
strcpy(symbol->errtxt, "610: Can't open output file");
return ZINT_ERROR_FILE_ACCESS;
}
#endif
gif_file = stdout;
} else {
if (!(gif_file = fopen(symbol->outfile, "wb"))) {
strcpy(symbol->errtxt, "611: Can't open output file");
return ZINT_ERROR_FILE_ACCESS;
}
}
/* /*
* Build a table of the used palette items. * Build a table of the used palette items.
* Currently, there are the following 10 colour codes: * Currently, there are the following 10 colour codes:
@ -481,6 +465,22 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
/* palette size 2 ^ bit size */ /* palette size 2 ^ bit size */
paletteSize = 1<<paletteBitSize; paletteSize = 1<<paletteBitSize;
/* Open output file in binary mode */
if ((symbol->output_options & BARCODE_STDOUT) != 0) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
strcpy(symbol->errtxt, "610: Can't open output file");
return ZINT_ERROR_FILE_ACCESS;
}
#endif
gif_file = stdout;
} else {
if (!(gif_file = fopen(symbol->outfile, "wb"))) {
strcpy(symbol->errtxt, "611: Can't open output file");
return ZINT_ERROR_FILE_ACCESS;
}
}
/* GIF signature (6) */ /* GIF signature (6) */
memcpy(outbuf, "GIF87a", 6); memcpy(outbuf, "GIF87a", 6);
if (transparent_index != -1) if (transparent_index != -1)