From 2f724b60ce0a8323dd4173b4651661d04b0c94f9 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 24 Feb 2014 02:17:41 +0100 Subject: Check parameter count before using argv, report syntax and errors --- src/export/map_coords.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/export/map_coords.c b/src/export/map_coords.c index b46f1cf..93c858f 100644 --- a/src/export/map_coords.c +++ b/src/export/map_coords.c @@ -18,13 +18,14 @@ int qsort_cmp( const void *a, const void *b ) int main( int argc, char ** args ) { - MAP coords = map_file( args[1], 1 ); - int i, l, lines; + MAP coords; char *p, **offsets, *input = malloc(1024); ssize_t ll; - size_t input_length = 1024; + size_t i, l, lines, input_length = 1024; - if( !coords ) exit( 111 ); + if( argc != 2 ) { fprintf( stderr, "Syntax: printf %%s\\t%%s\\t%%s | %s \n", args[0] ); exit(111); } + coords = map_file( args[1], 1 ); + if( !coords || !input ) { fprintf( stderr, "Error allocating resources\n" );exit( 111 ); } p = (char *)coords->addr; for ( i=0, lines=0; isize; ++i ) if( p[i] == 0x00 ) -- cgit v1.2.3