Project

General

Profile

Enhancement #750 » 0010-sanitize-use-proper-types-safe-casts-mostly-size_t.patch

Loïc Gomez, 2022-01-10 19:27

View differences:

src/bip.c
135 135
void conf_die(bip_t *bip, char *fmt, ...)
136 136
{
137 137
	va_list ap;
138
	int size = ERRBUFSZ;
138
	size_t size = ERRBUFSZ;
139 139
	int n;
140 140
	char *error = bip_malloc(size);
141 141

  
......
143 143
		va_start(ap, fmt);
144 144
		n = vsnprintf(error, size, fmt, ap);
145 145
		va_end(ap);
146
		if (n > -1 && n < size) {
146
		if (n > -1 && (unsigned int) n < size) {
147 147
			list_add_last(&bip->errors, error);
148 148
			break;
149 149
		}
150 150
		if (n > -1)
151
			size = n + 1;
151
			size = (unsigned int) n + 1;
152 152
		else
153 153
			size *= 2;
154 154
		error = bip_realloc(error, size);
......
166 166
	FILE *f;
167 167
	int fd;
168 168
	// size is conf_pid_file + hname max + %ld max + two '.'.
169
	int longpath_max = strlen(conf_pid_file) + 512 + 3 + 20;
169
	size_t longpath_max = strlen(conf_pid_file) + 512 + 3 + 20;
170 170
	char *longpath = bip_malloc(longpath_max + 1);
171 171

  
172 172
try_again:
......
1834 1834

  
1835 1835
#define ON_CONNECT_MAX_STRSIZE 1024
1836 1836
void adm_on_connect_send(struct link_client *ic, struct line *line,
1837
		unsigned int privmsg)
1837
		int privmsg)
1838 1838
{
1839 1839
	size_t remaining = ON_CONNECT_MAX_STRSIZE;
1840 1840
	char buf[ON_CONNECT_MAX_STRSIZE];
......
1855 1855
	for (i = privmsg + 2; i < irc_line_count(line); i++) {
1856 1856
		mylog(LOG_DEBUG, "[%s] processing item %d, remaining %ld, %s",
1857 1857
				LINK(ic)->user->name, i, remaining, buf);
1858
		if ((unsigned int)i > privmsg + 2)
1858
		if (i > privmsg + 2)
1859 1859
			bufpos = bip_strcatf_fit(&remaining, bufpos, " %s",
1860 1860
					irc_line_elem(line, i));
1861 1861
		else
1862 1862
			bufpos = bip_strcat_fit(&remaining, bufpos,
1863
					(char *)irc_line_elem(line, i));
1863
					irc_line_elem(line, i));
1864 1864
		mylog(LOG_DEBUG, "[%s] processed item %d, remaining %ld, %s",
1865 1865
				LINK(ic)->user->name, i, remaining, buf);
1866 1866
		if (!bufpos) {
......
2008 2008
	if (privmsg) {
2009 2009
		char *linestr, *elemstr;
2010 2010
		char *ptr, *eptr;
2011
		int slen;
2011
		size_t slen;
2012 2012

  
2013 2013
		if (irc_line_count(line) != 3)
2014 2014
			return OK_FORGET;
......
2020 2020
		elemstr = bip_malloc(strlen(linestr) + 1);
2021 2021

  
2022 2022
		while((eptr = strstr(ptr, " "))) {
2023
			slen = eptr - ptr;
2023
			// eptr is either >= ptr or NULL from strstr()
2024
			// but it can't be NULL per while loop
2025
			// we can then assume slen is unsigned
2026
			slen = (size_t)(eptr - ptr);
2024 2027
			if (slen == 0) {
2025 2028
				ptr++;
2026 2029
				continue;
......
2030 2033
			irc_line_append(line, elemstr);
2031 2034
			ptr = eptr + 1;
2032 2035
		}
2033
		eptr = ptr + strlen(ptr);
2034
		slen = eptr - ptr;
2036
		slen = strlen(ptr);
2037
		eptr = ptr + slen;
2035 2038
		if (slen != 0) {
2036 2039
			memcpy(elemstr, ptr, slen);
2037 2040
			elemstr[slen] = 0;
src/connection.c
206 206

  
207 207
static int _write_socket_SSL(connection_t *cn, char* message)
208 208
{
209
	int count, size;
209
	int count;
210
	size_t size;
210 211

  
211 212
	size = sizeof(char)*strlen(message);
212 213

  
......
304 305
		count = write(cn->handle, ((const char *)message) + tcount,
305 306
					size - tcount);
306 307
		if (count > 0) {
307
			tcount += count;
308
			tcount += (size_t)count;
308 309
			if (tcount == size)
309 310
				return WRITE_OK;
310 311
		}
......
805 806
		 * cn->lasttoken is the number of milliseconds when we
806 807
		 * last added a token to the bucket */
807 808
		if (!clock_gettime(CLOCK_MONOTONIC, &tv)) {
808
			now = tv.tv_sec * 1000 + tv.tv_nsec / 1000000;
809
			if (tv.tv_sec < 0 || tv.tv_nsec < 0)
810
				fatal("clock_gettime returned negative time");
811
			now = (unsigned long)(tv.tv_sec * 1000 + tv.tv_nsec / 1000000);
809 812
			/* round now to TOKEN_INTERVAL multiple */
810 813
			now -= now % TOKEN_INTERVAL;
811 814
			if (now < cn->lasttoken) {
......
813 816
				cn->token = 1;
814 817
				cn->lasttoken = now;
815 818
			} else if (now > cn->lasttoken + TOKEN_INTERVAL) {
816
				cn->token += (now - cn->lasttoken) /
817
					TOKEN_INTERVAL;
819
				cn->token += (unsigned)((now - cn->lasttoken) /
820
					TOKEN_INTERVAL);
818 821
				if (cn->token > TOKEN_MAX)
819 822
					cn->token = TOKEN_MAX;
820 823
				if (!cn->token)
......
837 840
}
838 841

  
839 842

  
840
list_t *wait_event(list_t *cn_list, int *msec, int *nc)
843
list_t *wait_event(list_t *cn_list, time_t *msec, int *nc)
841 844
{
842 845
	fd_set fds_read, fds_write, fds_except;
843 846
	int maxfd = -1, err, errtime;
......
1066 1069

  
1067 1070
		if (setsockopt(cn->handle, SOL_SOCKET, SO_REUSEADDR,
1068 1071
					(char *)&multi_client,
1069
					sizeof(multi_client)) < 0) {
1072
					(socklen_t)sizeof(multi_client)) < 0) {
1070 1073
			mylog(LOG_WARN, "setsockopt() : %s", strerror(errno));
1071 1074
			close(cn->handle);
1072 1075
			cn->handle = -1;
......
1099 1102
	cn->connected = CONN_ERROR;
1100 1103
}
1101 1104

  
1102
static connection_t *connection_init(int anti_flood, int ssl, int timeout,
1105
static connection_t *connection_init(int anti_flood, int ssl, time_t timeout,
1103 1106
		int listen)
1104 1107
{
1105 1108
	connection_t *conn;
......
1141 1144
	/* Return ephemeral DH parameters. */
1142 1145
	DH *dh = NULL;
1143 1146
	FILE *f;
1144
	int ret;
1147
	long ret;
1145 1148

  
1146 1149
	if ((f = fopen(conf_client_dh_file, "r")) == NULL) {
1147 1150
		mylog(LOG_ERROR, "Unable to open DH parameters (%s): %s",
......
1272 1275
	 * SSL flag is only here to tell program to convert socket to SSL after
1273 1276
	 * accept(). Listening socket will NOT be SSL
1274 1277
	 */
1275
	conn = connection_init(0, ssl, 0, 1);
1278
	conn = connection_init(0, ssl, (time_t)0, 1);
1276 1279
	create_listening_socket(hostname, portbuf, conn);
1277 1280

  
1278 1281
	return conn;
1279 1282
}
1280 1283

  
1281 1284
static connection_t *_connection_new(char *dsthostname, char *dstport,
1282
		char *srchostname, char *srcport, int timeout)
1285
		char *srchostname, char *srcport, time_t timeout)
1283 1286
{
1284 1287
	connection_t *conn;
1285 1288

  
......
1292 1295
#ifdef HAVE_LIBSSL
1293 1296
static SSL_CTX *SSL_init_context(char *ciphers)
1294 1297
{
1295
	int fd, flags, ret, rng;
1298
	int fd, flags, rng;
1299
	ssize_t ret;
1296 1300
	char buf[1025];
1297 1301
	SSL_CTX *ctx;
1298 1302

  
......
1322 1326
			}
1323 1327
			mylog(LOG_DEBUG, "PRNG seeded with %d /dev/random "
1324 1328
					"bytes", ret);
1325
			RAND_seed(buf, ret);
1329
			RAND_seed(buf, (int)ret);
1326 1330
		} while (!(rng = RAND_status()));
1327 1331

  
1328 1332
prng_end:
......
1426 1430
	if (!result) {
1427 1431
		/* We have a verify error! Log it */
1428 1432
		mylog(LOG_ERROR, "SSL cert check failed at depth=%d: %s (%d)",
1429
				depth, X509_verify_cert_error_string(err), err);
1433
				depth, X509_verify_cert_error_string((long)err), err);
1430 1434
	}
1431 1435

  
1432 1436
	return result;
......
1435 1439
static int SSLize(connection_t *cn, int *nc)
1436 1440
{
1437 1441
	int err, err2;
1442
	long errl;
1438 1443

  
1439 1444
	if (cn == NULL)
1440 1445
		return 1;
......
1461 1466
	if (err2 == SSL_ERROR_NONE) {
1462 1467
		const SSL_CIPHER *cipher;
1463 1468
		char buf[128];
1464
		int len;
1469
		size_t len;
1465 1470

  
1466 1471
		cipher = SSL_get_current_cipher(cn->ssl_h);
1467 1472
		SSL_CIPHER_description(cipher, buf, 128);
......
1480 1485
	case SSL_CHECK_NONE:
1481 1486
		break;
1482 1487
	case SSL_CHECK_BASIC:
1483
		if((err = SSL_get_verify_result(cn->ssl_h)) != X509_V_OK) {
1484
			mylog(LOG_ERROR, "Certificate check failed: %s (%d)!",
1485
				X509_verify_cert_error_string(err), err);
1488
		if((errl = SSL_get_verify_result(cn->ssl_h)) != X509_V_OK) {
1489
			mylog(LOG_ERROR, "Certificate check failed: %s (%ld)!",
1490
				X509_verify_cert_error_string(errl), errl);
1486 1491
			cn->connected = CONN_UNTRUSTED;
1487 1492
			return 1;
1488 1493
		}
1489 1494
		break;
1490 1495
	case SSL_CHECK_CA:
1491
		if((err = SSL_get_verify_result(cn->ssl_h)) != X509_V_OK) {
1492
			mylog(LOG_ERROR, "Certificate check failed: %s (%d)!",
1493
				X509_verify_cert_error_string(err), err);
1496
		if((errl = SSL_get_verify_result(cn->ssl_h)) != X509_V_OK) {
1497
			mylog(LOG_ERROR, "Certificate check failed: %s (%ld)!",
1498
				X509_verify_cert_error_string(errl), errl);
1494 1499
			cn->connected = CONN_UNTRUSTED;
1495 1500
			return 1;
1496 1501
		}
......
1520 1525

  
1521 1526
static connection_t *_connection_new_SSL(char *dsthostname, char *dstport,
1522 1527
		char *srchostname, char *srcport, char *ciphers, int check_mode,
1523
		char *check_store, char *ssl_client_certfile, int timeout)
1528
		char *check_store, char *ssl_client_certfile, time_t timeout)
1524 1529
{
1525 1530
	connection_t *conn;
1526 1531

  
......
1640 1645

  
1641 1646
connection_t *connection_new(char *dsthostname, int dstport, char *srchostname,
1642 1647
		int srcport, int ssl, char *ssl_ciphers, int ssl_check_mode,
1643
		char *ssl_check_store, char *ssl_client_certfile, int timeout)
1648
		char *ssl_check_store, char *ssl_client_certfile, time_t timeout)
1644 1649
{
1645 1650
	char dstportbuf[20], srcportbuf[20], *tmp;
1646 1651
#ifndef HAVE_LIBSSL
......
1726 1731
		fprintf(stderr,"Usage: %s host port\n",argv[0]);
1727 1732
		exit(1);
1728 1733
	}
1729
	conn = connection_init(0, 0, 0, 1);
1734
	conn = connection_init(0, 0, (time_t)0, 1);
1730 1735
	conn->connect_time = time(NULL);
1731 1736
	create_listening_socket(argv[1],argv[2],&conn);
1732 1737
	if (s == -1) {
......
1754 1759
}
1755 1760
#endif
1756 1761

  
1757
int connection_localport(connection_t *cn)
1762
uint16_t connection_localport(connection_t *cn)
1758 1763
{
1759 1764
	struct sockaddr_in addr;
1760 1765
	int err;
1761 1766
	socklen_t addrlen;
1762 1767

  
1763 1768
	if (cn->handle <= 0)
1764
		return -1;
1769
		return 0;
1765 1770

  
1766 1771
	addrlen = sizeof(addr);
1767 1772
	err = getsockname(cn->handle, (struct sockaddr *)&addr, &addrlen);
1768 1773
	if (err != 0) {
1769 1774
		mylog(LOG_ERROR, "in getsockname(%d): %s", cn->handle,
1770 1775
				strerror(errno));
1771
		return -1;
1776
		return 0;
1772 1777
	}
1773 1778

  
1774 1779
	return ntohs(addr.sin_port);
1775 1780
}
1776 1781

  
1777
int connection_remoteport(connection_t *cn)
1782
uint16_t connection_remoteport(connection_t *cn)
1778 1783
{
1779 1784
	struct sockaddr_in addr;
1780 1785
	int err;
1781 1786
	socklen_t addrlen;
1782 1787

  
1783 1788
	if (cn->handle <= 0)
1784
		return -1;
1789
		return 0;
1785 1790

  
1786 1791
	addrlen = sizeof(addr);
1787 1792
	err = getpeername(cn->handle, (struct sockaddr *)&addr, &addrlen);
1788 1793
	if (err != 0) {
1789 1794
		mylog(LOG_ERROR, "in getpeername(%d): %s", cn->handle,
1790 1795
				strerror(errno));
1791
		return -1;
1796
		return 0;
1792 1797
	}
1793 1798

  
1794 1799
	return ntohs(addr.sin_port);
src/connection.h
92 92

  
93 93
connection_t *connection_new(char *dsthostname, int dstport, char *srchostname,
94 94
		int srcport, int ssl, char *ssl_ciphers, int ssl_check_mode,
95
		char *ssl_check_store, char *ssl_client_certfile, int timeout);
95
		char *ssl_check_store, char *ssl_client_certfile, time_t timeout);
96 96
connection_t *listen_new(char *hostname, int port, int ssl);
97 97
connection_t *accept_new(connection_t *cn);
98 98
void connection_free(connection_t *cn);
......
102 102
void write_lines(connection_t *cn, list_t *lines);
103 103
void write_line_fast(connection_t *cn, char *line);
104 104
list_t *read_lines(connection_t *cn, int *error);
105
list_t *wait_event(list_t *cn_list, int *msec, int *nc);
105
list_t *wait_event(list_t *cn_list, time_t *msec, int *nc);
106 106

  
107 107
int cn_is_connected(connection_t *cn);
108 108
int cn_is_listening(connection_t *cn);
109 109

  
110
int connection_localport(connection_t *cn);
111
int connection_remoteport(connection_t *cn);
110
uint16_t connection_localport(connection_t *cn);
111
uint16_t connection_remoteport(connection_t *cn);
112 112
char *connection_localip(connection_t *cn);
113 113
char *connection_remoteip(connection_t *cn);
114 114
#endif
src/irc.c
53 53
static void server_set_prefix(struct link_server *l, const char *prefix);
54 54
static void server_init_modes(struct link_server *s);
55 55
static int bip_get_index(const char* str, char car);
56
static int bip_fls(int v);
56
static int bip_fls(long v);
57 57

  
58 58
void oidentd_dump(bip_t *bip);
59 59

  
......
99 99
		nick++;
100 100
	if (!*nick)
101 101
		return bip_strdup(mask);
102
	len = nick - mask;
102
	len = (size_t)(nick - mask); // cannot be < 0
103 103
	ret = bip_malloc(len + 1);
104 104
	memcpy(ret, mask, len);
105 105
	ret[len] = 0;
......
491 491
						newnick[7] = '`';
492 492
					}
493 493
				} else {
494
					newnick[8] = rand() *
495
						('z' - 'a') / RAND_MAX + 'a';
494
					newnick[8] = (char)('a' + ('z' - 'a') *
495
							rand() / RAND_MAX);
496 496
				}
497 497
				newnick[9] = 0;
498 498
			}
......
1123 1123
		ks = NULL;
1124 1124

  
1125 1125
	while ((e = strchr(s, ','))) {
1126
		size_t len = e - s;
1126
		size_t len = (size_t)(e - s); // cannot be < 0 or NULL per while
1127 1127
		char *p = bip_malloc(len + 1);
1128 1128
		size_t klen;
1129 1129
		char *kp = NULL;
......
1135 1135
				ke = strchr(ks, ',');
1136 1136
				if (!ke)
1137 1137
					ke = ks + strlen(ks);
1138
				klen = ke - ks;
1138
				klen = (size_t)(ke - ks);
1139 1139
				kp = bip_malloc(klen + 1);
1140 1140
				memcpy(kp, ks, klen);
1141 1141
				kp[klen] = 0;
......
1495 1495
		while (*eon && *eon != ' ')
1496 1496
			eon++;
1497 1497

  
1498
		len = eon - names;
1498
		len = (size_t)(eon - names); // cannot be < 0
1499 1499
		nick = bip_malloc(len + 1);
1500 1500
		memcpy(nick, names, len);
1501 1501
		nick[len] = 0;
......
1622 1622

  
1623 1623
static void mode_add_letter_uniq(struct link_server *s, char c)
1624 1624
{
1625
	int i;
1625
	size_t i;
1626 1626
	for (i = 0; i < s->user_mode_len; i++) {
1627 1627
		if (s->user_mode[i] == c)
1628 1628
			return;
......
1633 1633

  
1634 1634
static void mode_remove_letter(struct link_server *s, char c)
1635 1635
{
1636
	int i;
1636
	size_t i;
1637 1637
	for (i = 0; i < s->user_mode_len; i++) {
1638 1638
		if (s->user_mode[i] == c) {
1639 1639
			for (; i < s->user_mode_len - 1; i++)
......
1671 1671
	struct channel *channel;
1672 1672
	const char *mode;
1673 1673
	int add = 1;
1674
	unsigned cur_arg = 0;
1674
	int cur_arg = 0;
1675 1675
	array_t *mode_args = NULL;
1676 1676
	int ret;
1677 1677

  
......
2347 2347
#else
2348 2348
				0, NULL, 0, NULL, NULL,
2349 2349
#endif
2350
				CONNECT_TIMEOUT);
2350
				(time_t)CONNECT_TIMEOUT);
2351 2351
	assert(conn);
2352 2352
	if (conn->handle == -1) {
2353 2353
		mylog(LOG_INFO, "[%s] Cannot connect.", link->name);
......
2697 2697
 */
2698 2698
void irc_main(bip_t *bip)
2699 2699
{
2700
	int timeleft = 1000;
2700
	time_t timeleft = 1000;
2701 2701

  
2702 2702
	if (bip->reloading_client) {
2703 2703
		char *l;
......
2834 2834
		if (cur || modes) {
2835 2835
			size_t len;
2836 2836
			if (cur)
2837
				len = cur - modes;
2837
				// cur can't be lower than modes if !NULL
2838
				len = (size_t)(cur - modes);
2838 2839
			else
2839 2840
				len = strlen(modes); // last piece
2840 2841
			dup = bip_malloc(len + 1);
......
2854 2855
static void server_set_prefix(struct link_server *s, const char *modes)
2855 2856
{
2856 2857
	char * end_mode;
2857
	unsigned int len;
2858
	size_t len;
2858 2859

  
2859 2860
	mylog(LOG_DEBUG, "[%s] Set user modes", LINK(s)->name);
2860 2861

  
......
2866 2867
		return;
2867 2868
	}
2868 2869

  
2869
	len = end_mode - modes - 1; // len of mode without '('
2870
	// end_mode can't be lower than (modes + 1)
2871
	len = (size_t)(end_mode - modes - 1); // len of mode without '('
2870 2872
	if (len * 2 + 2 != strlen(modes)) {
2871 2873
		mylog(LOG_WARN, "[%s] Unable to parse PREFIX parameter", LINK(s)->name);
2872 2874
		return;
......
2894 2896
		return 0;
2895 2897
}
2896 2898

  
2897
static int bip_fls(int v)
2899
static int bip_fls(long v)
2898 2900
{
2899
	unsigned int r = 0;
2901
	int r = 0;
2900 2902
	while (v >>= 1)
2901 2903
		r++;
2902 2904

  
src/irc.h
235 235
	hash_t channels;
236 236

  
237 237
	char *user_mode;
238
	int user_mode_len;
238
	size_t user_mode_len;
239 239

  
240 240
	/* init stuff */
241 241
	int lag;
src/line.c
164 164
			irc_line_free(line);
165 165
			return NULL;
166 166
		}
167
		len = space - str - 1; /* leading ':' */
167
		// space is at least str + 1, len >= 0
168
		len = (size_t)(space - str - 1); /* leading ':' */
168 169
		line->origin = bip_malloc(len + 1);
169 170
		memcpy(line->origin, str + 1, len);
170 171
		line->origin[len] = 0;
......
187 188
			while (*space && *space != ' ')
188 189
				space++;
189 190
		}
190
		len = space - str;
191
		// str is the start of string
192
		// space is the end of string or end of word
193
		len = (size_t)(space - str);
191 194
		tmp = bip_malloc(len + 1);
192 195
		memcpy(tmp, str, len);
193 196
		tmp[len] = 0;
src/log.c
27 27

  
28 28
extern FILE *conf_global_log_file;
29 29

  
30
static int _log_write(log_t *logdata, logstore_t *lf, const char *d,
30
static size_t _log_write(log_t *logdata, logstore_t *lf, const char *d,
31 31
		const char *str);
32 32
static char *_log_wrap(const char *dest, const char *line);
33 33
void logfile_free(logfile_t *lf);
......
72 72

  
73 73
int check_dir_r(char *dirname)
74 74
{
75
	int pos, count = 0;
75
	size_t count = 0;
76 76
	char *dir, *tmp;
77
	int len = strlen(dirname);
77
	size_t len = strlen(dirname);
78
	size_t pos;
78 79

  
79 80
	mylog(LOG_DEBUGVERB, "Recursive check of %s engaged", dirname);
80 81
	tmp = dirname;
......
109 110
	char *c;
110 111

  
111 112
	for (c = str; *c != '\0'; c++)
112
		*c = tolower(*c);
113
		*c = (char)tolower(*c); // tolower()->int but should be safe to cast
113 114
}
114 115

  
115 116
/*
......
120 121
void replace_var(char *str, char *var, char *value, unsigned int max)
121 122
{
122 123
	char *pos;
123
	unsigned int lenvar = strlen(var);
124
	unsigned int lenval = strlen(value);
124
	size_t lenvar = strlen(var);
125
	size_t lenval = strlen(value);
125 126

  
126 127
	while((pos = strstr(str, var))) {
127 128
		/* Make room */
......
851 852
	assert(buf);
852 853

  
853 854
	p = strchr(buf, ' ');
855
	// buf...p
854 856
	if (!p || !p[0] || !p[1])
855 857
		return _log_wrap(dest, buf);
856 858
	p++;
859
	// buf...p
857 860
	sots = logdata->user->backlog_timestamp == BLTSDateTime ? buf : p;
861
	// buf...sots=p OR sots=buf...p
858 862
	p = strchr(p, ' ');
863
	// buf...sots...p OR sots=buf...p
859 864
	if (!p || !p[0] || !p[1])
860 865
		return _log_wrap(dest, buf);
861
	lots = p - sots;
866
	lots = (size_t)(p - sots);
862 867
	p++;
863 868

  
864 869
	if (strncmp(p, "-!-", (size_t)3) == 0) {
......
891 896
		p++;
892 897
	if (!p[0])
893 898
		return _log_wrap(dest, buf);
894
	lon = p - son;
899
	lon = (size_t)(p - son);
895 900

  
896 901
	p = strchr(p, ' ');
897 902
	if (!p || !p[0] || !p[1])
......
908 913
	if (lom == 0)
909 914
		return _log_wrap(dest, buf);
910 915

  
916
	// action and out are 0 or 1, safe to cast
911 917
	p = ret = (char *)bip_malloc(
912 918
		1 + lon + strlen(LAMESTRING) + strlen(dest) + 2 + lots + 2 +
913
		lom + 3 + action * (2 + strlen("ACTION ")) +
914
		out * strlen(PMSG_ARROW));
919
		lom + 3 + (size_t)action * (2 + strlen("ACTION ")) +
920
		(size_t)out * strlen(PMSG_ARROW));
915 921

  
916 922
	*p++ = ':';
917 923

  
......
1024 1030
			/* error or oef */
1025 1031
			break;
1026 1032
		}
1027
		int slen = strlen(buf);
1033
		size_t slen = strlen(buf);
1034
		if (slen == 0)
1035
			break; // should not happen, per previous fgets block
1028 1036
		if (buf[slen - 1] == '\n')
1029 1037
			buf[slen - 1] = 0;
1030 1038
		if (slen >= 2 && buf[slen] == '\r')
......
1121 1129
	return buf;
1122 1130
}
1123 1131

  
1124
static int _log_write(log_t *logdata, logstore_t *store,
1132
static size_t _log_write(log_t *logdata, logstore_t *store,
1125 1133
		const char *destination, const char *str)
1126 1134
{
1127 1135
	size_t nbwrite;
......
1246 1254
{
1247 1255
	const char *p = str;
1248 1256
	const char *start = str;
1249
	int len;
1257
	size_t len;
1250 1258
	char *extracted;
1251 1259
	array_t *array = array_new();;
1252 1260

  
1253 1261
	do {
1254 1262
		if (!*p || strchr(splt, *p)) {
1255
			len = p - start;
1263
			len = (size_t)(p - start);
1256 1264
			extracted = bip_malloc(len + 1);
1257 1265
			memcpy(extracted, start, len);
1258 1266
			extracted[len] = 0;
src/util.c
285 285
void dump_trace(void)
286 286
{
287 287
	void *array[32];
288
	size_t size;
288
	int size;
289 289

  
290 290
	size = backtrace(array, 32);
291 291
	fflush(conf_global_log_file);
......
629 629
	char c;
630 630
	unsigned long hash = 5381; /* 5381 & 0xff makes more sense */
631 631

  
632
	// toupper should not return negative values (only char compatible int)
632 633
	while ((c = *pkey++))
633
		hash = ((hash << 5) + hash) ^ toupper(c);
634
		hash = ((hash << 5) + hash) ^ (long unsigned)toupper(c);
634 635
	return (unsigned char)hash;
635 636
}
636 637

  
......
809 810
void strucase(char *s)
810 811
{
811 812
	while (*s) {
812
		*s = toupper(*s);
813
		*s = (char)toupper(*s); // toupper, safe to cast to char
813 814
		s++;
814 815
	}
815 816
}
......
839 840

  
840 841
	if (array_includes(a, index))
841 842
		return;
842
	a->elemv = bip_realloc(a->elemv, sizeof(void *) * (index + 1));
843
	memset(a->elemv + a->elemc, 0, sizeof(void *) * (index + 1 - a->elemc));
843
	a->elemv = bip_realloc(a->elemv, sizeof(void *) * (size_t)(index + 1));
844
	// a->elemc should be lower than index + 1
845
	memset(a->elemv + a->elemc, 0,
846
			sizeof(void *) * (size_t)(index + 1 - a->elemc));
844 847
	a->elemc = index + 1;
845 848
}
846 849

  
847
- 
(9-9/24)