fix some cppcheck warnings

This commit is contained in:
John Cupitt 2013-05-01 18:46:15 +01:00
parent 147b135944
commit 8956ba536b
22 changed files with 360 additions and 339 deletions

View File

@ -37,6 +37,10 @@ Then for a debug build:
$ make
$ make install
Static analysis with:
$ cppcheck --force --enable=style . &> cppcheck.log
# Dependencies
libvips has to have gettext, glib-2.x and libxml-2.0. The build system needs

View File

@ -141,12 +141,11 @@ colr_color(col, clr) /* convert short to float color */
register COLOR col;
register COLR clr;
{
double f;
if (clr[EXP] == 0)
col[RED] = col[GRN] = col[BLU] = 0.0;
else {
f = ldexp(1.0, (int)clr[EXP]-(COLXS+8));
double f = ldexp(1.0, (int)clr[EXP]-(COLXS+8));
col[RED] = (clr[RED] + 0.5)*f;
col[GRN] = (clr[GRN] + 0.5)*f;
col[BLU] = (clr[BLU] + 0.5)*f;

View File

@ -284,13 +284,14 @@ static void
vips_format_summary_class( VipsObjectClass *object_class, VipsBuf *buf )
{
VipsFormatClass *class = VIPS_FORMAT_CLASS( object_class );
const char **p;
VIPS_OBJECT_CLASS( vips_format_parent_class )->
summary_class( object_class, buf );
vips_buf_appends( buf, ", " );
if( class->suffs ) {
const char **p;
vips_buf_appends( buf, "(" );
for( p = class->suffs; *p; p++ ) {
vips_buf_appendf( buf, "%s", *p );

View File

@ -774,14 +774,16 @@ im_map_packages( VSListMap2Fn fn, void *a )
{
void *r = im_slist_map2( plugin_list,
(VSListMap2Fn) apply_plugin, (void *) fn, a );
int i;
/* If not there, try main VIPS package list.
*/
if( !r )
if( !r ) {
int i;
for( i = 0; i < VIPS_NUMBER( built_in ); i++ )
if( (r = fn( built_in[i], a, NULL )) )
return( r );
}
return( r );
}
@ -1089,8 +1091,6 @@ add_hist( im_function *fn, im_object *vargv, int argc, char **argv )
static int
dispatch_function( im_function *fn, im_object *vargv, int argc, char **argv )
{
int i;
/* Init memory from command line arguments.
*/
if( build_args( fn, vargv, argc, argv ) )
@ -1107,7 +1107,9 @@ dispatch_function( im_function *fn, im_object *vargv, int argc, char **argv )
* - create a region on the input, closed by a
* close callback on the output image
*/
if( fn->flags & IM_FN_PIO )
if( fn->flags & IM_FN_PIO ) {
int i;
for( i = 0; i < fn->argc; i++ ) {
im_type_desc *type = fn->argv[i].desc;
@ -1116,6 +1118,7 @@ dispatch_function( im_function *fn, im_object *vargv, int argc, char **argv )
if( note_dependencies( fn, vargv, i ) )
return( -1 );
}
}
/* Call function.
*/

View File

@ -317,13 +317,13 @@ vips_wrap7_object_set_property( GObject *gobject,
vips__argument_table_lookup( oclass->argument_table, pspec );
VipsArgumentInstance *argument_instance =
vips__argument_get_instance( argument_class, object );
VipsWrap7 *wrap7 = VIPS_WRAP7( gobject );
VipsWrap7Class *class = VIPS_WRAP7_GET_CLASS( wrap7 );
int i = argument_class->offset;
im_arg_desc *arg = &class->fn->argv[i];
im_type_desc *type = arg->desc;
im_arg_type vt = type->type;
int i;
im_arg_desc *arg;
im_type_desc *type;
im_arg_type vt;
g_assert( argument_instance );
@ -333,6 +333,11 @@ vips_wrap7_object_set_property( GObject *gobject,
return;
}
i = argument_class->offset;
arg = &class->fn->argv[i];
type = arg->desc;
vt = type->type;
#ifdef DEBUG
{
char *str_value;
@ -418,13 +423,13 @@ vips_wrap7_object_get_property( GObject *gobject,
vips__argument_table_lookup( class->argument_table, pspec );
VipsArgumentInstance *argument_instance =
vips__argument_get_instance( argument_class, object );
VipsWrap7 *wrap7 = VIPS_WRAP7( gobject );
VipsWrap7Class *wclass = VIPS_WRAP7_GET_CLASS( wrap7 );
int i = argument_class->offset;
im_arg_desc *arg = &wclass->fn->argv[i];
im_type_desc *type = arg->desc;
im_arg_type vt = type->type;
int i;
im_arg_desc *arg;
im_type_desc *type;
im_arg_type vt;
if( !argument_class ) {
G_OBJECT_WARN_INVALID_PROPERTY_ID( gobject,
@ -432,6 +437,11 @@ vips_wrap7_object_get_property( GObject *gobject,
return;
}
i = argument_class->offset;
arg = &wclass->fn->argv[i];
type = arg->desc;
vt = type->type;
g_assert( ((VipsArgument *) argument_class)->pspec == pspec );
if( !argument_instance->assigned ) {

View File

@ -172,7 +172,7 @@ read_double( FILE *fp, const char whitemap[256], const char sepmap[256],
if( ch == '"' ) {
(void) fgetc( fp );
ch = skip_to_quote( fp );
(void) skip_to_quote( fp );
ch = fgetc( fp );
}
else if( !sepmap[ch] &&

View File

@ -1161,8 +1161,7 @@ vips_foreign_save_dz_build( VipsObject *object )
vips_area_unref( background );
}
if( dz->overlap >= dz->tile_size ||
dz->overlap >= dz->tile_size ) {
if( dz->overlap >= dz->tile_size ) {
vips_error( "dzsave",
"%s", _( "overlap must be less than tile "
"width and height" ) ) ;

View File

@ -355,13 +355,14 @@ static void
vips_foreign_summary_class( VipsObjectClass *object_class, VipsBuf *buf )
{
VipsForeignClass *class = VIPS_FOREIGN_CLASS( object_class );
const char **p;
VIPS_OBJECT_CLASS( vips_foreign_parent_class )->
summary_class( object_class, buf );
vips_buf_appends( buf, " " );
if( class->suffs ) {
const char **p;
vips_buf_appends( buf, "(" );
for( p = class->suffs; *p; p++ ) {
vips_buf_appendf( buf, "%s", *p );

View File

@ -104,11 +104,12 @@ int
vips__openslide_isslide( const char *filename )
{
openslide_t *osr;
const char *vendor;
int ok;
ok = 0;
if( (osr = openslide_open( filename )) ) {
const char *vendor;
/* Generic tiled tiff images can be opened by openslide as
* well. Only offer to load this file if it's not a generic
* tiff since we want vips_tiffload() to handle these.
@ -278,9 +279,7 @@ int
vips__openslide_read_header( const char *filename, VipsImage *out,
int level, char *associated )
{
ReadSlide *rslide;
if( !(rslide = readslide_new( filename, out, level, associated )) )
if( !readslide_new( filename, out, level, associated ) )
return( -1 );
return( 0 );

View File

@ -81,9 +81,7 @@
static void
skip_line( FILE *fp )
{
int ch;
while( (ch = fgetc( fp )) != '\n' )
while( fgetc( fp ) != '\n' )
;
}

View File

@ -89,11 +89,12 @@ compare( const void *a, const void *b )
static void
free_state( State *state )
{
int i;
if( state->data ) {
int i;
if( state->data )
for( i = 0; i < state->input->ysize; i++ )
IM_FREE( state->data[i] );
}
IM_FREE( state->data );
IM_FREE( state->buf );

View File

@ -80,21 +80,18 @@ normalise( IMAGE *in, IMAGE *out )
return( -1 );
}
else if( vips_bandfmt_isint( in->BandFmt ) ) {
IMAGE *t1;
double min;
/* Move min up to 0.
*/
if( !(t1 = im_open_local( out, "im_histplot", "p" )) ||
im_min( in, &min ) ||
im_lintra( 1.0, in, -min, t1 ) )
if( im_min( in, &min ) ||
im_lintra( 1.0, in, -min, out ) )
return( -1 );
}
else {
/* Float image: scale min--max to 0--any. Output square
* graph.
*/
IMAGE *t1;
DOUBLEMASK *stats;
double min, max;
int any;
@ -110,9 +107,8 @@ normalise( IMAGE *in, IMAGE *out )
max = VIPS_MASK( stats, 1, 0 );
im_free_dmask( stats );
if( !(t1 = im_open_local( out, "im_histplot", "p" )) ||
im_lintra( any / (max - min), in,
-min * any / (max - min), out ) )
if( im_lintra( any / (max - min), in,
-min * any / (max - min), out ) )
return( -1 );
}

View File

@ -1,286 +1,286 @@
/* base64.c -- Encode/decode integers in base64 format
* Created: Mon Sep 23 16:55:12 1996 by faith@dict.org
* Revised: Sat Mar 30 12:02:36 2002 by faith@dict.org
* Copyright 1996, 2002 Rickard E. Faith (faith@dict.org)
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library General Public License as published
* by the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
/* base64.c -- Encode/decode integers in base64 format
* Created: Mon Sep 23 16:55:12 1996 by faith@dict.org
* Revised: Sat Mar 30 12:02:36 2002 by faith@dict.org
* Copyright 1996, 2002 Rickard E. Faith (faith@dict.org)
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library General Public License as published
* by the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*
* \section{Base-64 Routines}
*
* \intro These routines use the 64-character subset of International
* Alphabet IA5 discussed in RFC 1421 (printeable encoding) and RFC 1522
* (base64 MIME).
*
Value Encoding Value Encoding Value Encoding Value Encoding
0 A 17 R 34 i 51 z
1 B 18 S 35 j 52 0
2 C 19 T 36 k 53 1
3 D 20 U 37 l 54 2
4 E 21 V 38 m 55 3
5 F 22 W 39 n 56 4
6 G 23 X 40 o 57 5
7 H 24 Y 41 p 58 6
8 I 25 Z 42 q 59 7
9 J 26 a 43 r 60 8
10 K 27 b 44 s 61 9
11 L 28 c 45 t 62 +
12 M 29 d 46 u 63 /
13 N 30 e 47 v
14 O 31 f 48 w (pad) =
15 P 32 g 49 x
16 Q 33 h 50 y
*
*/
/*
Hacked for VIPS ... does any length object (not just ints), formats
base64 into 70 character lines, output to a malloc'd buffer.
VIPS uses this to write BLOBs (like ICC profiles, for example) to the
XML that follows an image.
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
25/3/11
- move to vips_ namespace
*/
/*
#define DEBUG
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <vips/vips.h>
#include "base64.h"
static unsigned char b64_list[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
#define XX 100
static unsigned char b64_index[256] = {
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,62, XX,XX,XX,63,
52,53,54,55, 56,57,58,59, 60,61,XX,XX, XX,XX,XX,XX,
XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
15,16,17,18, 19,20,21,22, 23,24,25,XX, XX,XX,XX,XX,
XX,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
41,42,43,44, 45,46,47,48, 49,50,51,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
};
/* Read (up to) 3 bytes from in. Be careful about byte ordering :-/ we need to
* end up with in[2] in the bottom few bits.
*/
static int
read24( const unsigned char *in, size_t remaining )
{
int bits;
int i;
bits = 0;
for( i = 0; i < 3; i++ ) {
bits <<= 8;
if( remaining > 0 ) {
bits |= in[i];
remaining -= 1;
}
}
return( bits );
}
/* Output (up to) 24 bits as four base64 chars. Pad with '=' characters.
*/
static void
encode24( char *p, int bits, size_t remaining )
{
int i;
for( i = 0; i < 4; i++ ) {
if( remaining <= 0 )
p[i] = '=';
else {
/* Take the top 6 bits of 24.
*/
p[i] = b64_list[(bits >> 18) & 63];
bits <<= 6;
remaining -= 6;
}
}
}
/* Output to a malloc'd buffer, NULL on error. Try to be simple and reliable,
* rather than quick.
*/
char *
vips__b64_encode( const unsigned char *data, size_t data_length )
{
/* Worst case: 1.333 chars per byte, plus 10% for extra carriage
* returns and stuff. And the \n\0 at the end.
*/
const size_t output_data_length = data_length * 44 / 30 + 2;
char *buffer;
char *p;
size_t i;
int cursor;
if( data_length <= 0 ) {
vips_error( "vips__b64_encode", "%s", _( "too little data" ) );
return( NULL );
}
if( output_data_length > 1024 * 1024 ) {
/* We shouldn't really be used for large amounts of data.
*/
vips_error( "vips__b64_encode", "%s", _( "too much data" ) );
return( NULL );
}
if( !(buffer = vips_malloc( NULL, output_data_length )) )
return( NULL );
p = buffer;
*p++ = '\n';
cursor = 0;
for( i = 0; i < data_length; i += 3 ) {
size_t remaining = data_length - i;
int bits;
bits = read24( data + i, remaining );
encode24( p, bits, remaining * 8 );
p += 4;
cursor += 4;
if( cursor >= 76 ) {
*p++ = '\n';
cursor = 0;
}
}
if( cursor > 0 )
*p++ = '\n';
*p++ = '\0';
#ifdef DEBUG
{
unsigned int total;
/* Calculate a very simple checksum for debugging.
*/
for( total = 0, i = 0; i < data_length; i++ )
total += data[i];
printf( "vips__b64_encode: length = %d, checksum 0x%x\n",
data_length, total & 0xffff );
}
#endif /*DEBUG*/
return( buffer );
}
/* Decode base64 back to binary in a malloc'd buffer. NULL on error.
*/
unsigned char *
vips__b64_decode( const char *buffer, size_t *data_length )
{
const size_t buffer_length = strlen( buffer );
/* Worst case.
*/
const size_t output_data_length = buffer_length * 3 / 4;
unsigned char *data;
unsigned char *p;
unsigned int bits;
int nbits;
size_t i;
if( output_data_length > 1024 * 1024 ) {
/* We shouldn't really be used for large amounts of data.
*/
vips_error( "vips__b64_decode", "%s", _( "too much data" ) );
return( NULL );
}
if( !(data = vips_malloc( NULL, output_data_length )) )
return( NULL );
p = data;
bits = 0;
nbits = 0;
for( i = 0; i < buffer_length; i++ ) {
unsigned int val;
if( (val = b64_index[(int) buffer[i]]) != XX ) {
bits <<= 6;
bits |= val;
nbits += 6;
if( nbits >= 8 ) {
*p++ = (bits >> (nbits - 8)) & 0xff;
nbits -= 8;
}
}
}
g_assert( (size_t) (p - data) < output_data_length );
if( data_length )
*data_length = p - data;
#ifdef DEBUG
{
unsigned int total;
/* Calculate a very simple checksum for debugging.
*/
for( total = 0, i = 0; i < p - data; i++ )
total += data[i];
printf( "vips__b64_decode: length = %d, checksum 0x%x\n",
p - data, total & 0xffff );
}
#endif /*DEBUG*/
return( data );
}
*
* \section{Base-64 Routines}
*
* \intro These routines use the 64-character subset of International
* Alphabet IA5 discussed in RFC 1421 (printeable encoding) and RFC 1522
* (base64 MIME).
*
Value Encoding Value Encoding Value Encoding Value Encoding
0 A 17 R 34 i 51 z
1 B 18 S 35 j 52 0
2 C 19 T 36 k 53 1
3 D 20 U 37 l 54 2
4 E 21 V 38 m 55 3
5 F 22 W 39 n 56 4
6 G 23 X 40 o 57 5
7 H 24 Y 41 p 58 6
8 I 25 Z 42 q 59 7
9 J 26 a 43 r 60 8
10 K 27 b 44 s 61 9
11 L 28 c 45 t 62 +
12 M 29 d 46 u 63 /
13 N 30 e 47 v
14 O 31 f 48 w (pad) =
15 P 32 g 49 x
16 Q 33 h 50 y
*
*/
/*
Hacked for VIPS ... does any length object (not just ints), formats
base64 into 70 character lines, output to a malloc'd buffer.
VIPS uses this to write BLOBs (like ICC profiles, for example) to the
XML that follows an image.
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
25/3/11
- move to vips_ namespace
*/
/*
#define DEBUG
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <vips/vips.h>
#include "base64.h"
static unsigned char b64_list[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
#define XX 100
static unsigned char b64_index[256] = {
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,62, XX,XX,XX,63,
52,53,54,55, 56,57,58,59, 60,61,XX,XX, XX,XX,XX,XX,
XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
15,16,17,18, 19,20,21,22, 23,24,25,XX, XX,XX,XX,XX,
XX,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
41,42,43,44, 45,46,47,48, 49,50,51,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
};
/* Read (up to) 3 bytes from in. Be careful about byte ordering :-/ we need to
* end up with in[2] in the bottom few bits.
*/
static int
read24( const unsigned char *in, size_t remaining )
{
int bits;
int i;
bits = 0;
for( i = 0; i < 3; i++ ) {
bits <<= 8;
if( remaining > 0 ) {
bits |= in[i];
remaining -= 1;
}
}
return( bits );
}
/* Output (up to) 24 bits as four base64 chars. Pad with '=' characters.
*/
static void
encode24( char *p, int bits, size_t remaining )
{
int i;
for( i = 0; i < 4; i++ ) {
if( remaining == 0 )
p[i] = '=';
else {
/* Take the top 6 bits of 24.
*/
p[i] = b64_list[(bits >> 18) & 63];
bits <<= 6;
remaining -= 6;
}
}
}
/* Output to a malloc'd buffer, NULL on error. Try to be simple and reliable,
* rather than quick.
*/
char *
vips__b64_encode( const unsigned char *data, size_t data_length )
{
/* Worst case: 1.333 chars per byte, plus 10% for extra carriage
* returns and stuff. And the \n\0 at the end.
*/
const size_t output_data_length = data_length * 44 / 30 + 2;
char *buffer;
char *p;
size_t i;
int cursor;
if( data_length == 0 ) {
vips_error( "vips__b64_encode", "%s", _( "too little data" ) );
return( NULL );
}
if( output_data_length > 1024 * 1024 ) {
/* We shouldn't really be used for large amounts of data.
*/
vips_error( "vips__b64_encode", "%s", _( "too much data" ) );
return( NULL );
}
if( !(buffer = vips_malloc( NULL, output_data_length )) )
return( NULL );
p = buffer;
*p++ = '\n';
cursor = 0;
for( i = 0; i < data_length; i += 3 ) {
size_t remaining = data_length - i;
int bits;
bits = read24( data + i, remaining );
encode24( p, bits, remaining * 8 );
p += 4;
cursor += 4;
if( cursor >= 76 ) {
*p++ = '\n';
cursor = 0;
}
}
if( cursor > 0 )
*p++ = '\n';
*p++ = '\0';
#ifdef DEBUG
{
unsigned int total;
/* Calculate a very simple checksum for debugging.
*/
for( total = 0, i = 0; i < data_length; i++ )
total += data[i];
printf( "vips__b64_encode: length = %u, checksum 0x%x\n",
data_length, total & 0xffff );
}
#endif /*DEBUG*/
return( buffer );
}
/* Decode base64 back to binary in a malloc'd buffer. NULL on error.
*/
unsigned char *
vips__b64_decode( const char *buffer, size_t *data_length )
{
const size_t buffer_length = strlen( buffer );
/* Worst case.
*/
const size_t output_data_length = buffer_length * 3 / 4;
unsigned char *data;
unsigned char *p;
unsigned int bits;
int nbits;
size_t i;
if( output_data_length > 1024 * 1024 ) {
/* We shouldn't really be used for large amounts of data.
*/
vips_error( "vips__b64_decode", "%s", _( "too much data" ) );
return( NULL );
}
if( !(data = vips_malloc( NULL, output_data_length )) )
return( NULL );
p = data;
bits = 0;
nbits = 0;
for( i = 0; i < buffer_length; i++ ) {
unsigned int val;
if( (val = b64_index[(int) buffer[i]]) != XX ) {
bits <<= 6;
bits |= val;
nbits += 6;
if( nbits >= 8 ) {
*p++ = (bits >> (nbits - 8)) & 0xff;
nbits -= 8;
}
}
}
g_assert( (size_t) (p - data) < output_data_length );
if( data_length )
*data_length = p - data;
#ifdef DEBUG
{
unsigned int total;
/* Calculate a very simple checksum for debugging.
*/
for( total = 0, i = 0; i < p - data; i++ )
total += data[i];
printf( "vips__b64_decode: length = %d, checksum 0x%x\n",
p - data, total & 0xffff );
}
#endif /*DEBUG*/
return( data );
}

View File

@ -509,13 +509,12 @@ vips_allocate_input_array( VipsImage *image, ... )
{
va_list ap;
VipsImage **ar;
VipsImage *im;
int i, n;
/* Count input images.
*/
va_start( ap, image );
for( n = 0; (im = va_arg( ap, VipsImage * )); n++ )
for( n = 0; va_arg( ap, VipsImage * ); n++ )
;
va_end( ap );

View File

@ -468,7 +468,8 @@ vips_image_sanity( VipsObject *object, VipsBuf *buf )
image->dtype > VIPS_IMAGE_PARTIAL ||
image->dhint > VIPS_DEMAND_STYLE_ANY )
vips_buf_appends( buf, "bad enum\n" );
if( image->Xres < 0 || image->Xres < 0 )
if( image->Xres < 0 ||
image->Yres < 0 )
vips_buf_appends( buf, "bad resolution\n" );
}

View File

@ -636,7 +636,7 @@ find_file( const char *name )
static const char *
guess_prefix( const char *argv0, const char *name )
{
char *prefix;
char *prefix;
/* Try to guess from argv0.
*/

View File

@ -230,10 +230,11 @@ vips_tracked_free( void *s )
if( vips_tracked_allocs <= 0 )
vips_warn( "vips_tracked",
"%s", _( "vips_free: too many frees" ) );
vips_tracked_mem -= size;
if( vips_tracked_mem < 0 )
if( vips_tracked_mem < size )
vips_warn( "vips_tracked",
"%s", _( "vips_free: too much free" ) );
vips_tracked_mem -= size;
vips_tracked_allocs -= 1;
g_mutex_unlock( vips_tracked_mutex );

View File

@ -848,7 +848,6 @@ static void
tile_copy( Tile *tile, VipsRegion *to )
{
VipsRect ovlap;
int y;
/* Find common pixels.
*/
@ -861,6 +860,8 @@ tile_copy( Tile *tile, VipsRegion *to )
if( tile->painted && !tile->region->invalid ) {
int len = VIPS_IMAGE_SIZEOF_PEL( to->im ) * ovlap.width;
int y;
VIPS_DEBUG_MSG( "tile_copy: "
"copying calculated pixels for %p %dx%d\n",
tile, tile->area.left, tile->area.top );

View File

@ -791,12 +791,16 @@ vips__file_read( FILE *fp, const char *filename, unsigned int *length_out )
len = 0;
size = 0;
do {
char *str2;
size += 1024;
if( !(str = realloc( str, size )) ) {
if( !(str2 = realloc( str, size )) ) {
free( str );
vips_error( "vips__file_read",
"%s", _( "out of memory" ) );
return( NULL );
}
str = str2;
/* -1 to allow space for an extra NULL we add later.
*/
@ -1601,7 +1605,7 @@ vips__parse_size( const char *size_string )
guint64 size;
int n;
int i, j;
int i;
char *unit;
/* An easy way to alloc a buffer large enough.
@ -1610,6 +1614,8 @@ vips__parse_size( const char *size_string )
n = sscanf( size_string, "%d %s", &i, unit );
size = i;
if( n > 1 ) {
int j;
for( j = 0; j < VIPS_NUMBER( units ); j++ )
if( tolower( unit[0] ) == units[j].unit ) {
size *= units[j].multiplier;

View File

@ -80,7 +80,7 @@ im_profile( IMAGE *in, IMAGE *out, int dir )
{
int sz;
unsigned short *buf;
int x, y, b;
int x, y;
/* If in is not uchar, do (!=0) to make a uchar image.
*/
@ -149,6 +149,8 @@ im_profile( IMAGE *in, IMAGE *out, int dir )
for( y = 0; y < in->Ysize; y++ ) {
VipsPel *p = IM_IMAGE_ADDR( in, 0, y );
int b;
for( b = 0; b < in->Bands; b++ ) {
VipsPel *p1;

View File

@ -104,11 +104,12 @@ rank_stop( void *vseq, void *a, void *b )
RankSequence *seq = (RankSequence *) vseq;
Rank *rank = (Rank *) b;
int i;
if( seq->ir ) {
int i;
if( seq->ir )
for( i = 0; i < rank->n; i++ )
IM_FREEF( im_region_free, seq->ir[i] );
}
return( 0 );
}

View File

@ -712,7 +712,6 @@ static JoinNode *
find_root( SymbolTable *st )
{
JoinNode *root;
JoinNode *notroot;
/* Clean the table, then scan it, setting all pointed-to nodes dirty.
*/
@ -736,7 +735,7 @@ find_root( SymbolTable *st )
* more than one root.
*/
root->dirty = 1;
if( (notroot = im__map_table( st, is_root, NULL, NULL )) ) {
if( im__map_table( st, is_root, NULL, NULL ) ) {
im_error( "im_global_balance",
"%s", _( "more than one root" ) );
return( NULL );