diff --git a/.gitignore b/.gitignore index e096c24a..312f6426 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ a.out *.log *.trs +cov-int tmp tmp-* test/variables.sh diff --git a/libvips/arithmetic/arithmetic.c b/libvips/arithmetic/arithmetic.c index 0b6fe14d..6db74766 100644 --- a/libvips/arithmetic/arithmetic.c +++ b/libvips/arithmetic/arithmetic.c @@ -424,7 +424,7 @@ vips__formatalike( VipsImage *in1, VipsImage *in2, in[0] = in1; in[1] = in2; - if( vips__formatalike_vec( in, out, 2 ) ) + if( vips__formatalike_vec( in, &out[0], 2 ) ) return( -1 ); *out1 = out[0]; @@ -443,7 +443,7 @@ vips__sizealike( VipsImage *in1, VipsImage *in2, in[0] = in1; in[1] = in2; - if( vips__sizealike_vec( in, out, 2 ) ) + if( vips__sizealike_vec( in, &out[0], 2 ) ) return( -1 ); *out1 = out[0]; @@ -462,7 +462,7 @@ vips__bandalike( const char *domain, in[0] = in1; in[1] = in2; - if( vips__bandalike_vec( domain, in, out, 2, 1 ) ) + if( vips__bandalike_vec( domain, in, &out[0], 2, 1 ) ) return( -1 ); *out1 = out[0]; diff --git a/libvips/foreign/openslide2vips.c b/libvips/foreign/openslide2vips.c index 7a1258cf..42165ada 100644 --- a/libvips/foreign/openslide2vips.c +++ b/libvips/foreign/openslide2vips.c @@ -419,14 +419,12 @@ argb2rgba( uint32_t *buf, int n, uint32_t bg ) uint8_t a = x >> 24; VipsPel *out = (VipsPel *) p; - if( a == 255 ) { - *p = GUINT32_TO_BE((x << 8) | 255); - } - else if( a == 0 ) { + if( a == 255 ) + *p = GUINT32_TO_BE( (x << 8) | 255 ); + else if( a == 0 ) /* Use background color. */ - *p = GUINT32_TO_BE((bg << 8) | 255); - } + *p = GUINT32_TO_BE( (bg << 8) | 255 ); else { /* Undo premultiplication. */ diff --git a/libvips/foreign/radiance.c b/libvips/foreign/radiance.c index f72f2a23..a1bc4e55 100644 --- a/libvips/foreign/radiance.c +++ b/libvips/foreign/radiance.c @@ -974,7 +974,7 @@ rad2vips_process_line( char *line, Read *read ) read->aspect *= aspectval( line ); } else if( isprims( line ) ) { - primsval( read->prims, line ); + (void) primsval( read->prims, line ); } return( 0 ); diff --git a/libvips/foreign/tiff2vips.c b/libvips/foreign/tiff2vips.c index 432ee1ce..b1a24127 100644 --- a/libvips/foreign/tiff2vips.c +++ b/libvips/foreign/tiff2vips.c @@ -1110,14 +1110,16 @@ parse_header( ReadTiff *rtiff, VipsImage *out ) { uint16 v; - TIFFGetFieldDefaulted( rtiff->tiff, TIFFTAG_SAMPLEFORMAT, &v ); + rtiff->sample_format = SAMPLEFORMAT_INT; - /* Some images have this set to void, bizarre. - */ - if( v == SAMPLEFORMAT_VOID ) - v = SAMPLEFORMAT_UINT; + if( TIFFGetFieldDefaulted( rtiff->tiff, TIFFTAG_SAMPLEFORMAT, &v ) ) { + /* Some images have this set to void, bizarre. + */ + if( v == SAMPLEFORMAT_VOID ) + v = SAMPLEFORMAT_UINT; - rtiff->sample_format = v; + rtiff->sample_format = v; + } } /* Arbitrary sanity-checking limits. diff --git a/libvips/foreign/vips2jpeg.c b/libvips/foreign/vips2jpeg.c index 4eb0e66d..10bae518 100644 --- a/libvips/foreign/vips2jpeg.c +++ b/libvips/foreign/vips2jpeg.c @@ -427,7 +427,7 @@ typedef void (*write_fn)( ExifData *ed, /* Write a tag. Update what's there, or make a new one. */ -static int +static void write_tag( ExifData *ed, int ifd, ExifTag tag, write_fn fn, void *data ) { ExifEntry *entry; @@ -448,8 +448,6 @@ write_tag( ExifData *ed, int ifd, ExifTag tag, write_fn fn, void *data ) fn( ed, entry, 0, data ); } - - return( 0 ); } /* This is different, we set the xres/yres from the vips header rather than @@ -501,16 +499,12 @@ set_exif_resolution( ExifData *ed, VipsImage *im ) /* Main image xres/yres/unit are in ifd0. ifd1 has the thumbnail * xres/yres/unit. */ - if( write_tag( ed, 0, EXIF_TAG_X_RESOLUTION, - vips_exif_set_double, (void *) &xres ) || - write_tag( ed, 0, EXIF_TAG_Y_RESOLUTION, - vips_exif_set_double, (void *) &yres ) || - write_tag( ed, 0, EXIF_TAG_RESOLUTION_UNIT, - vips_exif_set_int, (void *) &unit ) ) { - vips_error( "VipsJpeg", - "%s", _( "error setting JPEG resolution" ) ); - return( -1 ); - } + write_tag( ed, 0, EXIF_TAG_X_RESOLUTION, + vips_exif_set_double, (void *) &xres ); + write_tag( ed, 0, EXIF_TAG_Y_RESOLUTION, + vips_exif_set_double, (void *) &yres ); + write_tag( ed, 0, EXIF_TAG_RESOLUTION_UNIT, + vips_exif_set_int, (void *) &unit ); return( 0 ); } @@ -523,14 +517,10 @@ set_exif_dimensions( ExifData *ed, VipsImage *im ) VIPS_DEBUG_MSG( "set_exif_dimensions: vips size of %d, %d\n", im->Xsize, im->Ysize ); - if( write_tag( ed, 2, EXIF_TAG_PIXEL_X_DIMENSION, - vips_exif_set_int, (void *) &im->Xsize ) || - write_tag( ed, 2, EXIF_TAG_PIXEL_Y_DIMENSION, - vips_exif_set_int, (void *) &im->Ysize ) ) { - vips_error( "VipsJpeg", - "%s", _( "error setting JPEG dimensions" ) ); - return( -1 ); - } + write_tag( ed, 2, EXIF_TAG_PIXEL_X_DIMENSION, + vips_exif_set_int, (void *) &im->Xsize ); + write_tag( ed, 2, EXIF_TAG_PIXEL_Y_DIMENSION, + vips_exif_set_int, (void *) &im->Ysize ); return( 0 ); } @@ -1324,10 +1314,15 @@ term_destination( j_compress_ptr cinfo ) */ if( !(obuf = vips_malloc( NULL, len )) ) ERREXIT( cinfo, JERR_FILE_WRITE ); - *(buf->obuf) = obuf; - *(buf->olen) = len; + else { + /* coverity doesn't know ERREXIT() does not return, so put + * this in an else. + */ + *(buf->obuf) = obuf; + *(buf->olen) = len; - block_copy( buf->block, obuf ); + block_copy( buf->block, obuf ); + } } /* Set dest to one of our objects. diff --git a/libvips/foreign/webp2vips.c b/libvips/foreign/webp2vips.c index 1975df42..590ef38f 100644 --- a/libvips/foreign/webp2vips.c +++ b/libvips/foreign/webp2vips.c @@ -151,7 +151,7 @@ read_new( const char *filename, void *data, size_t length ) * * mmap the input file, it's slightly quicker. */ - if( !(read->fd = vips__open_image_read( read->filename )) || + if( (read->fd = vips__open_image_read( read->filename )) < 0 || (read->length = vips_file_length( read->fd )) < 0 || !(read->data = vips__mmap( read->fd, FALSE, read->length, 0 )) ) { diff --git a/libvips/iofuncs/buf.c b/libvips/iofuncs/buf.c index d575085f..a067c158 100644 --- a/libvips/iofuncs/buf.c +++ b/libvips/iofuncs/buf.c @@ -528,19 +528,19 @@ vips_buf_append_size( VipsBuf *buf, size_t n ) */ N_( "bytes" ), - /* Kilo byte unit. + /* Kilobyte unit. */ N_( "KB" ), - /* Mega byte unit. + /* Megabyte unit. */ N_( "MB" ), - /* Giga byte unit. + /* Gigabyte unit. */ N_( "GB" ), - /* Tera byte unit. + /* Terabyte unit. */ N_( "TB" ) }; @@ -548,14 +548,16 @@ vips_buf_append_size( VipsBuf *buf, size_t n ) double sz = n; int i; - for( i = 0; sz > 1024 && i < VIPS_NUMBER( names ); sz /= 1024, i++ ) + /* -1, since we want to stop at TB, not run off the end. + */ + for( i = 0; sz > 1024 && i < VIPS_NUMBER( names ) - 1; sz /= 1024, i++ ) ; if( i == 0 ) /* No decimal places for bytes. */ return( vips_buf_appendf( buf, "%g %s", sz, _( names[i] ) ) ); - else + else return( vips_buf_appendf( buf, "%.2f %s", sz, _( names[i] ) ) ); } diff --git a/libvips/iofuncs/header.c b/libvips/iofuncs/header.c index 105b5cef..db76dfd8 100644 --- a/libvips/iofuncs/header.c +++ b/libvips/iofuncs/header.c @@ -1503,30 +1503,29 @@ int vips_image_history_printf( VipsImage *image, const char *fmt, ... ) { va_list args; - char line[VIPS_PATH_MAX]; + char str[VIPS_PATH_MAX]; + VipsBuf buf = VIPS_BUF_STATIC( str ); time_t timebuf; - /* Format command. -40, to leave 26 for the ctime, three for the # and - * a bit. - */ va_start( args, fmt ); - (void) vips_vsnprintf( line, VIPS_PATH_MAX - 40, fmt, args ); + (void) vips_buf_vappendf( &buf, fmt, args ); va_end( args ); - strcat( line, " # " ); + vips_buf_appends( &buf, " # " ); /* Add the date. ctime always attaches a '\n', gah. */ time( &timebuf ); - strcat( line, ctime( &timebuf ) ); - line[strlen( line ) - 1] = '\0'; + vips_buf_appends( &buf, ctime( &timebuf ) ); + vips_buf_removec( &buf, '\n' ); #ifdef DEBUG printf( "vips_image_history_printf: " - "adding:\n\t%s\nto history on image %p\n", line, image ); + "adding:\n\t%s\nto history on image %p\n", + vips_buf_all( &buf ), image ); #endif /*DEBUG*/ image->history_list = g_slist_append( image->history_list, - vips__gvalue_ref_string_new( line ) ); + vips__gvalue_ref_string_new( vips_buf_all( &buf ) ) ); return( 0 ); } diff --git a/libvips/iofuncs/region.c b/libvips/iofuncs/region.c index 52c11908..aad8f3bf 100644 --- a/libvips/iofuncs/region.c +++ b/libvips/iofuncs/region.c @@ -363,7 +363,7 @@ vips_region_sanity( VipsObject *object, VipsBuf *buf ) { VipsRegion *region = VIPS_REGION( object ); - vips_object_sanity( VIPS_OBJECT( region->im ) ); + (void) vips_object_sanity( VIPS_OBJECT( region->im ) ); switch( region->im->dtype ) { case VIPS_IMAGE_PARTIAL: diff --git a/libvips/iofuncs/util.c b/libvips/iofuncs/util.c index 15d380b2..69686d33 100644 --- a/libvips/iofuncs/util.c +++ b/libvips/iofuncs/util.c @@ -1688,6 +1688,7 @@ vips__substitute( char *buf, size_t len, char *sub ) n = atoi( p + 1 ); if( lowest_n == -1 || n < lowest_n ) { + lowest_n = n; sub_start = p; sub_end = q + 1; } diff --git a/libvips/mosaicing/im_initialize.c b/libvips/mosaicing/im_initialize.c index d4eda738..0b57e319 100644 --- a/libvips/mosaicing/im_initialize.c +++ b/libvips/mosaicing/im_initialize.c @@ -74,9 +74,14 @@ im__initialize( TIE_POINTS *points ) ++j; } - xdelta = xdelta/j; - ydelta = ydelta/j; - for(i = 0; i < npt; i++ ) { + if( j == 0 ) { + vips_error( "im_initialize", "no tie points" ); + return( -1 ); + } + + xdelta = xdelta / j; + ydelta = ydelta / j; + for( i = 0; i < npt; i++ ) { dx[i] = (xsec[i] - xref[i]) - xdelta; dy[i] = (ysec[i] - yref[i]) - ydelta; } @@ -84,7 +89,7 @@ im__initialize( TIE_POINTS *points ) for( i = 0; i < npt; i++ ) { a1 = dx[i]; a2 = dy[i]; - points->deviation[i] = sqrt( a1*a1 + a2*a2 ); + points->deviation[i] = sqrt( a1 * a1 + a2 * a2 ); } points->l_scale = 1.0; diff --git a/libvips/resample/affine.c b/libvips/resample/affine.c index 564e159a..6274ceb4 100644 --- a/libvips/resample/affine.c +++ b/libvips/resample/affine.c @@ -430,6 +430,12 @@ vips_affine_build( VipsObject *object ) "interpolate", interpolate, NULL ); g_object_unref( interpolate ); + + /* coverity gets confused by this, it thinks + * affine->interpolate may still be null. Assign ourselves, + * even though we don't need to. + */ + affine->interpolate = interpolate; } in = resample->in; @@ -492,7 +498,7 @@ vips_affine_build( VipsObject *object ) /* Check for coordinate overflow ... we want to be able to hold the * output space inside INT_MAX / TRANSFORM_SCALE. */ - edge = INT_MAX / VIPS_TRANSFORM_SCALE; + edge = (int) (INT_MAX / VIPS_TRANSFORM_SCALE); if( affine->trn.oarea.left < -edge || affine->trn.oarea.top < -edge || VIPS_RECT_RIGHT( &affine->trn.oarea ) > edge ||