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
This commit is contained in:
John Cupitt 2015-09-28 22:01:15 +01:00
parent 3207cca96c
commit 01025328da
14 changed files with 43 additions and 26 deletions

View File

@ -104,7 +104,7 @@ VOption::~VOption()
{
std::list<Pair *>::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<Pair *>::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<Pair *>::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;

View File

@ -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, "" );

View File

@ -31,7 +31,7 @@ equal_vector( std::vector<double> a, std::vector<double> 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,

View File

@ -27,7 +27,7 @@ equal_vector( std::vector<double> a, std::vector<double> 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( ", " );

View File

@ -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]);
}

View File

@ -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*/

View File

@ -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 ) {

View File

@ -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 ) {

View File

@ -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 );

View File

@ -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 ) {

View File

@ -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*/

View File

@ -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 );

View File

@ -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;

View File

@ -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<VImage::refblock *>::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