Browse code

fix some gcc -W* warnings

git-svn: trunk@2912

Tomasz Kojm authored on 2007/03/06 10:55:55
Showing 8 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Mar  6 01:01:32 CET 2007 (tk)
2
+---------------------------------
3
+  * libclamav: fix some gcc -W* warnings
4
+
1 5
 Mon Mar  5 21:06:37 CET 2007 (tk)
2 6
 ---------------------------------
3 7
   * sigtool: fix gcc -W* warnings
... ...
@@ -401,7 +401,7 @@ int cab_open(int fd, off_t offset, struct cab_archive *cab)
401 401
 
402 402
 	cli_dbgmsg("CAB: File record %u\n", i);
403 403
 	cli_dbgmsg("CAB: File name: %s\n", file->name);
404
-	cli_dbgmsg("CAB: File offset: %u\n", file->offset);
404
+	cli_dbgmsg("CAB: File offset: %u\n", (unsigned int) file->offset);
405 405
 	cli_dbgmsg("CAB: File folder index: %u\n", fidx);
406 406
 	cli_dbgmsg("CAB: File attribs: 0x%x\n", file->attribs);
407 407
 	if(file->attribs & 0x01)
... ...
@@ -595,7 +595,7 @@ int cab_extract(struct cab_file *file, const char *name)
595 595
     }
596 596
 
597 597
     if(lseek(file->fd, file->folder->offset, SEEK_SET) == -1) {
598
-	cli_errmsg("cab_extract: Can't lseek to %u\n", file->folder->offset);
598
+	cli_errmsg("cab_extract: Can't lseek to %u\n", (unsigned int) file->folder->offset);
599 599
 	return CL_EIO;
600 600
     }
601 601
 
... ...
@@ -79,7 +79,7 @@ static const unsigned char mszip_bitlen_order[19] = {
79 79
 };
80 80
 
81 81
 /* ANDing with mszip_bit_mask[n] masks the lower n bits */
82
-static const unsigned short mszip_bit_mask[17] = {
82
+static const unsigned short mszip_bit_mask_tab[17] = {
83 83
  0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
84 84
  0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
85 85
 };
... ...
@@ -110,7 +110,7 @@ static const unsigned short mszip_bit_mask[17] = {
110 110
 } while (0)
111 111
 
112 112
 #define MSZIP_PEEK_BITS(nbits)   (bit_buffer & ((1<<(nbits))-1))
113
-#define MSZIP_PEEK_BITS_T(nbits) (bit_buffer & mszip_bit_mask[(nbits)])
113
+#define MSZIP_PEEK_BITS_T(nbits) (bit_buffer & mszip_bit_mask_tab[(nbits)])
114 114
 
115 115
 #define MSZIP_REMOVE_BITS(nbits) ((bit_buffer >>= (nbits)), (bits_left -= (nbits)))
116 116
 
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net>
2
+ *  Copyright (C) 2002 - 2007 Tomasz Kojm <tkojm@clamav.net>
3 3
  *
4 4
  *  This program is free software; you can redistribute it and/or modify
5 5
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -77,13 +77,18 @@ static pthread_mutex_t cli_ref_mutex = PTHREAD_MUTEX_INITIALIZER;
77 77
 #include "matcher-ncore.h"
78 78
 #endif
79 79
 
80
+/* Prototypes for old public functions just to shut up some gcc warnings;
81
+ * to be removed in 1.0
82
+ */
83
+int cl_loaddb(const char *filename, struct cl_engine **engine, unsigned int *signo);
84
+int cl_loaddbdir(const char *dirname, struct cl_engine **engine, unsigned int *signo);
80 85
 
81 86
 /* TODO: clean up the code */
82 87
 
83 88
 static int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hexsig, int sigid, int parts, int partno, unsigned short type, unsigned int mindist, unsigned int maxdist, const char *offset, unsigned short target)
84 89
 {
85 90
 	struct cli_ac_patt *new;
86
-	char *pt, *hex;
91
+	char *pt, *hex = NULL;
87 92
 	int virlen, ret, error = 0;
88 93
 	unsigned int i, j, wprefix = 0;
89 94
 
... ...
@@ -203,11 +208,9 @@ static int cli_ac_addsig(struct cli_matcher *root, const char *virname, const ch
203 203
 	    free(new);
204 204
 	    return CL_EMALFDB;
205 205
 	}
206
+    }
206 207
 
207
-    } else
208
-	hex = (char *) hexsig;
209
-
210
-    if((new->pattern = cli_hex2si(hex)) == NULL) {
208
+    if((new->pattern = cli_hex2si(new->alt ? hex : hexsig)) == NULL) {
211 209
 	FREE_ALT;
212 210
 	if(new->offset)
213 211
 	    free(new->offset);
... ...
@@ -215,7 +218,7 @@ static int cli_ac_addsig(struct cli_matcher *root, const char *virname, const ch
215 215
 	return CL_EMALFDB;
216 216
     }
217 217
 
218
-    new->length = strlen(hex) / 2;
218
+    new->length = strlen(new->alt ? hex : hexsig) / 2;
219 219
 
220 220
     for(i = 0; i < AC_DEFAULT_DEPTH; i++) {
221 221
 	if(new->pattern[i] == CLI_IGN || new->pattern[i] == CLI_ALT) {
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net>
2
+ *  Copyright (C) 2002 - 2007 Tomasz Kojm <tkojm@clamav.net>
3 3
  *
4 4
  *  This program is free software; you can redistribute it and/or modify
5 5
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -118,10 +118,10 @@ static int cli_unrar_scanmetadata(int desc, rar_metadata_t *metadata, cli_ctx *c
118 118
 	    *sfx_check = metadata->crc;
119 119
     }
120 120
 
121
-    cli_dbgmsg("RAR: %s, crc32: 0x%x, encrypted: %d, compressed: %u, normal: %u, method: %d, ratio: %d (max: %d)\n",
122
-	metadata->filename, metadata->crc, metadata->encrypted, metadata->pack_size,
123
-	metadata->unpack_size, metadata->method,
124
-	metadata->pack_size ? ((unsigned int) metadata->unpack_size / (unsigned int) metadata->pack_size) : 0, ctx->limits ? ctx->limits->maxratio : 0);
121
+    cli_dbgmsg("RAR: %s, crc32: 0x%x, encrypted: %u, compressed: %u, normal: %u, method: %u, ratio: %u (max: %u)\n",
122
+	metadata->filename, metadata->crc, metadata->encrypted, (unsigned int) metadata->pack_size,
123
+	(unsigned int) metadata->unpack_size, metadata->method,
124
+	metadata->pack_size ? (unsigned int) (metadata->unpack_size / metadata->pack_size) : 0, ctx->limits ? ctx->limits->maxratio : 0);
125 125
 
126 126
     /* Scan metadata */
127 127
     mdata = ctx->engine->rar_mlist;
... ...
@@ -187,7 +187,7 @@ static int cli_unrar_checklimits(const cli_ctx *ctx, const rar_metadata_t *metad
187 187
     if(ctx->limits) {
188 188
 	if(ctx->limits->maxratio && metadata->unpack_size && metadata->pack_size) {
189 189
 	    if(metadata->unpack_size / metadata->pack_size >= ctx->limits->maxratio) {
190
-		cli_dbgmsg("RAR: Max ratio reached (normal: %Lu, compressed: %Lu, max: %u)\n", metadata->unpack_size, metadata->pack_size, ctx->limits->maxratio);
190
+		cli_dbgmsg("RAR: Max ratio reached (%u, max: %u)\n", (unsigned int) (metadata->unpack_size / metadata->pack_size), ctx->limits->maxratio);
191 191
 		if(BLOCKMAX) {
192 192
 		    *ctx->virname = "Oversized.RAR";
193 193
 		    return CL_VIRUS;
... ...
@@ -197,7 +197,7 @@ static int cli_unrar_checklimits(const cli_ctx *ctx, const rar_metadata_t *metad
197 197
 	}
198 198
 
199 199
 	if(ctx->limits->maxfilesize && (metadata->unpack_size > ctx->limits->maxfilesize)) {
200
-	    cli_dbgmsg("RAR: %s: Size exceeded (%Lu, max: %lu)\n", metadata->filename, metadata->unpack_size, ctx->limits->maxfilesize);
200
+	    cli_dbgmsg("RAR: %s: Size exceeded (%lu, max: %lu)\n", metadata->filename, (unsigned long int) metadata->unpack_size, ctx->limits->maxfilesize);
201 201
 	    if(BLOCKMAX) {
202 202
 		*ctx->virname = "RAR.ExceededFileSize";
203 203
 		return CL_VIRUS;
... ...
@@ -367,7 +367,7 @@ static int cli_scanzip(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
367 367
 	 */
368 368
 	encrypted = ((zdirent.d_flags & 0x2041) != 0);
369 369
 
370
-	cli_dbgmsg("Zip: %s, crc32: 0x%x, offset: %d, encrypted: %d, compressed: %u, normal: %u, method: %d, ratio: %d (max: %d)\n", zdirent.d_name, zdirent.d_crc32, zdirent.d_off, encrypted, zdirent.d_csize, zdirent.st_size, zdirent.d_compr, zdirent.d_csize ? (zdirent.st_size / zdirent.d_csize) : 0, ctx->limits ? ctx->limits->maxratio : 0);
370
+	cli_dbgmsg("Zip: %s, crc32: 0x%x, offset: %u, encrypted: %u, compressed: %u, normal: %u, method: %u, ratio: %u (max: %u)\n", zdirent.d_name, zdirent.d_crc32, zdirent.d_off, encrypted, zdirent.d_csize, zdirent.st_size, zdirent.d_compr, zdirent.d_csize ? (zdirent.st_size / zdirent.d_csize) : 0, ctx->limits ? ctx->limits->maxratio : 0);
371 371
 
372 372
 	if(!zdirent.st_size) {
373 373
 	    if(zdirent.d_crc32) {
... ...
@@ -456,7 +456,7 @@ static int cli_scanzip(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
456 456
 
457 457
 	if(ctx->limits) {
458 458
 	    if(ctx->limits->maxfilesize && ((unsigned int) zdirent.st_size > ctx->limits->maxfilesize)) {
459
-		cli_dbgmsg("Zip: %s: Size exceeded (%d, max: %ld)\n", zdirent.d_name, zdirent.st_size, ctx->limits->maxfilesize);
459
+		cli_dbgmsg("Zip: %s: Size exceeded (%u, max: %lu)\n", zdirent.d_name, zdirent.st_size, ctx->limits->maxfilesize);
460 460
 		/* ret = CL_EMAXSIZE; */
461 461
 		if(BLOCKMAX) {
462 462
 		    *ctx->virname = "Zip.ExceededFileSize";
... ...
@@ -467,7 +467,7 @@ static int cli_scanzip(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
467 467
 	    }
468 468
 
469 469
 	    if(ctx->limits->maxfiles && (files > ctx->limits->maxfiles)) {
470
-		cli_dbgmsg("Zip: Files limit reached (max: %d)\n", ctx->limits->maxfiles);
470
+		cli_dbgmsg("Zip: Files limit reached (max: %u)\n", ctx->limits->maxfiles);
471 471
 		if(BLOCKMAX) {
472 472
 		    *ctx->virname = "Zip.ExceededFilesLimit";
473 473
 		    ret = CL_VIRUS;
... ...
@@ -516,7 +516,7 @@ static int cli_scanzip(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
516 516
 
517 517
 	    if(!encrypted) {
518 518
 		if(size != zdirent.st_size) {
519
-		    cli_dbgmsg("Zip: Incorrectly decompressed (%d != %d)\n", size, zdirent.st_size);
519
+		    cli_dbgmsg("Zip: Incorrectly decompressed (%lu != %lu)\n", size, (unsigned long int) zdirent.st_size);
520 520
 		    if(zfp->bf[0] == -1) {
521 521
 			ret = CL_EZIP;
522 522
 			break;
... ...
@@ -613,7 +613,7 @@ static int cli_scangzip(int desc, cli_ctx *ctx)
613 613
     fd = fileno(tmp);
614 614
 
615 615
     if(!(buff = (char *) cli_malloc(FILEBUFF))) {
616
-	cli_dbgmsg("GZip: Unable to malloc %d bytes.\n", FILEBUFF);
616
+	cli_dbgmsg("GZip: Unable to malloc %u bytes.\n", FILEBUFF);
617 617
 	gzclose(gd);
618 618
 	fclose(tmp);
619 619
 	if(!cli_leavetemps_flag)
... ...
@@ -882,7 +882,7 @@ static int cli_scanmscab(int desc, cli_ctx *ctx, off_t sfx_offset)
882 882
 	files++;
883 883
 
884 884
 	if(ctx->limits && ctx->limits->maxfilesize && (file->length > ctx->limits->maxfilesize)) {
885
-	    cli_dbgmsg("CAB: %s: Size exceeded (%u, max: %u)\n", file->name, file->length, ctx->limits->maxfilesize);
885
+	    cli_dbgmsg("CAB: %s: Size exceeded (%u, max: %lu)\n", file->name, file->length, ctx->limits->maxfilesize);
886 886
 	    if(BLOCKMAX) {
887 887
 		*ctx->virname = "CAB.ExceededFileSize";
888 888
 		cab_free(&cab);
... ...
@@ -1651,7 +1651,7 @@ static int cli_scanmail(int desc, cli_ctx *ctx)
1651 1651
 	int ret;
1652 1652
 
1653 1653
 
1654
-    cli_dbgmsg("Starting cli_scanmail(), mrec == %d, arec == %d\n", ctx->mrec, ctx->arec);
1654
+    cli_dbgmsg("Starting cli_scanmail(), mrec == %u, arec == %u\n", ctx->mrec, ctx->arec);
1655 1655
 
1656 1656
     /* generate the temporary directory */
1657 1657
     dir = cli_gentemp(NULL);
... ...
@@ -1732,15 +1732,15 @@ static int cli_scanraw(int desc, cli_ctx *ctx, cli_file_t type)
1732 1732
 			fpt = ftoffset;
1733 1733
 			while(fpt) {
1734 1734
 			    if(fpt->type == CL_TYPE_RARSFX && (DCONF_ARCH & ARCH_CONF_RAR)) {
1735
-				cli_dbgmsg("RAR-SFX signature found at %d\n", fpt->offset);
1735
+				cli_dbgmsg("RAR-SFX signature found at %u\n", (unsigned int) fpt->offset);
1736 1736
 				if((nret = cli_scanrar(desc, ctx, fpt->offset, &lastrar)) == CL_VIRUS)
1737 1737
 				    break;
1738 1738
 			    } else if(fpt->type == CL_TYPE_ZIPSFX && (DCONF_ARCH & ARCH_CONF_ZIP)) {
1739
-				cli_dbgmsg("ZIP-SFX signature found at %d\n", fpt->offset);
1739
+				cli_dbgmsg("ZIP-SFX signature found at %u\n", (unsigned int) fpt->offset);
1740 1740
 				if((nret = cli_scanzip(desc, ctx, fpt->offset, &lastzip)) == CL_VIRUS)
1741 1741
 				    break;
1742 1742
 			    } else if(fpt->type == CL_TYPE_CABSFX && (DCONF_ARCH & ARCH_CONF_CAB)) {
1743
-				cli_dbgmsg("CAB-SFX signature found at %d\n", fpt->offset);
1743
+				cli_dbgmsg("CAB-SFX signature found at %u\n", (unsigned int) fpt->offset);
1744 1744
 				if((nret = cli_scanmscab(desc, ctx, fpt->offset)) == CL_VIRUS)
1745 1745
 				    break;
1746 1746
 			    }
... ...
@@ -1783,7 +1783,7 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx)
1783 1783
     }
1784 1784
 
1785 1785
     if(sb.st_size <= 5) {
1786
-	cli_dbgmsg("Small data (%d bytes)\n", sb.st_size);
1786
+	cli_dbgmsg("Small data (%u bytes)\n", (unsigned int) sb.st_size);
1787 1787
 	return CL_CLEAN;
1788 1788
     }
1789 1789
 
... ...
@@ -1801,7 +1801,7 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx)
1801 1801
 
1802 1802
     if(SCAN_ARCHIVE && ctx->limits && ctx->limits->maxreclevel)
1803 1803
 	if(ctx->arec > ctx->limits->maxreclevel) {
1804
-	    cli_dbgmsg("Archive recursion limit exceeded (arec == %d).\n", ctx->arec);
1804
+	    cli_dbgmsg("Archive recursion limit exceeded (arec == %u).\n", ctx->arec);
1805 1805
 	    if(BLOCKMAX) {
1806 1806
 		*ctx->virname = "Archive.ExceededRecursionLimit";
1807 1807
 		return CL_VIRUS;
... ...
@@ -1811,7 +1811,7 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx)
1811 1811
 
1812 1812
     if(SCAN_MAIL)
1813 1813
 	if(ctx->mrec > MAX_MAIL_RECURSION) {
1814
-	    cli_dbgmsg("Mail recursion level exceeded (mrec == %d).\n", ctx->mrec);
1814
+	    cli_dbgmsg("Mail recursion level exceeded (mrec == %u).\n", ctx->mrec);
1815 1815
 	    /* return CL_EMAXREC; */
1816 1816
 	    return CL_CLEAN;
1817 1817
 	}
... ...
@@ -271,11 +271,11 @@ static int sis_extract_simple(int fd, char *mfile, uint32_t length, uint32_t off
271 271
 		continue;
272 272
 	    }
273 273
 
274
-	    cli_dbgmsg("SIS: Compressed size: %d\n", csize);
275
-	    cli_dbgmsg("SIS: Original size: %d\n", osize);
274
+	    cli_dbgmsg("SIS: Compressed size: %u\n", (unsigned int) csize);
275
+	    cli_dbgmsg("SIS: Original size: %u\n", (unsigned int) osize);
276 276
 
277 277
 	    if(ctx->limits && ctx->limits->maxfilesize && osize > ctx->limits->maxfilesize) {
278
-		cli_dbgmsg("SIS: Size exceeded (%d, max: %ld)\n", osize, ctx->limits->maxfilesize);
278
+		cli_dbgmsg("SIS: Size exceeded (%u, max: %lu)\n", (unsigned int) osize, ctx->limits->maxfilesize);
279 279
 		if(BLOCKMAX) {
280 280
 		    *ctx->virname = "SIS.ExceededFileSize";
281 281
 		    free(subdir);
... ...
@@ -304,7 +304,7 @@ static int sis_extract_simple(int fd, char *mfile, uint32_t length, uint32_t off
304 304
 	    }
305 305
 
306 306
 	    if(osize != (uLongf) filelen) {
307
-		cli_dbgmsg("SIS: WARNING: Real original size: %u\n", osize);
307
+		cli_dbgmsg("SIS: WARNING: Real original size: %u\n", (unsigned int) osize);
308 308
 		filelen = (uint32_t) osize;
309 309
 	    }
310 310
 
... ...
@@ -372,7 +372,7 @@ int cli_scansis(int desc, cli_ctx *ctx)
372 372
 	return CL_EIO;
373 373
     }
374 374
 
375
-    if(sb.st_size < sizeof(struct sis_file_hdr)) {
375
+    if(sb.st_size < (off_t) sizeof(struct sis_file_hdr)) {
376 376
 	cli_dbgmsg("SIS: Broken or not a SIS file (too small)\n");
377 377
 	return CL_CLEAN;
378 378
     }
... ...
@@ -426,7 +426,7 @@ int cli_scansis(int desc, cli_ctx *ctx)
426 426
 
427 427
     if(nlangs && nlangs < 100) {
428 428
 
429
-	if(EC32(file_hdr.plangs) >= length || EC32(file_hdr.plangs) + nlangs * 2 >= sb.st_size) {
429
+	if(EC32(file_hdr.plangs) >= length || EC32(file_hdr.plangs) + nlangs * 2 >= (uint32_t) sb.st_size) {
430 430
 	    cli_errmsg("SIS: Broken file structure (language records)\n");
431 431
 	    munmap(mfile, length);
432 432
 	    return CL_EFORMAT;
... ...
@@ -60,13 +60,13 @@ int cli_check_mydoom_log(int desc, const char **virname)
60 60
 
61 61
 	/* Decode the key */
62 62
 	record[0] = ~ntohl(record[0]);
63
-	cli_dbgmsg("Mydoom: key: %lu\n", record[0]);
63
+	cli_dbgmsg("Mydoom: key: %d\n", record[0]);
64 64
 	check = 0;
65 65
 	for (i=1 ; i<8; i++) {
66 66
 	    record[i] = ntohl(record[i]) ^ record[0];
67 67
 	    check += record[i];
68 68
 	}
69
-	cli_dbgmsg("Mydoom: check: %lu\n", ~check);
69
+	cli_dbgmsg("Mydoom: check: %d\n", ~check);
70 70
 	if ((~check) != record[0]) {
71 71
 	    return CL_CLEAN;
72 72
 	}
... ...
@@ -110,7 +110,7 @@ static int __zip_find_disk_trailer(int fd, off_t filesize, struct zip_disk_trail
110 110
 	}
111 111
 
112 112
         if(cli_readn(fd, buf, (size_t) bufsize) < (ssize_t) bufsize) {
113
-	    cli_errmsg("Unzip: __zip_find_disk_trailer: Can't read %d bytes\n", bufsize);
113
+	    cli_errmsg("Unzip: __zip_find_disk_trailer: Can't read %u bytes\n", (unsigned int) bufsize);
114 114
 	    free(buf);
115 115
 	    return CL_EIO;
116 116
 	}
... ...
@@ -141,7 +141,7 @@ static int __zip_find_disk_trailer(int fd, off_t filesize, struct zip_disk_trail
141 141
 			}
142 142
 
143 143
 			if(cli_readn(fd, &dirent, sizeof(dirent)) < __sizeof(dirent)) {
144
-			    cli_errmsg("Unzip: __zip_find_disk_trailer: Can't read %d bytes\n", bufsize);
144
+			    cli_errmsg("Unzip: __zip_find_disk_trailer: Can't read %u bytes\n", (unsigned int) bufsize);
145 145
 			    free(buf);
146 146
 			    return CL_EIO;
147 147
 			}