From b140c18a37f46d72908dcd9436acfaaaf7a9ba57 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 20 Jan 2017 08:55:13 +0000 Subject: [PATCH] various tweaks to calm coverity passes cleanly now --- TODO | 2 ++ cplusplus/VImage.cpp | 60 ++++++++++++++++---------------- cplusplus/include/vips/VImage8.h | 60 ++++++++++++++++---------------- libvips/foreign/dzsave.c | 3 +- libvips/iofuncs/header.c | 2 +- libvips/resample/mapim.c | 27 ++++++++++++-- libvips/resample/shrinkh.c | 2 +- libvips/resample/shrinkv.c | 2 +- 8 files changed, 91 insertions(+), 67 deletions(-) diff --git a/TODO b/TODO index 715f4c8f..c08a6abc 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,5 @@ +- seem to be leaking VipsReorder + - not sure about utf8 error messages on win - strange: diff --git a/cplusplus/VImage.cpp b/cplusplus/VImage.cpp index a1905441..e617b3f7 100644 --- a/cplusplus/VImage.cpp +++ b/cplusplus/VImage.cpp @@ -770,19 +770,19 @@ operator+( VImage a, std::vector b ) } VImage & -operator+=( VImage a, const VImage b ) +operator+=( VImage &a, const VImage b ) { return( a = a + b ); } VImage & -operator+=( VImage a, const double b ) +operator+=( VImage &a, const double b ) { return( a = a + b ); } VImage & -operator+=( VImage a, std::vector b ) +operator+=( VImage &a, std::vector b ) { return( a = a + b ); } @@ -818,19 +818,19 @@ operator-( VImage a, std::vector b ) } VImage & -operator-=( VImage a, const VImage b ) +operator-=( VImage &a, const VImage b ) { return( a = a - b ); } VImage & -operator-=( VImage a, const double b ) +operator-=( VImage &a, const double b ) { return( a = a - b ); } VImage & -operator-=( VImage a, std::vector b ) +operator-=( VImage &a, std::vector b ) { return( a = a - b ); } @@ -872,19 +872,19 @@ operator*( VImage a, std::vector b ) } VImage & -operator*=( VImage a, const VImage b ) +operator*=( VImage &a, const VImage b ) { return( a = a * b ); } VImage & -operator*=( VImage a, const double b ) +operator*=( VImage &a, const double b ) { return( a = a * b ); } VImage & -operator*=( VImage a, std::vector b ) +operator*=( VImage &a, std::vector b ) { return( a = a * b ); } @@ -920,19 +920,19 @@ operator/( VImage a, std::vector b ) } VImage & -operator/=( VImage a, const VImage b ) +operator/=( VImage &a, const VImage b ) { return( a = a / b ); } VImage & -operator/=( VImage a, const double b ) +operator/=( VImage &a, const double b ) { return( a = a / b ); } VImage & -operator/=( VImage a, std::vector b ) +operator/=( VImage &a, std::vector b ) { return( a = a / b ); } @@ -956,19 +956,19 @@ operator%( VImage a, std::vector b ) } VImage & -operator%=( VImage a, const VImage b ) +operator%=( VImage &a, const VImage b ) { return( a = a % b ); } VImage & -operator%=( VImage a, const double b ) +operator%=( VImage &a, const double b ) { return( a = a % b ); } VImage & -operator%=( VImage a, std::vector b ) +operator%=( VImage &a, std::vector b ) { return( a = a % b ); } @@ -1210,19 +1210,19 @@ operator&( VImage a, std::vector b ) } VImage & -operator&=( VImage a, const VImage b ) +operator&=( VImage &a, const VImage b ) { return( a = a & b ); } VImage & -operator&=( VImage a, const double b ) +operator&=( VImage &a, const double b ) { return( a = a & b ); } VImage & -operator&=( VImage a, std::vector b ) +operator&=( VImage &a, std::vector b ) { return( a = a & b ); } @@ -1260,19 +1260,19 @@ operator|( VImage a, std::vector b ) } VImage & -operator|=( VImage a, const VImage b ) +operator|=( VImage &a, const VImage b ) { return( a = a | b ); } VImage & -operator|=( VImage a, const double b ) +operator|=( VImage &a, const double b ) { return( a = a | b ); } VImage & -operator|=( VImage a, std::vector b ) +operator|=( VImage &a, std::vector b ) { return( a = a | b ); } @@ -1310,19 +1310,19 @@ operator^( VImage a, std::vector b ) } VImage & -operator^=( VImage a, const VImage b ) +operator^=( VImage &a, const VImage b ) { return( a = a ^ b ); } VImage & -operator^=( VImage a, const double b ) +operator^=( VImage &a, const double b ) { return( a = a ^ b ); } VImage & -operator^=( VImage a, std::vector b ) +operator^=( VImage &a, std::vector b ) { return( a = a ^ b ); } @@ -1347,19 +1347,19 @@ operator<<( VImage a, std::vector b ) } VImage & -operator<<=( VImage a, const VImage b ) +operator<<=( VImage &a, const VImage b ) { return( a = a << b ); } VImage & -operator<<=( VImage a, const double b ) +operator<<=( VImage &a, const double b ) { return( a = a << b ); } VImage & -operator<<=( VImage a, std::vector b ) +operator<<=( VImage &a, std::vector b ) { return( a = a << b ); } @@ -1384,19 +1384,19 @@ operator>>( VImage a, std::vector b ) } VImage & -operator>>=( VImage a, const VImage b ) +operator>>=( VImage &a, const VImage b ) { return( a = a << b ); } VImage & -operator>>=( VImage a, const double b ) +operator>>=( VImage &a, const double b ) { return( a = a << b ); } VImage & -operator>>=( VImage a, std::vector b ) +operator>>=( VImage &a, std::vector b ) { return( a = a << b ); } diff --git a/cplusplus/include/vips/VImage8.h b/cplusplus/include/vips/VImage8.h index 1480b12c..00d05896 100644 --- a/cplusplus/include/vips/VImage8.h +++ b/cplusplus/include/vips/VImage8.h @@ -781,9 +781,9 @@ public: friend VIPS_CPLUSPLUS_API VImage operator+( std::vector a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator+( VImage a, std::vector b ); - friend VIPS_CPLUSPLUS_API VImage & operator+=( VImage a, const VImage b ); - friend VIPS_CPLUSPLUS_API VImage & operator+=( VImage a, const double b ); - friend VIPS_CPLUSPLUS_API VImage & operator+=( VImage a, const std::vector b ); + friend VIPS_CPLUSPLUS_API VImage & operator+=( VImage &a, const VImage b ); + friend VIPS_CPLUSPLUS_API VImage & operator+=( VImage &a, const double b ); + friend VIPS_CPLUSPLUS_API VImage & operator+=( VImage &a, const std::vector b ); friend VIPS_CPLUSPLUS_API VImage operator-( VImage a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator-( double a, VImage b ); @@ -791,9 +791,9 @@ public: friend VIPS_CPLUSPLUS_API VImage operator-( std::vector a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator-( VImage a, std::vector b ); - friend VIPS_CPLUSPLUS_API VImage & operator-=( VImage a, const VImage b ); - friend VIPS_CPLUSPLUS_API VImage & operator-=( VImage a, const double b ); - friend VIPS_CPLUSPLUS_API VImage & operator-=( VImage a, const std::vector b ); + friend VIPS_CPLUSPLUS_API VImage & operator-=( VImage &a, const VImage b ); + friend VIPS_CPLUSPLUS_API VImage & operator-=( VImage &a, const double b ); + friend VIPS_CPLUSPLUS_API VImage & operator-=( VImage &a, const std::vector b ); friend VIPS_CPLUSPLUS_API VImage operator-( VImage a ); @@ -803,9 +803,9 @@ public: friend VIPS_CPLUSPLUS_API VImage operator*( std::vector a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator*( VImage a, std::vector b ); - friend VIPS_CPLUSPLUS_API VImage & operator*=( VImage a, const VImage b ); - friend VIPS_CPLUSPLUS_API VImage & operator*=( VImage a, const double b ); - friend VIPS_CPLUSPLUS_API VImage & operator*=( VImage a, const std::vector b ); + friend VIPS_CPLUSPLUS_API VImage & operator*=( VImage &a, const VImage b ); + friend VIPS_CPLUSPLUS_API VImage & operator*=( VImage &a, const double b ); + friend VIPS_CPLUSPLUS_API VImage & operator*=( VImage &a, const std::vector b ); friend VIPS_CPLUSPLUS_API VImage operator/( VImage a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator/( double a, VImage b ); @@ -813,17 +813,17 @@ public: friend VIPS_CPLUSPLUS_API VImage operator/( std::vector a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator/( VImage a, std::vector b ); - friend VIPS_CPLUSPLUS_API VImage & operator/=( VImage a, const VImage b ); - friend VIPS_CPLUSPLUS_API VImage & operator/=( VImage a, const double b ); - friend VIPS_CPLUSPLUS_API VImage & operator/=( VImage a, const std::vector b ); + friend VIPS_CPLUSPLUS_API VImage & operator/=( VImage &a, const VImage b ); + friend VIPS_CPLUSPLUS_API VImage & operator/=( VImage &a, const double b ); + friend VIPS_CPLUSPLUS_API VImage & operator/=( VImage &a, const std::vector b ); friend VIPS_CPLUSPLUS_API VImage operator%( VImage a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator%( VImage a, double b ); friend VIPS_CPLUSPLUS_API VImage operator%( VImage a, std::vector b ); - friend VIPS_CPLUSPLUS_API VImage & operator%=( VImage a, const VImage b ); - friend VIPS_CPLUSPLUS_API VImage & operator%=( VImage a, const double b ); - friend VIPS_CPLUSPLUS_API VImage & operator%=( VImage a, const std::vector b ); + friend VIPS_CPLUSPLUS_API VImage & operator%=( VImage &a, const VImage b ); + friend VIPS_CPLUSPLUS_API VImage & operator%=( VImage &a, const double b ); + friend VIPS_CPLUSPLUS_API VImage & operator%=( VImage &a, const std::vector b ); friend VIPS_CPLUSPLUS_API VImage operator<( VImage a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator<( double a, VImage b ); @@ -867,9 +867,9 @@ public: friend VIPS_CPLUSPLUS_API VImage operator&( std::vector a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator&( VImage a, std::vector b ); - friend VIPS_CPLUSPLUS_API VImage & operator&=( VImage a, const VImage b ); - friend VIPS_CPLUSPLUS_API VImage & operator&=( VImage a, const double b ); - friend VIPS_CPLUSPLUS_API VImage & operator&=( VImage a, const std::vector b ); + friend VIPS_CPLUSPLUS_API VImage & operator&=( VImage &a, const VImage b ); + friend VIPS_CPLUSPLUS_API VImage & operator&=( VImage &a, const double b ); + friend VIPS_CPLUSPLUS_API VImage & operator&=( VImage &a, const std::vector b ); friend VIPS_CPLUSPLUS_API VImage operator|( VImage a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator|( double a, VImage b ); @@ -877,9 +877,9 @@ public: friend VIPS_CPLUSPLUS_API VImage operator|( std::vector a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator|( VImage a, std::vector b ); - friend VIPS_CPLUSPLUS_API VImage & operator|=( VImage a, const VImage b ); - friend VIPS_CPLUSPLUS_API VImage & operator|=( VImage a, const double b ); - friend VIPS_CPLUSPLUS_API VImage & operator|=( VImage a, const std::vector b ); + friend VIPS_CPLUSPLUS_API VImage & operator|=( VImage &a, const VImage b ); + friend VIPS_CPLUSPLUS_API VImage & operator|=( VImage &a, const double b ); + friend VIPS_CPLUSPLUS_API VImage & operator|=( VImage &a, const std::vector b ); friend VIPS_CPLUSPLUS_API VImage operator^( VImage a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator^( double a, VImage b ); @@ -887,25 +887,25 @@ public: friend VIPS_CPLUSPLUS_API VImage operator^( std::vector a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator^( VImage a, std::vector b ); - friend VIPS_CPLUSPLUS_API VImage & operator^=( VImage a, const VImage b ); - friend VIPS_CPLUSPLUS_API VImage & operator^=( VImage a, const double b ); - friend VIPS_CPLUSPLUS_API VImage & operator^=( VImage a, const std::vector b ); + friend VIPS_CPLUSPLUS_API VImage & operator^=( VImage &a, const VImage b ); + friend VIPS_CPLUSPLUS_API VImage & operator^=( VImage &a, const double b ); + friend VIPS_CPLUSPLUS_API VImage & operator^=( VImage &a, const std::vector b ); friend VIPS_CPLUSPLUS_API VImage operator<<( VImage a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator<<( VImage a, double b ); friend VIPS_CPLUSPLUS_API VImage operator<<( VImage a, std::vector b ); - friend VIPS_CPLUSPLUS_API VImage & operator<<=( VImage a, const VImage b ); - friend VIPS_CPLUSPLUS_API VImage & operator<<=( VImage a, const double b ); - friend VIPS_CPLUSPLUS_API VImage & operator<<=( VImage a, const std::vector b ); + friend VIPS_CPLUSPLUS_API VImage & operator<<=( VImage &a, const VImage b ); + friend VIPS_CPLUSPLUS_API VImage & operator<<=( VImage &a, const double b ); + friend VIPS_CPLUSPLUS_API VImage & operator<<=( VImage &a, const std::vector b ); friend VIPS_CPLUSPLUS_API VImage operator>>( VImage a, VImage b ); friend VIPS_CPLUSPLUS_API VImage operator>>( VImage a, double b ); friend VIPS_CPLUSPLUS_API VImage operator>>( VImage a, std::vector b ); - friend VIPS_CPLUSPLUS_API VImage & operator>>=( VImage a, const VImage b ); - friend VIPS_CPLUSPLUS_API VImage & operator>>=( VImage a, const double b ); - friend VIPS_CPLUSPLUS_API VImage & operator>>=( VImage a, const std::vector b ); + friend VIPS_CPLUSPLUS_API VImage & operator>>=( VImage &a, const VImage b ); + friend VIPS_CPLUSPLUS_API VImage & operator>>=( VImage &a, const double b ); + friend VIPS_CPLUSPLUS_API VImage & operator>>=( VImage &a, const std::vector b ); }; diff --git a/libvips/foreign/dzsave.c b/libvips/foreign/dzsave.c index d83309d0..46696af2 100644 --- a/libvips/foreign/dzsave.c +++ b/libvips/foreign/dzsave.c @@ -213,7 +213,8 @@ write_vips_property( VipsImage *image, xmlNode *child; g_value_init( &save_value, VIPS_TYPE_SAVE_STRING ); - g_value_transform( value, &save_value ); + if( !g_value_transform( value, &save_value ) ) + return( image ); if( !(property = new_child( info, info->node, "property" )) ) return( image ); diff --git a/libvips/iofuncs/header.c b/libvips/iofuncs/header.c index f453e716..57a42d81 100644 --- a/libvips/iofuncs/header.c +++ b/libvips/iofuncs/header.c @@ -1167,7 +1167,7 @@ vips_image_map( VipsImage *image, VipsImageMapFn fn, void *a ) for( i = 0; i < VIPS_NUMBER( vips_header_fields ); i++ ) { HeaderField *field = &vips_header_fields[i]; - vips_image_get( image, field->name, &value ); + (void) vips_image_get( image, field->name, &value ); result = fn( image, field->name, &value, a ); g_value_unset( &value ); diff --git a/libvips/resample/mapim.c b/libvips/resample/mapim.c index 8592363e..28042c03 100644 --- a/libvips/resample/mapim.c +++ b/libvips/resample/mapim.c @@ -159,6 +159,27 @@ vips_mapim_region_minmax( VipsRegion *region, VipsRect *r, VipsRect *bounds ) bounds->height = 1 + max_y - min_y; } +#define ULOOKUP( TYPE ) { \ + TYPE * restrict p1 = (TYPE *) p; \ + \ + for( x = 0; x < r->width; x++ ) { \ + TYPE px = p1[0]; \ + TYPE py = p1[1]; \ + \ + if( px >= resample->in->Xsize || \ + py >= resample->in->Ysize ) { \ + for( z = 0; z < ps; z++ ) \ + q[z] = 0; \ + } \ + else \ + interpolate( mapim->interpolate, q, ir[0], \ + px + window_offset, py + window_offset ); \ + \ + p1 += 2; \ + q += ps; \ + } \ +} + #define LOOKUP( TYPE ) { \ TYPE * restrict p1 = (TYPE *) p; \ \ @@ -265,15 +286,15 @@ vips_mapim_gen( VipsRegion *or, void *seq, void *a, void *b, gboolean *stop ) switch( ir[1]->im->BandFmt ) { case VIPS_FORMAT_UCHAR: - LOOKUP( unsigned char ); break; + ULOOKUP( unsigned char ); break; case VIPS_FORMAT_CHAR: LOOKUP( signed char ); break; case VIPS_FORMAT_USHORT: - LOOKUP( unsigned short ); break; + ULOOKUP( unsigned short ); break; case VIPS_FORMAT_SHORT: LOOKUP( signed short ); break; case VIPS_FORMAT_UINT: - LOOKUP( unsigned int ); break; + ULOOKUP( unsigned int ); break; case VIPS_FORMAT_INT: LOOKUP( signed int ); break; diff --git a/libvips/resample/shrinkh.c b/libvips/resample/shrinkh.c index 695b039c..3c1afaf6 100644 --- a/libvips/resample/shrinkh.c +++ b/libvips/resample/shrinkh.c @@ -283,7 +283,7 @@ vips_shrinkh_build( VipsObject *object ) * fractional part), we just see the integer part here. */ resample->out->Xsize = VIPS_ROUND_UINT( - resample->in->Xsize / shrink->hshrink ); + (double) resample->in->Xsize / shrink->hshrink ); if( resample->out->Xsize <= 0 ) { vips_error( class->nickname, "%s", _( "image has shrunk to nothing" ) ); diff --git a/libvips/resample/shrinkv.c b/libvips/resample/shrinkv.c index 9e061566..3672c7c5 100644 --- a/libvips/resample/shrinkv.c +++ b/libvips/resample/shrinkv.c @@ -387,7 +387,7 @@ vips_shrinkv_build( VipsObject *object ) * fractional part), we just see the integer part here. */ resample->out->Ysize = VIPS_ROUND_UINT( - resample->in->Ysize / shrink->vshrink ); + (double) resample->in->Ysize / shrink->vshrink ); if( resample->out->Ysize <= 0 ) { vips_error( class->nickname, "%s", _( "image has shrunk to nothing" ) );