* tools/raw2tiff.c (main): Fix Coverity 1024887 "Unchecked return
value from library". (guessSize): Fix Coverity 1024888 "Unchecked return value from library". (guessSize): Fix Coverity 1214162 "Ignoring number of bytes read". (guessSize): Fix Coverity 1024889 "Unchecked return value from library".
This commit is contained in:
parent
cf204cbace
commit
e18809068d
@ -1,5 +1,13 @@
|
||||
2015-05-30 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
|
||||
|
||||
* tools/raw2tiff.c (main): Fix Coverity 1024887 "Unchecked return
|
||||
value from library".
|
||||
(guessSize): Fix Coverity 1024888 "Unchecked return value from
|
||||
library".
|
||||
(guessSize): Fix Coverity 1214162 "Ignoring number of bytes read".
|
||||
(guessSize): Fix Coverity 1024889 "Unchecked return value from
|
||||
library".
|
||||
|
||||
* tools/tiff2pdf.c (t2p_readwrite_pdf_image): Fix Coverity 298621
|
||||
"Resource leak".
|
||||
(t2p_readwrite_pdf_image): Fix Coverity 1024181 "Structurally dead
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: raw2tiff.c,v 1.25 2010-03-10 18:56:49 bfriesen Exp $
|
||||
/* $Id: raw2tiff.c,v 1.26 2015-05-30 16:13:29 bfriesen Exp $
|
||||
*
|
||||
* Project: libtiff tools
|
||||
* Purpose: Convert raw byte sequences in TIFF images
|
||||
@ -286,9 +286,15 @@ main(int argc, char* argv[])
|
||||
switch(interleaving) {
|
||||
case BAND: /* band interleaved data */
|
||||
for (band = 0; band < nbands; band++) {
|
||||
lseek(fd,
|
||||
if (lseek(fd,
|
||||
hdr_size + (length*band+row)*linebytes,
|
||||
SEEK_SET);
|
||||
SEEK_SET) == (off_t)-1) {
|
||||
fprintf(stderr,
|
||||
"%s: %s: scanline %lu: seek error.\n",
|
||||
argv[0], argv[optind],
|
||||
(unsigned long) row);
|
||||
break;
|
||||
}
|
||||
if (read(fd, buf, linebytes) < 0) {
|
||||
fprintf(stderr,
|
||||
"%s: %s: scanline %lu: Read error.\n",
|
||||
@ -366,7 +372,10 @@ guessSize(int fd, TIFFDataType dtype, off_t hdr_size, uint32 nbands,
|
||||
uint32 depth = TIFFDataWidth(dtype);
|
||||
float cor_coef = 0, tmp;
|
||||
|
||||
fstat(fd, &filestat);
|
||||
if (fstat(fd, &filestat) == -1) {
|
||||
fprintf(stderr, "Failed to obtain file size.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (filestat.st_size < hdr_size) {
|
||||
fprintf(stderr, "Too large header size specified.\n");
|
||||
@ -394,6 +403,7 @@ guessSize(int fd, TIFFDataType dtype, off_t hdr_size, uint32 nbands,
|
||||
|
||||
return 1;
|
||||
} else if (*width == 0 && *length == 0) {
|
||||
unsigned int fail = 0;
|
||||
fprintf(stderr, "Image width and height are not specified.\n");
|
||||
|
||||
for (w = (uint32) sqrt(imagesize / longt);
|
||||
@ -404,10 +414,25 @@ guessSize(int fd, TIFFDataType dtype, off_t hdr_size, uint32 nbands,
|
||||
buf1 = _TIFFmalloc(scanlinesize);
|
||||
buf2 = _TIFFmalloc(scanlinesize);
|
||||
h = imagesize / w;
|
||||
lseek(fd, hdr_size + (int)(h/2)*scanlinesize,
|
||||
SEEK_SET);
|
||||
read(fd, buf1, scanlinesize);
|
||||
read(fd, buf2, scanlinesize);
|
||||
do {
|
||||
if (lseek(fd, hdr_size + (int)(h/2)*scanlinesize,
|
||||
SEEK_SET) == (off_t)-1) {
|
||||
fprintf(stderr, "seek error.\n");
|
||||
fail=1;
|
||||
break;
|
||||
}
|
||||
if (read(fd, buf1, scanlinesize) !=
|
||||
(long) scanlinesize) {
|
||||
fprintf(stderr, "read error.\n");
|
||||
fail=1;
|
||||
break;
|
||||
}
|
||||
if (read(fd, buf2, scanlinesize) !=
|
||||
(long) scanlinesize) {
|
||||
fprintf(stderr, "read error.\n");
|
||||
fail=1;
|
||||
break;
|
||||
}
|
||||
if (swab) {
|
||||
swapBytesInScanline(buf1, w, dtype);
|
||||
swapBytesInScanline(buf2, w, dtype);
|
||||
@ -418,12 +443,17 @@ guessSize(int fd, TIFFDataType dtype, off_t hdr_size, uint32 nbands,
|
||||
cor_coef = tmp;
|
||||
*width = w, *length = h;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
_TIFFfree(buf1);
|
||||
_TIFFfree(buf2);
|
||||
}
|
||||
}
|
||||
|
||||
if (fail) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(stderr,
|
||||
"Width is guessed as %lu, height is guessed as %lu.\n",
|
||||
(unsigned long)*width, (unsigned long)*length);
|
||||
|
Loading…
Reference in New Issue
Block a user