From 6922e6678d247af8c9d63df7a3db2fe83c328f7e Mon Sep 17 00:00:00 2001
From: Dirk Engling <erdgeist@erdgeist.org>
Date: Tue, 25 Feb 2014 00:30:31 +0100
Subject: Get rid of warnings uncovered with clangs -Weverything

---
 src/export/extract_version_1.c | 20 ++++++-------
 src/export/extract_version_2.c | 65 +++++++++++++++++++++---------------------
 src/export/extract_version_3.c |  7 +++--
 src/export/map_coords.c        |  4 +--
 src/export/mystdlib.c          |  4 +--
 src/export/mystdlib.h          |  5 ++--
 src/export/split_version_2.c   | 16 +++++------
 7 files changed, 60 insertions(+), 61 deletions(-)

(limited to 'src')

diff --git a/src/export/extract_version_1.c b/src/export/extract_version_1.c
index 987c38f..bbe900a 100644
--- a/src/export/extract_version_1.c
+++ b/src/export/extract_version_1.c
@@ -7,7 +7,7 @@
 
 #include "mystdlib.h"
 
-static char xlat_table[] = {
+static uint8_t xlat_table[] = {
   0x00, 0x09, 0x02, 0x03, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
   0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
   0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
@@ -18,7 +18,7 @@ static char xlat_table[] = {
   0xfb, 0xf9, 0xff, 0xd6, 0xdc, 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xdf, 0x5b, 0x5c, 0x5d, 0x60
 };
 
-static char cp437_to_iso8859_1_table[] = {
+static uint8_t cp437_to_iso8859_1_table[] = {
   0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
   0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
   0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
@@ -42,7 +42,7 @@ static struct {
   char * zip;
 } g_state;
 
-void decode_7bit_string( uint8_t const *source, uint8_t *dest )
+static void decode_7bit_string( uint8_t const *source, uint8_t *dest )
 {
   uint16_t acc = 0, acc_bits = 0;
   while( 1 )
@@ -55,7 +55,7 @@ again:
   }
 }
 
-void split_to_files( uint8_t *entries, int num_entries )
+static void split_to_files( uint8_t *entries, int num_entries )
 {
   int entry = 0, column;
   char *e = (char*)entries;
@@ -74,7 +74,7 @@ void split_to_files( uint8_t *entries, int num_entries )
       if( end ) {
         *end = '\n';
         if( column == 9 && *e >= '0' && *e <= '9' ) write( g_state.outfiles[column+1], "0", 1 ); /* Augment Vorwahl */
-        write( g_state.outfiles[column+1], e, end - e + 1);
+        write( g_state.outfiles[column+1], e, (size_t)(end - e + 1) );
         e = end + 1;
       } else
         dprintf( g_state.outfiles[column+1], "%s\n", e);
@@ -82,7 +82,7 @@ void split_to_files( uint8_t *entries, int num_entries )
   }
 }
 
-void act_on_record( uint8_t *file, int flag, uint8_t *page, uint16_t record_off )
+static void act_on_record( uint8_t *file, int flag, uint8_t *page, uint16_t record_off )
 {
   uint8_t outbuf[8192], *out_dest = outbuf, *record;
   int     num_entries;
@@ -116,7 +116,7 @@ void act_on_record( uint8_t *file, int flag, uint8_t *page, uint16_t record_off
 }
 
 /* Page is always 0x2000 */
-void act_on_page( uint8_t *file, uint8_t *page, int page_nr )
+static void act_on_page( uint8_t *file, uint8_t *page, int page_nr )
 {
   int record, flag  = page[0];
   int blob_len      = *(uint16_t*)(page + 0x2);
@@ -131,17 +131,17 @@ void act_on_page( uint8_t *file, uint8_t *page, int page_nr )
       act_on_record( file, flag, page + 0xe, recs[record] );
 }
 
-void act_on_file( uint8_t *file )
+static void act_on_file( uint8_t *file )
 {
   int page, num_pages = *(uint16_t*)(file+0x40);
-  int num_records     = *(uint32_t*)(file+0x42);
+  uint32_t num_records= *(uint32_t*)(file+0x42);
   char *gasse         = (char *)file + 0x8e;
   char *ort           = gasse + 1 + strlen(gasse);
   char *zip           = ort   + 1 + strlen(ort);
   char *vorwahl       = zip   + 1 + strlen(zip);
   char ort_conv[1024]; int i;
 
-  for(i=0; ort[i]; ++i ) ort_conv[i] = cp437_to_iso8859_1_table[((uint8_t*)ort)[i]]; ort_conv[i] = 0;
+  for(i=0; ort[i]; ++i ) ort_conv[i] = (char)cp437_to_iso8859_1_table[((uint8_t*)ort)[i]]; ort_conv[i] = 0;
   /* printf( "Working on a %04d page and %06d records file, city: %4s %-32s with prefix %s\n", num_pages, num_records, zip, ort_conv, vorwahl ); */
   (void)num_records; /* silence warning about unused variable */
 
diff --git a/src/export/extract_version_2.c b/src/export/extract_version_2.c
index 6686dca..c4914a7 100644
--- a/src/export/extract_version_2.c
+++ b/src/export/extract_version_2.c
@@ -28,10 +28,9 @@ static uint8_t mantra_in[] = { 0x68, 0x35, 0x2d, 0x6c };
 
 int main( int args, char **argv )
 {
-  int      filenum = 0, run = 1;
-  size_t   offset = 0, reported = 0, enc_len = 32;
-  ssize_t  oldoffset = -1;
-  uint8_t  mantra[4], id0, id5, *mappedfile;
+  int      filenum = 0, run = 1, first_run = 1;
+  size_t   offset = 0, old_offset = 0, reported = 0, enc_len = 32;
+  uint8_t  mantra[4], id0, id5, *mapped_file;
   MAP      map;
 
   /* For streets we do have a enc_len of 34 */
@@ -39,11 +38,11 @@ int main( int args, char **argv )
     switch( getopt( args, argv, ":e:" ) ) {
       case -1 : run = 0; break;
       case 'e':
-        enc_len = atol( optarg );
+        enc_len = strtoul( optarg, 0, 0 );
         break;
       default:
-        fputs( "Syntax: %s [-e encrypted_length (default: 32, for streets 34 or 0)] path-to-teiln.dat", stderr ); exit( 1 );
-        break;
+        fputs( "Syntax: %s [-e encrypted_length (default: 32, for streets 34 or 0)] path-to-teiln.dat", stderr );
+        exit( 1 );
     }
   }
   run = 1;
@@ -52,25 +51,25 @@ int main( int args, char **argv )
     { fputs( "Missing filename.", stderr ); exit( 1 ); }
 
   map = map_file( argv[optind], 1 );
-  mappedfile = map->addr;
+  mapped_file = map->addr;
 
-  mantra[0] = mantra_in[0] ^ mappedfile[4];
-  mantra[1] = mantra_in[1] ^ mappedfile[5];
-  mantra[2] = mantra_in[2] ^ mappedfile[2];
-  mantra[3] = mantra_in[3] ^ mappedfile[3];
+  mantra[0] = mantra_in[0] ^ mapped_file[4];
+  mantra[1] = mantra_in[1] ^ mapped_file[5];
+  mantra[2] = mantra_in[2] ^ mapped_file[2];
+  mantra[3] = mantra_in[3] ^ mapped_file[3];
 
-  id0 = mappedfile[0];
-  id5 = mappedfile[5];
+  id0 = mapped_file[0];
+  id5 = mapped_file[5];
 
   while( run )
   {
     while( ( offset < map->size ) && (
-           ( mappedfile[ offset + 0 ] != id0                         ) ||
-           ( mappedfile[ offset + 2 ] != ( '-'          ^ mantra[2] )) ||
-           ( mappedfile[ offset + 3 ] != ( 'l'          ^ mantra[3] )) ||
-           ( mappedfile[ offset + 4 ] != ( 'h'          ^ mantra[0] )) ||
-           ( mappedfile[ offset + 5 ] != id5                         ) ||
-           ( mappedfile[ offset + 6 ] != ( '-'          ^ mantra[2] ))
+           ( mapped_file[ offset + 0 ] != id0                         ) ||
+           ( mapped_file[ offset + 2 ] != ( '-'          ^ mantra[2] )) ||
+           ( mapped_file[ offset + 3 ] != ( 'l'          ^ mantra[3] )) ||
+           ( mapped_file[ offset + 4 ] != ( 'h'          ^ mantra[0] )) ||
+           ( mapped_file[ offset + 5 ] != id5                         ) ||
+           ( mapped_file[ offset + 6 ] != ( '-'          ^ mantra[2] ))
           ) ) offset++;
 
     // printf( "Found an appropriate offset at: %zd\n", offset );
@@ -85,11 +84,12 @@ int main( int args, char **argv )
     if( offset == map->size )
         run = 0;
 
-    if( oldoffset != -1 )
+    if( !first_run )
     {
-        uint8_t *mf = mappedfile + oldoffset, df[128];
+        uint8_t *mf = mapped_file + old_offset, df[128];
         size_t filename_len, header_len, i;
-        char filename_template[32], filename[32];
+        int    fh;
+        char   filename[32];
 
         /* De-"crypt" obfuscation to our header copy */
         for( i=0; i<enc_len; ++i)
@@ -104,26 +104,25 @@ int main( int args, char **argv )
            df[i] = mf[i];
 
         /* Make up new sequental file name */
-        snprintf( filename_template, sizeof(filename_template), "%%0%dd.lha", (int)filename_len );
-        snprintf( filename, sizeof( filename ), filename_template, filenum++ );
+        snprintf( filename, sizeof(filename), "%0*d.lha", (int)filename_len, filenum++ );
         memcpy( ((uint8_t*)df) + 22, filename, filename_len);
 
         /* Recalculate checksum with new file name */
         df[1] = 0; for( i=2; i<header_len; ++i) df[1] += df[i];
 
         /* Open file and dump our de-"crypted" header and then rest of file */
-        i = open( filename, O_CREAT | O_TRUNC | O_WRONLY, 0644 );
+        fh = open( filename, O_CREAT | O_TRUNC | O_WRONLY, 0644 );
         if( enc_len > header_len ) {
-            write( i, df, enc_len );
-            write( i, mf + enc_len, offset - oldoffset - enc_len );
+            write( fh, df, enc_len );
+            write( fh, mf + enc_len, offset - old_offset - enc_len );
         } else {
-            write( i, df, header_len );
-            write( i, mf + header_len, offset - oldoffset - header_len );
+            write( fh, df, header_len );
+            write( fh, mf + header_len, offset - old_offset - header_len );
         }
-        close( i );
+        close( fh );
     }
-    oldoffset = offset;
-    offset++;
+    first_run = 0;
+    old_offset = offset++;
   }
 
   unmap_file( &map );
diff --git a/src/export/extract_version_3.c b/src/export/extract_version_3.c
index 19df167..cbe0c7e 100644
--- a/src/export/extract_version_3.c
+++ b/src/export/extract_version_3.c
@@ -19,8 +19,8 @@ int main(int argc, char **argv) {
   unsigned char input  [XORLEN];
   unsigned char output [HUGEBLOCK];
   char respath[32]; /* file_XXXXX\0 */
-  int i, zres = 0, filenum = 0, resfile;
-  size_t offs = 0, reported = 0;
+  int zres = 0, filenum = 0, resfile;
+  size_t i, offs = 0, reported = 0;
 
   z_stream z; memset( &z, 0, sizeof(z));
 
@@ -32,7 +32,8 @@ int main(int argc, char **argv) {
     if( (zres != Z_OK) && (zres != Z_STREAM_END) )
       goto error_continue;
 
-    z.next_in  = in->addr + offs + XORLEN; z.avail_in = in->size - offs - XORLEN;
+    z.next_in  = in->addr + offs + XORLEN;
+    z.avail_in = (unsigned int)(in->size - offs - XORLEN);
     while( zres == Z_OK ) zres = inflate( &z, Z_NO_FLUSH );
 
     if( zres != Z_STREAM_END ) {
diff --git a/src/export/map_coords.c b/src/export/map_coords.c
index 93c858f..ed5376a 100644
--- a/src/export/map_coords.c
+++ b/src/export/map_coords.c
@@ -5,13 +5,13 @@
 #include <string.h>
 #include <ctype.h>
 
-int find_offset( const void *key, const void *line )
+static int find_offset( const void *key, const void *line )
 {
   size_t l = strlen( (char*)key );
   return strncmp( (char*)key, *(char**)line, l );
 }
 
-int qsort_cmp( const void *a, const void *b )
+static int qsort_cmp( const void *a, const void *b )
 {
   return strcmp( *(char**)a, *(char**)b );
 }
diff --git a/src/export/mystdlib.c b/src/export/mystdlib.c
index ffc0cd9..b65f63d 100644
--- a/src/export/mystdlib.c
+++ b/src/export/mystdlib.c
@@ -46,10 +46,10 @@ void unmap_file ( MAP *pMap )
   free( *pMap ); *pMap = NULL;
 }
 
-int getfilesize( int fd, unsigned long *size)
+int getfilesize( int fd, size_t *size)
 {
   struct stat sb;
   if( fstat( fd, &sb )) return -1;
-  *size = sb.st_size;
+  *size = (size_t)sb.st_size;
   return 0;
 }
diff --git a/src/export/mystdlib.h b/src/export/mystdlib.h
index 2e9499f..dd08137 100644
--- a/src/export/mystdlib.h
+++ b/src/export/mystdlib.h
@@ -1,7 +1,8 @@
 #include <sys/types.h>
+#include <stdint.h>
 #include <stdio.h>
 
-typedef struct { int fh; unsigned char *addr; size_t size; } *MAP;
+typedef struct { int fh; uint8_t *addr; size_t size; } *MAP;
 
 /* Mapps a file into memory
    returns pointer to the mapping struct,
@@ -28,5 +29,5 @@ void unmap_file ( MAP *pMap );
 
 /* Gets file size of open file
    returns != 0 in case of error */
-inline int getfilesize( int fd, unsigned long *size );
+inline int getfilesize( int fd, size_t *size );
 
diff --git a/src/export/split_version_2.c b/src/export/split_version_2.c
index ab6c8cf..2019762 100644
--- a/src/export/split_version_2.c
+++ b/src/export/split_version_2.c
@@ -7,19 +7,17 @@
 
 int main( int argc, char **args ) {
   char table[64], f[1024*1024];
-  int  outfiles[64], i, base = 0;
-  uint32_t fixed_columns = 0;
+  int  outfiles[64], i, base = 0, fixed_columns = 0;
   uint32_t *p = (uint32_t*)f;
 
-  if( argc > 1 ) base = atol( args[1] );
-  if( argc > 2 ) fixed_columns = atol( args[2] );
+  if( argc > 1 ) base = atoi( args[1] );
+  if( argc > 2 ) fixed_columns = atoi( args[2] );
 
   /* No output file yet valid */
   for( i=0; i<64; ++i ) outfiles[i] = -1;
 
   while( fgets( table, sizeof(table), stdin ) ) {
-    unsigned int file, strnr;
-    uint32_t count, columns;
+    int file, strnr, columns, count;
 
     table[strlen(table)-1] = 0;
 
@@ -32,15 +30,15 @@ int main( int argc, char **args ) {
       close(f_in);
     }
 
-    count = p[0],
-    columns = fixed_columns ? fixed_columns : p[1] / 4 - 1;
+    count = (int)*p,
+    columns = fixed_columns ? fixed_columns : (int)p[1] / 4 - 1;
 
     for( file=0; file<columns; ++file ) {
       uint32_t off;
 
       /* Create outfile, if it is not yet there */
       if( outfiles[file] == -1 ) {
-        sprintf( table, "%02d_unknown", file+base );
+        sprintf( table, "%02d_unknown", file + base );
         outfiles[file] = open( table, O_WRONLY | O_APPEND | O_CREAT, 0644 );
         if ( outfiles[file] == -1 ) {
           fprintf( stderr, "Can not create output file %s\n", table );
-- 
cgit v1.2.3