Browse code

eliminating compile warnings in windows 10, vs2015, x86 and x64.

Micah Snyder authored on 2017/09/01 05:38:41
Showing 17 changed files
... ...
@@ -36,6 +36,8 @@
36 36
 #include <inttypes.h>
37 37
 #elif defined(HAVE_STDINT_H)
38 38
 #include <stdint.h>
39
+#elif defined(_MSC_VER)
40
+#include <stdint.h>
39 41
 #else
40 42
     typedef signed char int8_t;
41 43
     typedef unsigned char uint8_t;
... ...
@@ -150,7 +150,7 @@ fmap_t *fmap_check_empty(int fd, off_t offset, size_t len, int *empty) { /* WIN3
150 150
 	CloseHandle(fh);
151 151
 	return NULL;
152 152
     }
153
-    m->handle = (void*)(ssize_t)fd;
153
+    m->handle = (void*)(size_t)fd;
154 154
     m->handle_is_fd = 1;
155 155
     m->fh = fh;
156 156
     m->mh = mh;
... ...
@@ -401,7 +401,7 @@ static int fmap_readpage(fmap_t *m, unsigned int first_page, unsigned int count,
401 401
 	    /* we have some pending reads to perform */
402 402
 	    if (m->handle_is_fd) {
403 403
 		unsigned int j;
404
-		int _fd = (int)(ssize_t)m->handle;
404
+		int _fd = (int)(ptrdiff_t)m->handle;
405 405
 		for(j=first_page; j<page; j++) {
406 406
 		    if(fmap_bitmap[j] & FM_MASK_SEEN) {
407 407
 			/* page we've seen before: check mtime */
... ...
@@ -784,7 +784,7 @@ int fmap_fd(fmap_t *m)
784 784
     int fd;
785 785
     if (!m->handle_is_fd)
786 786
 	return -1;
787
-    fd = (int)(ssize_t)m->handle;
787
+    fd = (int)(ptrdiff_t)m->handle;
788 788
     lseek(fd, 0, SEEK_SET);
789 789
     return fd;
790 790
 }
... ...
@@ -165,7 +165,7 @@ static inline const void *fmap_need_off_once_len(fmap_t *m, size_t at, size_t le
165 165
     const void *p;
166 166
     if(at >= m->len) {
167 167
 	*lenout = 0;
168
-	return (void*)0xE0F00000;/* EOF, not read error */
168
+	return (void*)(size_t)0xE0F00000;/* EOF, not read error */
169 169
     }
170 170
     if(len > m->len - at)
171 171
 	len = m->len - at;
... ...
@@ -2158,7 +2158,7 @@ inline static int ac_addspecial_add_alt_node(const char *subexpr, uint8_t sigopt
2158 2158
     }
2159 2159
 
2160 2160
     newnode->str = s;
2161
-    newnode->len = strlen(subexpr)/2;
2161
+    newnode->len = (uint16_t)strlen(subexpr)/2;
2162 2162
     newnode->unique = 1;
2163 2163
 
2164 2164
     /* setting nocase match */
... ...
@@ -2700,7 +2700,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
2700 2700
         return CL_EMALFDB;
2701 2701
     }
2702 2702
 
2703
-    new->length[0] = strlen(hex ? hex : hexsig) / 2;
2703
+    new->length[0] = (uint16_t)strlen(hex ? hex : hexsig) / 2;
2704 2704
     for(i = 0, j = 0; i < new->length[0]; i++) {
2705 2705
         if((new->pattern[i] & CLI_MATCH_METADATA) == CLI_MATCH_SPECIAL) {
2706 2706
             new->length[1] += new->special_table[j]->len[0];
... ...
@@ -229,7 +229,7 @@ int openioc_parse(const char * fname, int fd, struct cl_engine *engine, unsigned
229 229
     else
230 230
         iocp++;
231 231
 
232
-    ioclen = strlen(fname);
232
+    ioclen = (uint16_t)strlen(fname);
233 233
 
234 234
     if (elems != NULL) {
235 235
         if (NULL == engine->hm_hdb) {
... ...
@@ -2148,7 +2148,7 @@ static int cli_loadftm(FILE *fs, struct cl_engine *engine, unsigned int options,
2148 2148
 		mpool_free(engine->mempool, new);
2149 2149
 		break;
2150 2150
 	    }
2151
-	    new->length = strlen(tokens[2]) / 2;
2151
+	    new->length = (uint16_t)strlen(tokens[2]) / 2;
2152 2152
 	    new->tname = cli_mpool_strdup(engine->mempool, tokens[3]);
2153 2153
 	    if(!new->tname) {
2154 2154
 		mpool_free(engine->mempool, new->magic);
... ...
@@ -4222,10 +4222,10 @@ static int cli_loadpwdb(FILE *fs, struct cl_engine *engine, unsigned int options
4222 4222
 
4223 4223
             if(pwstype == 0) { /* cleartext */
4224 4224
                 new->passwd = cli_mpool_strdup(engine->mempool, tokens[3]);
4225
-                new->length = strlen(tokens[3]);
4225
+                new->length = (uint16_t)strlen(tokens[3]);
4226 4226
             } else { /* 1 => hex-encoded */
4227 4227
                 new->passwd = cli_mpool_hex2str(engine->mempool, tokens[3]);
4228
-                new->length = strlen(tokens[3]) / 2;
4228
+                new->length = (uint16_t)strlen(tokens[3]) / 2;
4229 4229
             }
4230 4230
             if(!new->passwd) {
4231 4231
                 cli_errmsg("cli_loadpwdb: Can't decode or add new password entry\n");
... ...
@@ -432,7 +432,7 @@ p_ere_exp(struct parse *p)
432 432
 				count2 = p_count(p);
433 433
 				REQUIRE(count <= count2, REG_BADBR);
434 434
 			} else		/* single number with comma */
435
-				count2 = INFINITY;
435
+				count2 = REGEX_INFINITY;
436 436
 		} else		/* just a single number */
437 437
 			count2 = count;
438 438
 		repeat(p, pos, count, count2);
... ...
@@ -603,7 +603,7 @@ p_simp_re(struct parse *p,
603 603
 				count2 = p_count(p);
604 604
 				REQUIRE(count <= count2, REG_BADBR);
605 605
 			} else		/* single number with comma */
606
-				count2 = INFINITY;
606
+				count2 = REGEX_INFINITY;
607 607
 		} else		/* just a single number */
608 608
 			count2 = count;
609 609
 		repeat(p, pos, count, count2);
... ...
@@ -961,13 +961,13 @@ static void
961 961
 repeat(struct parse *p,
962 962
     sopno start,		/* operand from here to end of strip */
963 963
     int from,			/* repeated from this number */
964
-    int to)			/* to this number of times (maybe INFINITY) */
964
+    int to)			/* to this number of times (maybe REGEX_INFINITY) */
965 965
 {
966 966
 	sopno finish = HERE();
967 967
 #	define	N	2
968 968
 #	define	INF	3
969 969
 #	define	REP(f, t)	((f)*8 + (t))
970
-#	define	MAP(n)	(((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N)
970
+#	define	MAP(n)	(((n) <= 1) ? (n) : ((n) == REGEX_INFINITY) ? INF : N)
971 971
 	sopno copy;
972 972
 
973 973
 	if (p->error != 0)	/* head off possible runaway recursion */
... ...
@@ -110,8 +110,8 @@ typedef struct {
110 110
 	char *multis;		/* -> char[smulti]  ab\0cd\0ef\0\0 */
111 111
 } cset;
112 112
 /* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
113
-#define	CHadd(cs, c)	((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c))
114
-#define	CHsub(cs, c)	((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c))
113
+#define	CHadd(cs, c)	((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (uch)(c))
114
+#define	CHsub(cs, c)	((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (uch)(c))
115 115
 #define	CHIN(cs, c)	((cs)->ptr[(uch)(c)] & (cs)->mask)
116 116
 #define	MCadd(p, cs, cp)	mcadd(p, cs, cp)	/* cli_regcomp() internal fns */
117 117
 #define	MCsub(p, cs, cp)	mcsub(p, cs, cp)
... ...
@@ -41,7 +41,7 @@
41 41
 #else
42 42
 #define DUPMAX  255
43 43
 #endif
44
-#define	INFINITY	(DUPMAX + 1)
44
+#define	REGEX_INFINITY	(DUPMAX + 1)
45 45
 #define	NC		(CHAR_MAX - CHAR_MIN + 1)
46 46
 typedef unsigned char uch;
47 47
 
... ...
@@ -77,7 +77,7 @@ static void fatal_error(struct regex_matcher* matcher)
77 77
 }
78 78
 
79 79
 
80
-static inline size_t get_char_at_pos_with_skip(const struct pre_fixup_info* info, const char* buffer, size_t pos)
80
+static inline char get_char_at_pos_with_skip(const struct pre_fixup_info* info, const char* buffer, size_t pos)
81 81
 {
82 82
 	const char* str;
83 83
 	size_t realpos = 0;
... ...
@@ -586,7 +586,7 @@ static int add_newsuffix(struct regex_matcher *matcher, struct regex_list *info,
586 586
 	new->mindist = 0;
587 587
 	new->maxdist = 0;
588 588
 	new->offset_min = CLI_OFF_ANY;
589
-	new->length[0] = len;
589
+	new->length[0] = (uint16_t)len;
590 590
 
591 591
 	new->ch[0] = new->ch[1] |= CLI_MATCH_IGNORE;
592 592
 	if(new->length[0] > root->maxpatlen)
... ...
@@ -358,7 +358,7 @@ static int build_suffixtree_ascend(struct node *n, struct text_buffer *buf, stru
358 358
 					if(BITMAP_HASSET(n->u.leaf_class_bitmap, i)) {
359 359
 						size_t pos;
360 360
 						pos = buf->pos;
361
-						textbuffer_putc(buf, i);
361
+						textbuffer_putc(buf, (char)i);
362 362
 						if(build_suffixtree_ascend(n->parent, buf, n, cb, cbdata, regex) < 0)
363 363
 							return CL_EMEM;
364 364
 						buf->pos = pos;
... ...
@@ -226,11 +226,7 @@ void submit_post(const char *host, const char *port, const char *method, const c
226 226
         encoded = encode_data(postdata);
227 227
         if (!(encoded))
228 228
             return;
229
-#if defined(_WIN32)
230
-		snprintf(chunkedlen, sizeof(chunkedlen), "%u", strlen(encoded));
231
-#else
232 229
         snprintf(chunkedlen, sizeof(chunkedlen), "%zu", strlen(encoded));
233
-#endif
234 230
         bufsz += sizeof("Content-Type: application/x-www-form-urlencoded\r\n");
235 231
         bufsz += sizeof("Content-Length: \r\n");
236 232
         bufsz += strlen(chunkedlen);
... ...
@@ -1566,7 +1566,7 @@ primary_expression
1566 1566
     | _TEXT_STRING_
1567 1567
       {
1568 1568
         SIZED_STRING* sized_string = $1;
1569
-        char* string;
1569
+        char* string = NULL;
1570 1570
 
1571 1571
 #if REAL_YARA
1572 1572
         compiler->last_result = yr_arena_write_string(
... ...
@@ -48,6 +48,10 @@ typedef uint16_t flex_uint16_t;
48 48
 typedef int32_t flex_int32_t;
49 49
 typedef uint32_t flex_uint32_t;
50 50
 #else
51
+
52
+#if _MSC_VER
53
+#include <inttypes.h>
54
+#endif
51 55
 typedef signed char flex_int8_t;
52 56
 typedef short int flex_int16_t;
53 57
 typedef int flex_int32_t;
... ...
@@ -166,7 +166,7 @@ uint32_t rar_crc(uint32_t start_crc, void *addr, uint32_t size)
166 166
 
167 167
 	data = addr;
168 168
 #if WORDS_BIGENDIAN == 0
169
-	while (size > 0 && ((long)data & 7))
169
+	while (size > 0 && ((size_t)data & 7))
170 170
 	{
171 171
 		start_crc = crc_tab[(unsigned char)(start_crc^data[0])]^(start_crc>>8);
172 172
 		size--;
... ...
@@ -26,6 +26,7 @@
26 26
 #include <netdb.h>
27 27
 #include <netinet/in.h>
28 28
 #endif
29
+#include "platform.h"
29 30
 #include "optparser.h"
30 31
 /* Maximum filenames under various systems - njh */
31 32
 #ifndef	NAME_MAX	/* e.g. Linux */
... ...
@@ -92,6 +92,7 @@ typedef u_int64_t uint64_t;
92 92
 #else /* _MSC_VER */
93 93
 /* Visual C++ doesn't provide standard integer headers, but it does provide
94 94
    built-in data types. */
95
+#include <stdint.h>
95 96
 #include <stdlib.h>
96 97
 #include <stddef.h>
97 98
 #include <sys/types.h>
... ...
@@ -109,18 +110,36 @@ typedef unsigned short uint16_t;
109 109
 typedef signed char int8_t;
110 110
 typedef unsigned char uint8_t;
111 111
 typedef signed int ssize_t;
112
+/* Certain compatibility updates to VC++ introduce the `cstdint'
113
+* header, which defines the INT*_C macros. On default installs they
114
+* are absent. */
115
+#ifndef INT8_MAX
112 116
 #define INT8_MAX 127
117
+#endif
118
+#ifndef INT8_MIN
113 119
 #define INT8_MIN -128
120
+#endif
121
+#ifndef UINT8_MAX
114 122
 #define UINT8_MAX 255
123
+#endif
124
+#ifndef INT16_MAX
115 125
 #define INT16_MAX 32767
126
+#endif
127
+#ifndef INT16_MIN
116 128
 #define INT16_MIN -32768
129
+#endif
130
+#ifndef UINT16_MAX
117 131
 #define UINT16_MAX 65535
132
+#endif
133
+#ifndef INT32_MAX
118 134
 #define INT32_MAX 2147483647
135
+#endif
136
+#ifndef INT32_MIN
119 137
 #define INT32_MIN -2147483648
138
+#endif
139
+#ifndef UINT32_MAX
120 140
 #define UINT32_MAX 4294967295U
121
-/* Certain compatibility updates to VC++ introduce the `cstdint'
122
- * header, which defines the INT*_C macros. On default installs they
123
- * are absent. */
141
+#endif
124 142
 #ifndef INT8_C
125 143
 # define INT8_C(C)   C
126 144
 #endif