Commit 07c76b666dc8e8fd2fb4f2b716f65687b60af8c7

Guillem Jover 2017-06-05T06:17:27

Do not use legacy BSD u_* types Some systems do not have these types available, and they are simply convenience aliases. Instead use the expanded versions which are more portable. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=101192

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
diff --git a/include/bsd/netinet/ip_icmp.h b/include/bsd/netinet/ip_icmp.h
index 0742aa6..45f5d72 100644
--- a/include/bsd/netinet/ip_icmp.h
+++ b/include/bsd/netinet/ip_icmp.h
@@ -33,7 +33,7 @@
 #ifndef _NETINET_IP_ICMP_H_
 #define _NETINET_IP_ICMP_H_
 
-#include <sys/types.h>		/* u_int32_t, u_char */
+#include <sys/types.h>		/* uint32_t */
 #include <netinet/in.h>		/* in_addr */
 #include <netinet/in_systm.h>	/* n_short */
 #include <netinet/ip.h>		/* idi_ip */
@@ -47,19 +47,19 @@
  * Internal of an ICMP Router Advertisement
  */
 struct icmp_ra_addr {
-	u_int32_t ira_addr;
-	u_int32_t ira_preference;
+	uint32_t ira_addr;
+	uint32_t ira_preference;
 };
 
 /*
  * Structure of an icmp header.
  */
 struct icmp {
-	u_char	icmp_type;		/* type of message, see below */
-	u_char	icmp_code;		/* type sub code */
-	u_short	icmp_cksum;		/* ones complement cksum of struct */
+	unsigned char	icmp_type;	/* type of message, see below */
+	unsigned char	icmp_code;	/* type sub code */
+	unsigned short	icmp_cksum;	/* ones complement cksum of struct */
 	union {
-		u_char ih_pptr;			/* ICMP_PARAMPROB */
+		unsigned char ih_pptr;		/* ICMP_PARAMPROB */
 		struct in_addr ih_gwaddr;	/* ICMP_REDIRECT */
 		struct ih_idseq {
 			n_short	icd_id;
@@ -74,9 +74,9 @@ struct icmp {
 		} ih_pmtu;
 
 		struct ih_rtradv {
-			u_char irt_num_addrs;
-			u_char irt_wpa;
-			u_int16_t irt_lifetime;
+			unsigned char irt_num_addrs;
+			unsigned char irt_wpa;
+			uint16_t irt_lifetime;
 		} ih_rtradv;
 	} icmp_hun;
 #define	icmp_pptr	icmp_hun.ih_pptr
@@ -100,7 +100,7 @@ struct icmp {
 			/* options and then 64 bits of data */
 		} id_ip;
 		struct icmp_ra_addr id_radv;
-		u_int32_t id_mask;
+		uint32_t id_mask;
 		char	id_data[1];
 	} icmp_dun;
 #define	icmp_otime	icmp_dun.id_ts.its_otime
diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index 0604cad..46a009e 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -49,7 +49,7 @@
 __BEGIN_DECLS
 uint32_t arc4random(void);
 void arc4random_stir(void);
-void arc4random_addrandom(u_char *dat, int datlen);
+void arc4random_addrandom(unsigned char *dat, int datlen);
 void arc4random_buf(void *_buf, size_t n);
 uint32_t arc4random_uniform(uint32_t upper_bound);
 
diff --git a/src/arc4random.c b/src/arc4random.c
index fb16757..c6f89c3 100644
--- a/src/arc4random.c
+++ b/src/arc4random.c
@@ -59,7 +59,7 @@ static struct _rs {
 /* Maybe be preserved in fork children, if _rs_allocate() decides. */
 static struct _rsx {
 	chacha_ctx	rs_chacha;	/* chacha context for random keystream */
-	u_char		rs_buf[RSBUFSZ];	/* keystream blocks */
+	unsigned char	rs_buf[RSBUFSZ];	/* keystream blocks */
 } *rsx;
 
 static inline int _rs_allocate(struct _rs **, struct _rsx **);
@@ -67,7 +67,7 @@ static inline void _rs_forkdetect(void);
 #include "arc4random.h"
 
 static inline void
-_rs_init(u_char *buf, size_t n)
+_rs_init(unsigned char *buf, size_t n)
 {
 	if (n < KEYSZ + IVSZ)
 		return;
@@ -82,7 +82,7 @@ _rs_init(u_char *buf, size_t n)
 }
 
 static inline void
-_rs_rekey(u_char *dat, size_t datlen)
+_rs_rekey(unsigned char *dat, size_t datlen)
 {
 #ifndef KEYSTREAM_ONLY
 	memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf));
@@ -107,7 +107,7 @@ _rs_rekey(u_char *dat, size_t datlen)
 static void
 _rs_stir(void)
 {
-	u_char rnd[KEYSZ + IVSZ];
+	unsigned char rnd[KEYSZ + IVSZ];
 
 	if (getentropy(rnd, sizeof rnd) == -1)
 		_getentropy_fail();
@@ -140,8 +140,8 @@ _rs_stir_if_needed(size_t len)
 static inline void
 _rs_random_buf(void *_buf, size_t n)
 {
-	u_char *buf = (u_char *)_buf;
-	u_char *keystream;
+	unsigned char *buf = (unsigned char *)_buf;
+	unsigned char *keystream;
 	size_t m;
 
 	_rs_stir_if_needed(n);
@@ -164,7 +164,7 @@ _rs_random_buf(void *_buf, size_t n)
 static inline void
 _rs_random_u32(uint32_t *val)
 {
-	u_char *keystream;
+	unsigned char *keystream;
 
 	_rs_stir_if_needed(sizeof(*val));
 	if (rs->rs_have < sizeof(*val))
@@ -184,7 +184,7 @@ arc4random_stir(void)
 }
 
 void
-arc4random_addrandom(u_char *dat, int datlen)
+arc4random_addrandom(unsigned char *dat, int datlen)
 {
 	_ARC4_LOCK();
 	_rs_stir_if_needed(datlen);
diff --git a/src/chacha_private.h b/src/chacha_private.h
index b720d93..5aae8d8 100644
--- a/src/chacha_private.h
+++ b/src/chacha_private.h
@@ -92,7 +92,7 @@ chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes)
   u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
   u8 *ctarget = NULL;
   u8 tmp[64];
-  u_int i;
+  unsigned int i;
 
   if (!bytes) return;
 
diff --git a/src/getentropy_bsd.c b/src/getentropy_bsd.c
index 1959984..d45901b 100644
--- a/src/getentropy_bsd.c
+++ b/src/getentropy_bsd.c
@@ -30,7 +30,7 @@
  * Derived from lib/libc/gen/arc4random.c from FreeBSD.
  */
 static size_t
-getentropy_sysctl(u_char *buf, size_t size)
+getentropy_sysctl(unsigned char *buf, size_t size)
 {
 	int mib[2];
 	size_t len, done;
diff --git a/src/hash/helper.c b/src/hash/helper.c
index 1c63564..d9362d3 100644
--- a/src/hash/helper.c
+++ b/src/hash/helper.c
@@ -51,7 +51,7 @@ char *
 HASHFileChunk(const char *filename, char *buf, off_t off, off_t len)
 {
 	struct stat sb;
-	u_char buffer[BUFSIZ];
+	unsigned char buffer[BUFSIZ];
 	HASH_CTX ctx;
 	int fd, save_errno;
 	ssize_t nr;
@@ -92,7 +92,7 @@ HASHFile(const char *filename, char *buf)
 }
 
 char *
-HASHData(const u_char *data, size_t len, char *buf)
+HASHData(const unsigned char *data, size_t len, char *buf)
 {
 	HASH_CTX ctx;
 
diff --git a/src/inet_net_pton.c b/src/inet_net_pton.c
index 28c55ba..b0147f6 100644
--- a/src/inet_net_pton.c
+++ b/src/inet_net_pton.c
@@ -39,7 +39,7 @@ __FBSDID("$FreeBSD: src/lib/libc/net/inet_net_pton.c,v 1.9 2003/09/15 23:38:06 f
 # define SPRINTF(x) ((size_t)sprintf x)
 #endif
 
-static int	inet_net_pton_ipv4(const char *src, u_char *dst, size_t size);
+static int	inet_net_pton_ipv4(const char *src, unsigned char *dst, size_t size);
 
 /*
  * static int
@@ -83,13 +83,13 @@ inet_net_pton(int af, const char *src, void *dst, size_t size)
  *	Paul Vixie (ISC), June 1996
  */
 static int
-inet_net_pton_ipv4(const char *src, u_char *dst, size_t size)
+inet_net_pton_ipv4(const char *src, unsigned char *dst, size_t size)
 {
 	static const char
 		xdigits[] = "0123456789abcdef",
 		digits[] = "0123456789";
 	int n, ch, tmp, dirty, bits;
-	const u_char *odst = dst;
+	const unsigned char *odst = dst;
 
 	ch = *src++;
 	if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
@@ -130,7 +130,7 @@ inet_net_pton_ipv4(const char *src, u_char *dst, size_t size)
 				 isascii(ch) && isdigit(ch));
 			if (size-- <= 0)
 				goto emsgsize;
-			*dst++ = (u_char) tmp;
+			*dst++ = (unsigned char) tmp;
 			if (ch == '\0' || ch == '/')
 				break;
 			if (ch != '.')
diff --git a/src/merge.c b/src/merge.c
index c82594c..dc92b44 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -56,13 +56,13 @@ __FBSDID("$FreeBSD$");
 #include <stdlib.h>
 #include <string.h>
 
-static void setup(u_char *, u_char *, size_t, size_t,
+static void setup(unsigned char *, unsigned char *, size_t, size_t,
     int (*)(const void *, const void *));
-static void insertionsort(u_char *, size_t, size_t,
+static void insertionsort(unsigned char *, size_t, size_t,
     int (*)(const void *, const void *));
 
 #define ISIZE sizeof(int)
-#define PSIZE sizeof(u_char *)
+#define PSIZE sizeof(unsigned char *)
 #define ICOPY_LIST(src, dst, last)				\
 	do							\
 	*(int*)dst = *(int*)src, src += ISIZE, dst += ISIZE;	\
@@ -87,9 +87,10 @@ static void insertionsort(u_char *, size_t, size_t,
  * boundaries.
  */
 /* Assumption: PSIZE is a power of 2. */
-#define EVAL(p) (u_char **)						\
-	((u_char *)0 +							\
-	    (((u_char *)p + PSIZE - 1 - (u_char *) 0) & ~(PSIZE - 1)))
+#define EVAL(p) (unsigned char **)					\
+	((unsigned char *)0 +						\
+	 (((unsigned char *)p + PSIZE - 1 -				\
+	   (unsigned char *)0) & ~(PSIZE - 1)))
 
 /*
  * Arguments are as for qsort.
@@ -101,8 +102,8 @@ mergesort(void *base, size_t nmemb, size_t size,
 	size_t i;
 	int sense;
 	int big, iflag;
-	u_char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2;
-	u_char *list2, *list1, *p2, *p, *last, **p1;
+	unsigned char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2;
+	unsigned char *list2, *list1, *p2, *p, *last, **p1;
 
 	if (size < PSIZE / 2) {		/* Pointers must fit into 2 * size. */
 		errno = EINVAL;
@@ -256,16 +257,16 @@ COPY:	    			b = t;
  * is defined.  Otherwise simple pairwise merging is used.)
  */
 static void
-setup(u_char *list1, u_char *list2, size_t n, size_t size,
+setup(unsigned char *list1, unsigned char *list2, size_t n, size_t size,
 	int (*cmp)(const void *, const void *))
 {
 	int i, length, size2, tmp, sense;
-	u_char *f1, *f2, *s, *l2, *last, *p2;
+	unsigned char *f1, *f2, *s, *l2, *last, *p2;
 
 	size2 = size*2;
 	if (n <= 5) {
 		insertionsort(list1, n, size, cmp);
-		*EVAL(list2) = (u_char*) list2 + n*size;
+		*EVAL(list2) = (unsigned char*) list2 + n*size;
 		return;
 	}
 	/*
@@ -328,10 +329,10 @@ setup(u_char *list1, u_char *list2, size_t n, size_t size,
  * last 4 elements.
  */
 static void
-insertionsort(u_char *a, size_t n, size_t size,
+insertionsort(unsigned char *a, size_t n, size_t size,
 	int (*cmp)(const void *, const void *))
 {
-	u_char *ai, *s, *t, *u, tmp;
+	unsigned char *ai, *s, *t, *u, tmp;
 	int i;
 
 	for (ai = a+size; --n >= 1; ai += size)
diff --git a/src/nlist.c b/src/nlist.c
index 0cffe55..a066935 100644
--- a/src/nlist.c
+++ b/src/nlist.c
@@ -117,7 +117,7 @@ __aout_fdnlist(int fd, struct nlist *list)
 	struct nlist *p, *symtab;
 	caddr_t strtab, a_out_mmap;
 	off_t stroff, symoff;
-	u_long symsize;
+	unsigned long symsize;
 	int nent;
 	struct exec * exec;
 	struct stat st;
diff --git a/src/radixsort.c b/src/radixsort.c
index ad2ae70..77ae52c 100644
--- a/src/radixsort.c
+++ b/src/radixsort.c
@@ -59,14 +59,14 @@ __RCSID("$NetBSD: radixsort.c,v 1.18 2009/08/21 20:49:50 dsl Exp $");
 #include <errno.h>
 
 typedef struct {
-	const u_char **sa;
+	const unsigned char **sa;
 	int sn, si;
 } stack;
 
-static inline void simplesort(const u_char **, int, int, const u_char *, u_int);
-static void r_sort_a(const u_char **, int, int, const u_char *, u_int);
-static void r_sort_b(const u_char **,
-	    const u_char **, int, int, const u_char *, u_int);
+static inline void simplesort(const unsigned char **, int, int, const unsigned char *, unsigned int);
+static void r_sort_a(const unsigned char **, int, int, const unsigned char *, unsigned int);
+static void r_sort_b(const unsigned char **,
+	    const unsigned char **, int, int, const unsigned char *, unsigned int);
 
 #define	THRESHOLD	20		/* Divert to simplesort(). */
 #define	SIZE		512		/* Default stack size. */
@@ -91,11 +91,12 @@ static void r_sort_b(const u_char **,
 }
 
 int
-radixsort(const u_char **a, int n, const u_char *tab, u_int endch)
+radixsort(const unsigned char **a, int n, const unsigned char *tab,
+          unsigned int endch)
 {
-	const u_char *tr;
-	u_int c;
-	u_char tr0[256];
+	const unsigned char *tr;
+	unsigned int c;
+	unsigned char tr0[256];
 
 	SETUP;
 	r_sort_a(a, n, 0, tr, endch);
@@ -103,11 +104,12 @@ radixsort(const u_char **a, int n, const u_char *tab, u_int endch)
 }
 
 int
-sradixsort(const u_char **a, int n, const u_char *tab, u_int endch)
+sradixsort(const unsigned char **a, int n, const unsigned char *tab,
+           unsigned int endch)
 {
-	const u_char *tr, **ta;
-	u_int c;
-	u_char tr0[256];
+	const unsigned char *tr, **ta;
+	unsigned int c;
+	unsigned char tr0[256];
 
 	if (a == NULL) {
 		errno = EFAULT;
@@ -134,14 +136,15 @@ sradixsort(const u_char **a, int n, const u_char *tab, u_int endch)
 
 /* Unstable, in-place sort. */
 static void
-r_sort_a(const u_char **a, int n, int i, const u_char *tr, u_int endch)
+r_sort_a(const unsigned char **a, int n, int i, const unsigned char *tr,
+         unsigned int endch)
 {
-	static u_int count[256], nc, bmin;
-	u_int c;
-	const u_char **ak, *r;
+	static unsigned int count[256], nc, bmin;
+	unsigned int c;
+	const unsigned char **ak, *r;
 	stack s[SIZE], *sp, *sp0, *sp1, temp;
-	u_int *cp, bigc;
-	const u_char **an, *t, **aj, **top[256];
+	unsigned int *cp, bigc;
+	const unsigned char **an, *t, **aj, **top[256];
 
 	/* Set up stack. */
 	sp = s;
@@ -176,7 +179,7 @@ r_sort_a(const u_char **a, int n, int i, const u_char *tr, u_int endch)
 		 * character at position i, move on to the next
 		 * character.
 		 */
-		if (nc == 1 && count[bmin] == (u_int)n) {
+		if (nc == 1 && count[bmin] == (unsigned int)n) {
 			push(a, n, i+1);
 			nc = count[bmin] = 0;
 			continue;
@@ -232,15 +235,15 @@ r_sort_a(const u_char **a, int n, int i, const u_char *tr, u_int endch)
 
 /* Stable sort, requiring additional memory. */
 static void
-r_sort_b(const u_char **a, const u_char **ta, int n, int i, const u_char *tr,
-    u_int endch)
+r_sort_b(const unsigned char **a, const unsigned char **ta, int n, int i,
+         const unsigned char *tr, unsigned int endch)
 {
-	static u_int count[256], nc, bmin;
-	u_int c;
-	const u_char **ak, **ai;
+	static unsigned int count[256], nc, bmin;
+	unsigned int c;
+	const unsigned char **ak, **ai;
 	stack s[512], *sp, *sp0, *sp1, temp;
-	const u_char **top[256];
-	u_int *cp, bigc;
+	const unsigned char **top[256];
+	unsigned int *cp, bigc;
 
 	sp = s;
 	push(a, n, i);
@@ -302,10 +305,11 @@ r_sort_b(const u_char **a, const u_char **ta, int n, int i, const u_char *tr,
 
 /* insertion sort */
 static inline void
-simplesort(const u_char **a, int n, int b, const u_char *tr, u_int endch)
+simplesort(const unsigned char **a, int n, int b, const unsigned char *tr,
+           unsigned int endch)
 {
-	u_char ch;
-	const u_char  **ak, **ai, *s, *t;
+	unsigned char ch;
+	const unsigned char  **ak, **ai, *s, *t;
 
 	for (ak = a+1; --n >= 1; ak++)
 		for (ai = ak; ai > a; ai--) {
diff --git a/src/unvis.c b/src/unvis.c
index 53da64b..c45a5f8 100644
--- a/src/unvis.c
+++ b/src/unvis.c
@@ -45,8 +45,11 @@
 
 #define	S_HTTP		0x080	/* %HEXHEX escape */
 
-#define	isoctal(c)	(((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
-#define	ishex(c)	((((u_char)(c)) >= '0' && ((u_char)(c)) <= '9') || (((u_char)(c)) >= 'a' && ((u_char)(c)) <= 'f'))
+#define	isoctal(c) \
+	(((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '7')
+#define	ishex(c) \
+	((((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '9') || \
+	 (((unsigned char)(c)) >= 'a' && ((unsigned char)(c)) <= 'f'))
 
 /*
  * unvis - decode characters previously encoded by vis
diff --git a/src/vis.c b/src/vis.c
index f869ed8..c9a06e8 100644
--- a/src/vis.c
+++ b/src/vis.c
@@ -35,17 +35,20 @@
 #include <stdio.h>
 #include <vis.h>
 
-#define	isoctal(c)	(((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
+#define	isoctal(c)	\
+	(((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '7')
 #define	isvisible(c)							\
-	(((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) &&		\
+	(((unsigned int)(c) <= UCHAR_MAX &&				\
+	  isascii((unsigned char)(c)) &&				\
 	(((c) != '*' && (c) != '?' && (c) != '[' && (c) != '#') ||	\
-		(flag & VIS_GLOB) == 0) && isgraph((u_char)(c))) ||	\
+		(flag & VIS_GLOB) == 0) &&				\
+	  isgraph((unsigned char)(c))) ||				\
 	((flag & VIS_SP) == 0 && (c) == ' ') ||				\
 	((flag & VIS_TAB) == 0 && (c) == '\t') ||			\
 	((flag & VIS_NL) == 0 && (c) == '\n') ||			\
 	((flag & VIS_SAFE) && ((c) == '\b' ||				\
 		(c) == '\007' || (c) == '\r' ||				\
-		isgraph((u_char)(c)))))
+		isgraph((unsigned char)(c)))))
 
 /*
  * vis - visually encode characters
@@ -131,9 +134,9 @@ vis(char *dst, int c, int flag, int nextc)
 	}
 	if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) {
 		*dst++ = '\\';
-		*dst++ = ((u_char)c >> 6 & 07) + '0';
-		*dst++ = ((u_char)c >> 3 & 07) + '0';
-		*dst++ = ((u_char)c & 07) + '0';
+		*dst++ = ((unsigned char)c >> 6 & 07) + '0';
+		*dst++ = ((unsigned char)c >> 3 & 07) + '0';
+		*dst++ = ((unsigned char)c & 07) + '0';
 		goto done;
 	}
 	if ((flag & VIS_NOSLASH) == 0)