From 01025328daba23027bddd49bd3db2023bf401837 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 28 Sep 2015 22:01:15 +0100 Subject: [PATCH] fix some cppcheck warnings try: $ cppcheck -f --enable=warning,performance,portability -j4 . 2> err.txt there are still some left, see: see https://github.com/jcupitt/libvips/issues/331 --- cplusplus/VImage.cpp | 6 +++--- cplusplus/examples/buffer.cpp | 2 +- cplusplus/examples/test.cpp | 6 +++--- cplusplus/examples/test_overloads.cpp | 2 +- libvips/colour/UCS2LCh.c | 12 +++++++++--- libvips/conversion/insert.c | 2 +- libvips/foreign/jpeg2vips.c | 17 +++++++++++++++++ libvips/foreign/jpegsave.c | 2 +- libvips/foreign/tiff2vips.c | 2 +- libvips/foreign/webpsave.c | 2 +- libvips/iofuncs/base64.c | 2 +- libvips/iofuncs/object.c | 6 ------ libvips/iofuncs/util.c | 2 +- libvipsCC/VImage.cc | 6 +++--- 14 files changed, 43 insertions(+), 26 deletions(-) diff --git a/cplusplus/VImage.cpp b/cplusplus/VImage.cpp index 5b9818e6..b97577fe 100644 --- a/cplusplus/VImage.cpp +++ b/cplusplus/VImage.cpp @@ -104,7 +104,7 @@ VOption::~VOption() { std::list::iterator i; - for( i = options.begin(); i != options.end(); i++ ) + for( i = options.begin(); i != options.end(); ++i ) delete *i; } @@ -378,7 +378,7 @@ VOption::set_operation( VipsOperation *operation ) { std::list::iterator i; - for( i = options.begin(); i != options.end(); i++ ) + for( i = options.begin(); i != options.end(); ++i ) if( (*i)->input ) { #ifdef VIPS_DEBUG_VERBOSE printf( "set_operation: " ); @@ -399,7 +399,7 @@ VOption::get_operation( VipsOperation *operation ) { std::list::iterator i; - for( i = options.begin(); i != options.end(); i++ ) + for( i = options.begin(); i != options.end(); ++i ) if( not (*i)->input ) { const char *name = (*i)->name; diff --git a/cplusplus/examples/buffer.cpp b/cplusplus/examples/buffer.cpp index 12dcf1f6..176a56d7 100644 --- a/cplusplus/examples/buffer.cpp +++ b/cplusplus/examples/buffer.cpp @@ -46,7 +46,7 @@ main( int argc, char **argv ) size_t size; void *buf; im.write_to_buffer( ".png", &buf, &size ); - printf( "written to memory %p in png format, %zd bytes\n", buf, size ); + printf( "written to memory %p in png format, %zu bytes\n", buf, size ); // load from the formatted memory area im = VImage::new_from_buffer( buf, size, "" ); diff --git a/cplusplus/examples/test.cpp b/cplusplus/examples/test.cpp index fc6b1a8a..1e0db301 100644 --- a/cplusplus/examples/test.cpp +++ b/cplusplus/examples/test.cpp @@ -31,7 +31,7 @@ equal_vector( std::vector a, std::vector b ) { for( unsigned int i = 0; i < a.size(); i++ ) if( fabs( a[i] - b[i] ) > 0.001 ) { - printf( "vectors differ at %d: should be [", i ); + printf( "vectors differ at %u: should be [", i ); for( unsigned int i = 0; i < a.size(); i++ ) { if( i > 0 ) printf( ", " ); @@ -302,7 +302,7 @@ main( int argc, char **argv ) size_t size; void *buf; left.write_to_buffer( ".png", &buf, &size ); - printf( "written to memory %p in png format, %zd bytes\n", buf, size ); + printf( "written to memory %p in png format, %zu bytes\n", buf, size ); // load from the formatted memory area VImage im = VImage::new_from_buffer( buf, size, "" ); @@ -323,7 +323,7 @@ main( int argc, char **argv ) size_t size; void *buf; buf = left.write_to_memory( &size ); - printf( "written to memory %p as an array, %zd bytes\n", buf, size ); + printf( "written to memory %p as an array, %zu bytes\n", buf, size ); // load from the memory array VImage im = VImage::new_from_memory( buf, size, diff --git a/cplusplus/examples/test_overloads.cpp b/cplusplus/examples/test_overloads.cpp index e1b84445..7a598af2 100644 --- a/cplusplus/examples/test_overloads.cpp +++ b/cplusplus/examples/test_overloads.cpp @@ -27,7 +27,7 @@ equal_vector( std::vector a, std::vector b ) { for( unsigned int i = 0; i < a.size(); i++ ) if( fabs( a[i] - b[i] ) > 0.001 ) { - printf( "vectors differ at %d: should be [", i ); + printf( "vectors differ at %u: should be [", i ); for( unsigned int i = 0; i < a.size(); i++ ) { if( i > 0 ) printf( ", " ); diff --git a/libvips/colour/UCS2LCh.c b/libvips/colour/UCS2LCh.c index dfec05ae..8426ebbe 100644 --- a/libvips/colour/UCS2LCh.c +++ b/libvips/colour/UCS2LCh.c @@ -77,7 +77,9 @@ make_LI( void ) for( i = 0; i < 1001; i++ ) { int j; - for( j = 0; j < 1001 && Ll[j] <= i / 10.0; j++ ) + /* Must be 1000, since j will be +1 on exit. + */ + for( j = 0; j < 1000 && Ll[j] <= i / 10.0; j++ ) ; LI[i] = (j - 1) / 10.0 + @@ -99,8 +101,11 @@ make_CI( void ) for( i = 0; i < 3001; i++ ) { int j; - for( j = 0; j < 3001 && Cl[j] <= i / 10.0; j++ ) + /* Must be 3000, since j will be +1 on exit. + */ + for( j = 0; j < 3000 && Cl[j] <= i / 10.0; j++ ) ; + CI[i] = (j - 1) / 10.0 + (i / 10.0 - Cl[j - 1]) / ((Cl[j] - Cl[j - 1]) * 10.0); } @@ -122,8 +127,9 @@ make_hI( void ) for( i = 0; i < 361; i++ ) { int k; - for( k = 0; k < 361 && hl[j][k] <= i; k++ ) + for( k = 0; k < 360 && hl[j][k] <= i; k++ ) ; + hI[j][i] = k - 1 + (i - hl[j][k - 1]) / (hl[j][k] - hl[j][k - 1]); } diff --git a/libvips/conversion/insert.c b/libvips/conversion/insert.c index 68640837..d01ecf6f 100644 --- a/libvips/conversion/insert.c +++ b/libvips/conversion/insert.c @@ -343,7 +343,7 @@ vips__ink_to_vector( const char *domain, VipsImage *im, VipsPel *ink, int *n ) printf( "\tvec = " ); for( i = 0; i < *n; i++ ) - printf( "%d ", result[i] ); + printf( "%g ", result[i] ); printf( "\n" ); } #endif /*VIPS_DEBUG*/ diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index 561a97ec..c61ceabd 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -872,6 +872,11 @@ read_jpeg_header( ReadJpeg *jpeg, VipsImage *out ) break; default: +#ifdef DEBUG + printf( "read_jpeg_header: " + "ignoring %d byte APP%d block\n", + p->data_length, p->marker - JPEG_APP0 ); +#endif /*DEBUG*/ break; } } @@ -1067,6 +1072,18 @@ vips__jpeg_read( ReadJpeg *jpeg, VipsImage *out, gboolean header_only ) jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + 2, 0xffff ); jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + 13, 0xffff ); +#ifdef DEBUG +{ + int i; + + /* Handy for debubgging ... spot any extra markers. + */ + for( i = 0; i < 16; i++ ) + jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + i, 0xffff ); +} +#endif /*DEBUG*/ + + /* Convert! */ if( header_only ) { diff --git a/libvips/foreign/jpegsave.c b/libvips/foreign/jpegsave.c index 6329aabb..2cc29a6a 100644 --- a/libvips/foreign/jpegsave.c +++ b/libvips/foreign/jpegsave.c @@ -360,7 +360,7 @@ vips_foreign_save_jpeg_mime_build( VipsObject *object ) jpeg->trellis_quant, jpeg->overshoot_deringing, jpeg->optimize_scans) ) return( -1 ); - printf( "Content-length: %zd\r\n", olen ); + printf( "Content-length: %zu\r\n", olen ); printf( "Content-type: image/jpeg\r\n" ); printf( "\r\n" ); if( fwrite( obuf, sizeof( char ), olen, stdout ) != olen ) { diff --git a/libvips/foreign/tiff2vips.c b/libvips/foreign/tiff2vips.c index ec4a3c21..2c7291c8 100644 --- a/libvips/foreign/tiff2vips.c +++ b/libvips/foreign/tiff2vips.c @@ -1772,7 +1772,7 @@ my_tiff_read( thandle_t st, tdata_t buffer, tsize_t size ) size_t available = rtiff->len - rtiff->pos; size_t copy = VIPS_MIN( size, available ); - memcpy( buffer, rtiff->buf + rtiff->pos, copy ); + memcpy( buffer, (unsigned char *) rtiff->buf + rtiff->pos, copy ); rtiff->pos += copy; return( copy ); diff --git a/libvips/foreign/webpsave.c b/libvips/foreign/webpsave.c index 03120c0d..b507785a 100644 --- a/libvips/foreign/webpsave.c +++ b/libvips/foreign/webpsave.c @@ -269,7 +269,7 @@ vips_foreign_save_webp_mime_build( VipsObject *object ) webp->Q, webp->lossless ) ) return( -1 ); - printf( "Content-length: %zd\r\n", olen ); + printf( "Content-length: %zu\r\n", olen ); printf( "Content-type: image/webp\r\n" ); printf( "\r\n" ); if( fwrite( obuf, sizeof( char ), olen, stdout ) != olen ) { diff --git a/libvips/iofuncs/base64.c b/libvips/iofuncs/base64.c index ab2c9a0f..dc072f64 100644 --- a/libvips/iofuncs/base64.c +++ b/libvips/iofuncs/base64.c @@ -213,7 +213,7 @@ vips__b64_encode( const unsigned char *data, size_t data_length ) for( total = 0, i = 0; i < data_length; i++ ) total += data[i]; - printf( "vips__b64_encode: length = %u, checksum 0x%x\n", + printf( "vips__b64_encode: length = %zu, checksum 0x%x\n", data_length, total & 0xffff ); } #endif /*DEBUG*/ diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index 30f0b813..f27ebd2d 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -1167,12 +1167,6 @@ vips_object_set_property( GObject *gobject, g_assert( argument_instance ); - if( !argument_class ) { - G_OBJECT_WARN_INVALID_PROPERTY_ID( gobject, - property_id, pspec ); - return; - } - #ifdef DEBUG printf( "vips_object_set_property: " ); vips_object_print_name( object ); diff --git a/libvips/iofuncs/util.c b/libvips/iofuncs/util.c index 7afafcb3..15d380b2 100644 --- a/libvips/iofuncs/util.c +++ b/libvips/iofuncs/util.c @@ -1313,7 +1313,7 @@ vips__token_need( const char *p, VipsToken need_token, const char * vips__find_rightmost_brackets( const char *p ) { - const char *start[MAX_TOKENS]; + const char *start[MAX_TOKENS + 1]; VipsToken tokens[MAX_TOKENS]; char str[VIPS_PATH_MAX]; int n, i; diff --git a/libvipsCC/VImage.cc b/libvipsCC/VImage.cc index f229d1d9..6548f745 100644 --- a/libvipsCC/VImage.cc +++ b/libvipsCC/VImage.cc @@ -81,7 +81,7 @@ void VImage::refblock::debug_print() printf( " close_on_delete = %d\n", close_on_delete ); printf( " nrefs (refs to us) = %d\n", nrefs ); printf( " orefs (refs we make) = refblocks " ); - for( i = orefs.begin(); i != orefs.end(); i++ ) + for( i = orefs.begin(); i != orefs.end(); ++i ) printf( "%p ", *i ); printf( "\n" ); } @@ -93,7 +93,7 @@ void VImage::print_all() std::list::iterator i; printf( "*** VImage::refblock::print_all() start\n" ); - for( i = all_refblock.begin(); i != all_refblock.end(); i++ ) + for( i = all_refblock.begin(); i != all_refblock.end(); ++i ) (*i)->debug_print(); printf( "*** VImage::refblock::print_all() end\n" ); #endif /*DEBUG*/ @@ -143,7 +143,7 @@ VImage::refblock::~refblock() throw( VError ) } // remove any refs we have ... may trigger other destructs in turn - for( i = orefs.begin(); i != orefs.end(); i++ ) + for( i = orefs.begin(); i != orefs.end(); ++i ) (*i)->removeref(); #ifdef DEBUG