diff options
author | Dirk Engling <erdgeist@erdgeist.org> | 2014-02-24 02:17:41 +0100 |
---|---|---|
committer | Dirk Engling <erdgeist@erdgeist.org> | 2014-02-24 02:17:41 +0100 |
commit | 2f724b60ce0a8323dd4173b4651661d04b0c94f9 (patch) | |
tree | e2e9d712acc22bfc2ee4688830f9e3ae46707d21 | |
parent | 86a9ddecb6e3dc0063ea2cc56576ba7c7934b400 (diff) |
Check parameter count before using argv, report syntax and errors
-rw-r--r-- | src/export/map_coords.c | 9 |
1 files 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 ) | |||
18 | 18 | ||
19 | int main( int argc, char ** args ) | 19 | int main( int argc, char ** args ) |
20 | { | 20 | { |
21 | MAP coords = map_file( args[1], 1 ); | 21 | MAP coords; |
22 | int i, l, lines; | ||
23 | char *p, **offsets, *input = malloc(1024); | 22 | char *p, **offsets, *input = malloc(1024); |
24 | ssize_t ll; | 23 | ssize_t ll; |
25 | size_t input_length = 1024; | 24 | size_t i, l, lines, input_length = 1024; |
26 | 25 | ||
27 | if( !coords ) exit( 111 ); | 26 | if( argc != 2 ) { fprintf( stderr, "Syntax: printf %%s\\t%%s\\t%%s <zipcode> <streetname> <housenumber> | %s <coords_file>\n", args[0] ); exit(111); } |
27 | coords = map_file( args[1], 1 ); | ||
28 | if( !coords || !input ) { fprintf( stderr, "Error allocating resources\n" );exit( 111 ); } | ||
28 | p = (char *)coords->addr; | 29 | p = (char *)coords->addr; |
29 | for ( i=0, lines=0; i<coords->size; ++i ) | 30 | for ( i=0, lines=0; i<coords->size; ++i ) |
30 | if( p[i] == 0x00 ) | 31 | if( p[i] == 0x00 ) |