-Wextra fixes

This commit is contained in:
John Cupitt 2009-05-12 15:32:52 +00:00
parent ab5476f270
commit 5c95d1d681
17 changed files with 82 additions and 42 deletions

View File

@ -6,6 +6,7 @@
- report virtual memory too in im__print_all()
- cosmetic changes to nohalo
- im_magick2vips() needs to invert alpha
- now (more or less) passes -Wextra
25/3/09 started 7.18.0
- revised version numbers

8
TODO
View File

@ -1,3 +1,11 @@
- IMAGE->file_length should be gint64 rather than size_t?
if we make this change, need to remove extra casts from various uses
- rename "header" program? or maybe use "vips header" instead?
it's disabled on ubuntu due to a name clash
- import ~/summer-demo/summer.tif fails with "unable to read embedded
profile", is this a bug? better err msg would be good

View File

@ -2,6 +2,9 @@
*
* 2006-09-21 tcv
* random access to images and regions
*
* 12/5/09
* - add casts to IM__VALUE_FROM_ARRAY() to remove confusion about the type of the result
*/
#ifndef IM_R_ACCESS_H
@ -25,14 +28,14 @@
#define IM__DOUBLE_FROM_ARRAY(vptr,i) IM__TYPE_FROM_ARRAY( double, (vptr), (i) )
#define IM__VALUE_FROM_ARRAY(band_fmt,vptr,i) ( \
( IM_BANDFMT_DOUBLE == (band_fmt) ) ? IM__DOUBLE_FROM_ARRAY( (vptr), (i) ) \
: ( IM_BANDFMT_FLOAT == (band_fmt) ) ? IM__FLOAT_FROM_ARRAY( (vptr), (i) ) \
: ( IM_BANDFMT_INT == (band_fmt) ) ? IM__INT_FROM_ARRAY( (vptr), (i) ) \
: ( IM_BANDFMT_UINT == (band_fmt) ) ? IM__UINT_FROM_ARRAY( (vptr), (i) ) \
: ( IM_BANDFMT_SHORT == (band_fmt) ) ? IM__SHORT_FROM_ARRAY( (vptr), (i) ) \
: ( IM_BANDFMT_USHORT == (band_fmt) ) ? IM__USHORT_FROM_ARRAY( (vptr), (i) ) \
: ( IM_BANDFMT_CHAR == (band_fmt) ) ? IM__CHAR_FROM_ARRAY( (vptr), (i) ) \
: IM__UCHAR_FROM_ARRAY( (vptr), (i) ) )
( IM_BANDFMT_DOUBLE == (band_fmt) ) ? (double) IM__DOUBLE_FROM_ARRAY( (vptr), (i) ) \
: ( IM_BANDFMT_FLOAT == (band_fmt) ) ? (double) IM__FLOAT_FROM_ARRAY( (vptr), (i) ) \
: ( IM_BANDFMT_INT == (band_fmt) ) ? (double) IM__INT_FROM_ARRAY( (vptr), (i) ) \
: ( IM_BANDFMT_UINT == (band_fmt) ) ? (double) IM__UINT_FROM_ARRAY( (vptr), (i) ) \
: ( IM_BANDFMT_SHORT == (band_fmt) ) ? (double) IM__SHORT_FROM_ARRAY( (vptr), (i) ) \
: ( IM_BANDFMT_USHORT == (band_fmt) ) ? (double) IM__USHORT_FROM_ARRAY( (vptr), (i) ) \
: ( IM_BANDFMT_CHAR == (band_fmt) ) ? (double) IM__CHAR_FROM_ARRAY( (vptr), (i) ) \
: (double) IM__UCHAR_FROM_ARRAY( (vptr), (i) ) )
#define IM__ARRAY_ASSIGNMENT(band_fmt,vptr,i,val) ( \
( IM_BANDFMT_DOUBLE == (band_fmt) ) ? ( IM__DOUBLE_FROM_ARRAY( (vptr), (i) )= (val) ) \

View File

@ -13,6 +13,9 @@
* Author: Tom Vajzovic
*
* Written on: 2006-12-26
*
* 12/5/09
* - make x_anal() static, fix some signed/unsigned warnings
*/
/*
@ -89,7 +92,7 @@ LINREG_SEQ( double );
/** LOCAL FUNCTION DECLARATIONS **/
x_set *x_anal( IMAGE *im, double *xs, unsigned int n );
static x_set *x_anal( IMAGE *im, double *xs, unsigned int n );
#define LINREG_START_DECL( TYPE ) static void * linreg_start_ ## TYPE( IMAGE *, void *, void * );
#define LINREG_GEN_DECL( TYPE ) static int linreg_gen_ ## TYPE( REGION *, void *, void *, void * );
@ -246,8 +249,8 @@ int im_linreg( IMAGE **ins, IMAGE *out, double *xs ){
/** LOCAL FUNCTION DECLARATIONS **/
x_set *x_anal( IMAGE *im, double *xs, unsigned int n ){
int i;
static x_set *x_anal( IMAGE *im, double *xs, unsigned int n ){
unsigned int i;
x_set *x_vals= IM_NEW( im, x_set );
@ -321,7 +324,7 @@ x_set *x_anal( IMAGE *im, double *xs, unsigned int n ){
double *out_end= out + out_skip * to_make-> valid. height; \
double *out_stop; \
size_t out_n= IM_REGION_N_ELEMENTS( to_make ); \
int i; \
unsigned int i; \
\
out_skip-= out_n; \
\

View File

@ -101,10 +101,10 @@ int im_point_bilinear( IMAGE *im, double x, double y, int band, double *val ){
if( x_frac )
if( y_frac )
*val= x_frac * y_frac * IM_REGION_VALUE( reg, ((int)x + 1), ((int)y + 1), band )
+ x_frac * ( 1.0 - y_frac ) * IM_REGION_VALUE( reg, ((int)x + 1), (int)y , band )
+ ( 1.0 - x_frac ) * y_frac * IM_REGION_VALUE( reg, (int)x, ((int)y + 1), band )
+ ( 1.0 - x_frac ) * ( 1.0 - y_frac ) * IM_REGION_VALUE( reg, (int)x, (int)y , band );
*val= x_frac * y_frac * (double) IM_REGION_VALUE( reg, ((int)x + 1), ((int)y + 1), band )
+ x_frac * ( 1.0 - y_frac ) * (double) IM_REGION_VALUE( reg, ((int)x + 1), (int)y , band )
+ ( 1.0 - x_frac ) * y_frac * (double) IM_REGION_VALUE( reg, (int)x, ((int)y + 1), band )
+ ( 1.0 - x_frac ) * ( 1.0 - y_frac ) * (double) IM_REGION_VALUE( reg, (int)x, (int)y , band );
else
*val= x_frac * IM_REGION_VALUE( reg, ((int)x + 1), (int)y, band )

View File

@ -12,6 +12,8 @@
* - from im_tiff2vips and im_vips2jpeg, plus some stuff from Steve
* 11/7/01 JC
* - page number now in filename
* 12/5/09
* - fix signed/unsigned warning
*/
/*
@ -57,15 +59,16 @@
static int
extract( IMAGE *in, int x, int y, int w, int h )
{
IMAGE *t1;
int len;
char *buf;
IMAGE *t1 = im_open_local( in, "im_bernd:2", "p" );
if( im_extract_area( in, t1, x, y, w, h ) ||
if( !(t1 = im_open_local( in, "im_bernd:2", "p" )) ||
im_extract_area( in, t1, x, y, w, h ) ||
im_vips2bufjpeg( t1, in, 75, &buf, &len ) )
return( -1 );
if( fwrite( buf, sizeof( char ), len, stdout ) != len ) {
if( fwrite( buf, sizeof( char ), len, stdout ) != (size_t) len ) {
im_error( "im_bernd", "%s", _( "error writing output" ) );
return( -1 );
}

View File

@ -4,6 +4,8 @@
* - dbh.h header from Ralph Myers
* 22/8/05
* - better byteswapper
* 12/5/09
* - fix signed/unsigned warning
*/
/*
@ -312,7 +314,7 @@ read_header( const char *header )
/* Ouch! Should check at configure time I guess.
*/
assert( sizeof( struct dsr ) == 348 );
g_assert( sizeof( struct dsr ) == 348 );
/* dsr headers are always SPARC byte order (MSB first). Do we need to
* swap?
@ -348,7 +350,7 @@ read_header( const char *header )
}
}
if( len != d->hk.sizeof_hdr ) {
if( (int) len != d->hk.sizeof_hdr ) {
im_free( d );
return( NULL );
}

View File

@ -27,6 +27,8 @@
* 20/4/09
* - argh libMagick uses 255 == transparent ... we must invert all
* alpha channels
* 12/5/09
* - fix signed/unsigned warnings
*/
/*
@ -355,9 +357,9 @@ parse_header( Read *read )
*/
read->n_frames = 0;
for( p = image; p; (p = GetNextImageInList( p )) ) {
if( p->columns != im->Xsize ||
p->rows != im->Ysize ||
p->depth != im->Bbits ||
if( p->columns != (unsigned int) im->Xsize ||
p->rows != (unsigned int) im->Ysize ||
p->depth != (unsigned int) im->Bbits ||
get_bands( p ) != im->Bands )
break;

View File

@ -25,6 +25,8 @@
* - use im_wbuffer() API for BG writes
* 15/2/08
* - write CMYK if Bands == 4 and Type == CMYK
* 12/5/09
* - fix signed/unsigned warning
*/
/*
@ -815,6 +817,9 @@ buf_dest( j_compress_ptr cinfo, IMAGE *out, char **obuf, int *olen )
/* As above, but save to a buffer. The buffer is allocated relative to out.
* On success, buf is set to the output buffer and len to the size of the
* compressed image.
FIXME ... argh, the retuen length should really be a size_t, but we can't fix this now sadly
*/
int
im_vips2bufjpeg( IMAGE *in, IMAGE *out, int qfac, char **obuf, int *olen )
@ -877,7 +882,7 @@ im_vips2mimejpeg( IMAGE *in, int qfac )
printf( "Content-length: %d\r\n", len );
printf( "Content-type: image/jpeg\r\n" );
printf( "\r\n" );
if( fwrite( buf, sizeof( char ), len, stdout ) != len ) {
if( fwrite( buf, sizeof( char ), len, stdout ) != (size_t) len ) {
im_error( "im_vips2mimejpeg",
"%s", _( "error writing output" ) );
return( -1 );

View File

@ -38,6 +38,8 @@
* 14/12/05
* - redone plot function in C, also use incheck() to cache calcs
* - much, much faster!
* 12/5/09
* - fix signed/unsigned warning
*/
/*
@ -145,7 +147,7 @@ normalise( IMAGE *in, IMAGE *out )
\
for( x = le; x < ri; x++ ) { \
for( z = 0; z < nb; z++ ) \
q[z] = p1[z] < x ? 0 : 255; \
q[z] = p1[z] < ((TYPE) x) ? 0 : 255; \
\
q += nb; \
} \
@ -198,7 +200,7 @@ make_vert_gen( REGION *or, void *seq, void *a, void *b )
\
for( y = to; y < bo; y++ ) { \
for( z = 0; z < nb; z++ ) \
q[z] = p1[z] < (ht - y) ? 0 : 255; \
q[z] = p1[z] < ((TYPE) (ht - y)) ? 0 : 255; \
\
q += lsk; \
} \

View File

@ -59,6 +59,9 @@ Modified on:
23/7/07 JC
- oop, needed a slightly larger worst-case buffer in im__b64_encode()
12/5/09
- fix signed/unsigned warning
*/
/*
@ -262,7 +265,7 @@ im__b64_decode( const char *buffer, size_t *data_length )
}
}
assert( p - data < output_data_length );
g_assert( (size_t) (p - data) < output_data_length );
if( data_length )
*data_length = p - data;

View File

@ -29,6 +29,8 @@
* - use int64 for size calcs so we can map >31 bit files on 64 bit
* machines
* - delay mmap() for large files, cf. im_openin()
* 12/5/09
* - fix signed/unsigned warnings
*/
/*
@ -84,6 +86,7 @@ im_binfile( const char *name, int xs, int ys, int bands, int offset )
{
IMAGE *im;
gint64 psize;
gint64 rsize;
/* Check parameters.
*/
@ -108,17 +111,18 @@ im_binfile( const char *name, int xs, int ys, int bands, int offset )
*/
psize = (gint64) xs * ys * bands + offset;
/* Read the file length and check against what we think
/* Read the real file length and check against what we think
* the size should be.
*/
if( (im->file_length = im_file_length( im->fd )) == -1 ) {
if( (rsize = im_file_length( im->fd )) == -1 ) {
im_close( im );
return( NULL );
}
im->file_length = (size_t) rsize;
/* Very common, so special message.
*/
if( psize > im->file_length ) {
if( psize > rsize ) {
im_error( "im_binfile", _( "unable to open %s: "
"file has been truncated" ), im->filename );
im_close( im );
@ -128,7 +132,7 @@ im_binfile( const char *name, int xs, int ys, int bands, int offset )
/* Just wierd. Only print a warning for this, since we should
* still be able to process it without coredumps.
*/
if( psize < im->file_length )
if( psize < rsize )
im_warn( "im_binfile", _( "%s is longer than expected" ),
im->filename );

View File

@ -5,6 +5,8 @@
* im_openout.c
* 19/3/09
* - block mmaps of nodata images
* 12/5/09
* - fix signed/unsigned warnings
*/
/*
@ -311,7 +313,7 @@ read_chunk( int fd, gint64 offset, size_t length )
return( NULL );
if( !(buf = im_malloc( NULL, length + 1 )) )
return( NULL );
if( read( fd, buf, length ) != length ) {
if( read( fd, buf, length ) != (ssize_t) length ) {
im_free( buf );
im_error( "im_readhist", "%s", _( "unable to read history" ) );
return( NULL );
@ -894,6 +896,7 @@ im__read_header( IMAGE *image )
unsigned char header[IM_SIZEOF_HEADER];
gint64 psize;
gint64 rsize;
image->dtype = IM_OPENIN;
if( (image->fd = im__open_image_file( image->filename )) == -1 )
@ -909,9 +912,10 @@ im__read_header( IMAGE *image )
/* Predict and check the file size.
*/
psize = im__image_pixel_length( image );
if( (image->file_length = im_file_length( image->fd )) == -1 )
if( (rsize = im_file_length( image->fd )) == -1 )
return( -1 );
if( psize > image->file_length )
image->file_length = rsize;
if( psize > rsize )
im_warn( "im_openin", _( "unable to read data for \"%s\", %s" ),
image->filename, _( "file has been truncated" ) );
@ -960,7 +964,7 @@ im_openin( IMAGE *image )
size = (gint64) IM_IMAGE_SIZEOF_LINE( image ) * image->Ysize +
image->sizeof_header;
if( size < im__mmap_limit &&
image->file_length >= size ) {
(gint64) image->file_length >= size ) {
if( im_mapfile( image ) )
return( -1 );
image->data = image->baseaddr + image->sizeof_header;

View File

@ -803,7 +803,7 @@ vips_object_class_install_argument( VipsObjectClass *object_class,
static int
vips_object_set_arg( VipsObject *object, const char *name, const char *value )
{
GValue gvalue = { 0, };
GValue gvalue = { 0 };
g_value_init( &gvalue, G_TYPE_STRING );
g_value_set_string( &gvalue, value );

View File

@ -284,8 +284,8 @@ im_threadgroup_wait( im_threadgroup_t *tg )
g_mutex_lock( tg->idle_lock );
assert( tg->idle );
assert( g_slist_length( tg->idle ) == tg->nthr );
g_assert( tg->idle );
g_assert( g_slist_length( tg->idle ) == (unsigned int) tg->nthr );
g_mutex_unlock( tg->idle_lock );

View File

@ -249,7 +249,7 @@ vips_type_map( GType base, VipsTypeMap2 fn, void *a, void *b )
{
GType *child;
guint n_children;
int i;
unsigned int i;
void *result;
child = g_type_children( base, &n_children );
@ -1098,7 +1098,7 @@ im__gslist_gvalue_get( const GSList *list )
q += 1;
}
assert( q - all == length );
g_assert( (size_t) (q - all) == length );
return( all );
}

View File

@ -231,7 +231,7 @@ im_window_set( im_window_t *window, int top, int height )
/* Make sure we have enough file.
*/
if( end > window->im->file_length ) {
if( end > (gint64) window->im->file_length ) {
im_error( "im_window_set",
_( "unable to read data for \"%s\", %s" ),
window->im->filename, _( "file has been truncated" ) );