From 951dc0f83e3a655e9dc2091ef989f55332c86dd6 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 21 Nov 2011 18:09:28 +0000 Subject: [PATCH] fail for too many args on the CLI --- TODO | 11 ++++++----- libvips/iofuncs/object.c | 9 ++++++++- libvips/iofuncs/operation.c | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index 94002cda..3ac33821 100644 --- a/TODO +++ b/TODO @@ -1,12 +1,13 @@ -- text vips_complexform() +- imagevec in can be non-NULL if the images do not exist -- try + not enough to check that imagevec is non-NULL, have to check all images too, + argh - $ vips bandjoin a b c + test with - copies a on top of b, ignores c ... argh!! + $ vips bandjoin a b - need to fail if there are unused arguments + where 'a' does not exist diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index 74a1b05e..90bce3ad 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -224,10 +224,17 @@ vips_object_print_name( VipsObject *object ) gboolean vips_object_sanity( VipsObject *object ) { - VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object ); + VipsObjectClass *class; char str[1000]; VipsBuf buf = VIPS_BUF_STATIC( str ); + if( !object ) { + printf( "vips_object_sanity: null object\n" ); + + return( FALSE ); + } + + class = VIPS_OBJECT_GET_CLASS( object ); class->sanity( object, &buf ); if( !vips_buf_is_empty( &buf ) ) { printf( "sanity failure: " ); diff --git a/libvips/iofuncs/operation.c b/libvips/iofuncs/operation.c index 644a1bff..72a99db7 100644 --- a/libvips/iofuncs/operation.c +++ b/libvips/iofuncs/operation.c @@ -909,6 +909,23 @@ vips_call_argv( VipsOperation *operation, int argc, char **argv ) (void) vips_argument_map( VIPS_OBJECT( operation ), vips_call_argv_input, &call, NULL ); + /* Any unused arguments? We must fail. Consider eg. "vips bandjoin a b + * c". This would overwrite b with a and ignore c, potentially + * disasterous. + */ + if( argc > call.i ) { + vips_error( VIPS_OBJECT_GET_CLASS( operation )->nickname, + "%s", _( "too many arguments" ) ); + + /* We must unref any output objects, they are holding refs to + * the operation. + */ + (void) vips_argument_map( VIPS_OBJECT( operation ), + vips_call_argv_unref_output, NULL, NULL ); + + return( -1 ); + } + if( vips_object_build( VIPS_OBJECT( operation ) ) ) { /* We must unref any output objects, they are holding refs to * the operation.