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
This commit is contained in:
Guillem Jover 2017-06-05 06:17:27 +02:00
parent e4475738fe
commit 07c76b666d
12 changed files with 92 additions and 81 deletions

View File

@ -33,7 +33,7 @@
#ifndef _NETINET_IP_ICMP_H_ #ifndef _NETINET_IP_ICMP_H_
#define _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.h> /* in_addr */
#include <netinet/in_systm.h> /* n_short */ #include <netinet/in_systm.h> /* n_short */
#include <netinet/ip.h> /* idi_ip */ #include <netinet/ip.h> /* idi_ip */
@ -47,19 +47,19 @@
* Internal of an ICMP Router Advertisement * Internal of an ICMP Router Advertisement
*/ */
struct icmp_ra_addr { struct icmp_ra_addr {
u_int32_t ira_addr; uint32_t ira_addr;
u_int32_t ira_preference; uint32_t ira_preference;
}; };
/* /*
* Structure of an icmp header. * Structure of an icmp header.
*/ */
struct icmp { struct icmp {
u_char icmp_type; /* type of message, see below */ unsigned char icmp_type; /* type of message, see below */
u_char icmp_code; /* type sub code */ unsigned char icmp_code; /* type sub code */
u_short icmp_cksum; /* ones complement cksum of struct */ unsigned short icmp_cksum; /* ones complement cksum of struct */
union { union {
u_char ih_pptr; /* ICMP_PARAMPROB */ unsigned char ih_pptr; /* ICMP_PARAMPROB */
struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
struct ih_idseq { struct ih_idseq {
n_short icd_id; n_short icd_id;
@ -74,9 +74,9 @@ struct icmp {
} ih_pmtu; } ih_pmtu;
struct ih_rtradv { struct ih_rtradv {
u_char irt_num_addrs; unsigned char irt_num_addrs;
u_char irt_wpa; unsigned char irt_wpa;
u_int16_t irt_lifetime; uint16_t irt_lifetime;
} ih_rtradv; } ih_rtradv;
} icmp_hun; } icmp_hun;
#define icmp_pptr icmp_hun.ih_pptr #define icmp_pptr icmp_hun.ih_pptr
@ -100,7 +100,7 @@ struct icmp {
/* options and then 64 bits of data */ /* options and then 64 bits of data */
} id_ip; } id_ip;
struct icmp_ra_addr id_radv; struct icmp_ra_addr id_radv;
u_int32_t id_mask; uint32_t id_mask;
char id_data[1]; char id_data[1];
} icmp_dun; } icmp_dun;
#define icmp_otime icmp_dun.id_ts.its_otime #define icmp_otime icmp_dun.id_ts.its_otime

View File

@ -49,7 +49,7 @@
__BEGIN_DECLS __BEGIN_DECLS
uint32_t arc4random(void); uint32_t arc4random(void);
void arc4random_stir(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); void arc4random_buf(void *_buf, size_t n);
uint32_t arc4random_uniform(uint32_t upper_bound); uint32_t arc4random_uniform(uint32_t upper_bound);

View File

@ -59,7 +59,7 @@ static struct _rs {
/* Maybe be preserved in fork children, if _rs_allocate() decides. */ /* Maybe be preserved in fork children, if _rs_allocate() decides. */
static struct _rsx { static struct _rsx {
chacha_ctx rs_chacha; /* chacha context for random keystream */ chacha_ctx rs_chacha; /* chacha context for random keystream */
u_char rs_buf[RSBUFSZ]; /* keystream blocks */ unsigned char rs_buf[RSBUFSZ]; /* keystream blocks */
} *rsx; } *rsx;
static inline int _rs_allocate(struct _rs **, struct _rsx **); static inline int _rs_allocate(struct _rs **, struct _rsx **);
@ -67,7 +67,7 @@ static inline void _rs_forkdetect(void);
#include "arc4random.h" #include "arc4random.h"
static inline void static inline void
_rs_init(u_char *buf, size_t n) _rs_init(unsigned char *buf, size_t n)
{ {
if (n < KEYSZ + IVSZ) if (n < KEYSZ + IVSZ)
return; return;
@ -82,7 +82,7 @@ _rs_init(u_char *buf, size_t n)
} }
static inline void static inline void
_rs_rekey(u_char *dat, size_t datlen) _rs_rekey(unsigned char *dat, size_t datlen)
{ {
#ifndef KEYSTREAM_ONLY #ifndef KEYSTREAM_ONLY
memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf)); memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf));
@ -107,7 +107,7 @@ _rs_rekey(u_char *dat, size_t datlen)
static void static void
_rs_stir(void) _rs_stir(void)
{ {
u_char rnd[KEYSZ + IVSZ]; unsigned char rnd[KEYSZ + IVSZ];
if (getentropy(rnd, sizeof rnd) == -1) if (getentropy(rnd, sizeof rnd) == -1)
_getentropy_fail(); _getentropy_fail();
@ -140,8 +140,8 @@ _rs_stir_if_needed(size_t len)
static inline void static inline void
_rs_random_buf(void *_buf, size_t n) _rs_random_buf(void *_buf, size_t n)
{ {
u_char *buf = (u_char *)_buf; unsigned char *buf = (unsigned char *)_buf;
u_char *keystream; unsigned char *keystream;
size_t m; size_t m;
_rs_stir_if_needed(n); _rs_stir_if_needed(n);
@ -164,7 +164,7 @@ _rs_random_buf(void *_buf, size_t n)
static inline void static inline void
_rs_random_u32(uint32_t *val) _rs_random_u32(uint32_t *val)
{ {
u_char *keystream; unsigned char *keystream;
_rs_stir_if_needed(sizeof(*val)); _rs_stir_if_needed(sizeof(*val));
if (rs->rs_have < sizeof(*val)) if (rs->rs_have < sizeof(*val))
@ -184,7 +184,7 @@ arc4random_stir(void)
} }
void void
arc4random_addrandom(u_char *dat, int datlen) arc4random_addrandom(unsigned char *dat, int datlen)
{ {
_ARC4_LOCK(); _ARC4_LOCK();
_rs_stir_if_needed(datlen); _rs_stir_if_needed(datlen);

View File

@ -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; u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
u8 *ctarget = NULL; u8 *ctarget = NULL;
u8 tmp[64]; u8 tmp[64];
u_int i; unsigned int i;
if (!bytes) return; if (!bytes) return;

View File

@ -30,7 +30,7 @@
* Derived from lib/libc/gen/arc4random.c from FreeBSD. * Derived from lib/libc/gen/arc4random.c from FreeBSD.
*/ */
static size_t static size_t
getentropy_sysctl(u_char *buf, size_t size) getentropy_sysctl(unsigned char *buf, size_t size)
{ {
int mib[2]; int mib[2];
size_t len, done; size_t len, done;

View File

@ -51,7 +51,7 @@ char *
HASHFileChunk(const char *filename, char *buf, off_t off, off_t len) HASHFileChunk(const char *filename, char *buf, off_t off, off_t len)
{ {
struct stat sb; struct stat sb;
u_char buffer[BUFSIZ]; unsigned char buffer[BUFSIZ];
HASH_CTX ctx; HASH_CTX ctx;
int fd, save_errno; int fd, save_errno;
ssize_t nr; ssize_t nr;
@ -92,7 +92,7 @@ HASHFile(const char *filename, char *buf)
} }
char * char *
HASHData(const u_char *data, size_t len, char *buf) HASHData(const unsigned char *data, size_t len, char *buf)
{ {
HASH_CTX ctx; HASH_CTX ctx;

View File

@ -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) # define SPRINTF(x) ((size_t)sprintf x)
#endif #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 * static int
@ -83,13 +83,13 @@ inet_net_pton(int af, const char *src, void *dst, size_t size)
* Paul Vixie (ISC), June 1996 * Paul Vixie (ISC), June 1996
*/ */
static int 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 static const char
xdigits[] = "0123456789abcdef", xdigits[] = "0123456789abcdef",
digits[] = "0123456789"; digits[] = "0123456789";
int n, ch, tmp, dirty, bits; int n, ch, tmp, dirty, bits;
const u_char *odst = dst; const unsigned char *odst = dst;
ch = *src++; ch = *src++;
if (ch == '0' && (src[0] == 'x' || src[0] == 'X') 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)); isascii(ch) && isdigit(ch));
if (size-- <= 0) if (size-- <= 0)
goto emsgsize; goto emsgsize;
*dst++ = (u_char) tmp; *dst++ = (unsigned char) tmp;
if (ch == '\0' || ch == '/') if (ch == '\0' || ch == '/')
break; break;
if (ch != '.') if (ch != '.')

View File

@ -56,13 +56,13 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h> #include <stdlib.h>
#include <string.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 *)); 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 *)); int (*)(const void *, const void *));
#define ISIZE sizeof(int) #define ISIZE sizeof(int)
#define PSIZE sizeof(u_char *) #define PSIZE sizeof(unsigned char *)
#define ICOPY_LIST(src, dst, last) \ #define ICOPY_LIST(src, dst, last) \
do \ do \
*(int*)dst = *(int*)src, src += ISIZE, dst += ISIZE; \ *(int*)dst = *(int*)src, src += ISIZE, dst += ISIZE; \
@ -87,9 +87,10 @@ static void insertionsort(u_char *, size_t, size_t,
* boundaries. * boundaries.
*/ */
/* Assumption: PSIZE is a power of 2. */ /* Assumption: PSIZE is a power of 2. */
#define EVAL(p) (u_char **) \ #define EVAL(p) (unsigned char **) \
((u_char *)0 + \ ((unsigned char *)0 + \
(((u_char *)p + PSIZE - 1 - (u_char *) 0) & ~(PSIZE - 1))) (((unsigned char *)p + PSIZE - 1 - \
(unsigned char *)0) & ~(PSIZE - 1)))
/* /*
* Arguments are as for qsort. * Arguments are as for qsort.
@ -101,8 +102,8 @@ mergesort(void *base, size_t nmemb, size_t size,
size_t i; size_t i;
int sense; int sense;
int big, iflag; int big, iflag;
u_char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2; unsigned char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2;
u_char *list2, *list1, *p2, *p, *last, **p1; unsigned char *list2, *list1, *p2, *p, *last, **p1;
if (size < PSIZE / 2) { /* Pointers must fit into 2 * size. */ if (size < PSIZE / 2) { /* Pointers must fit into 2 * size. */
errno = EINVAL; errno = EINVAL;
@ -256,16 +257,16 @@ COPY: b = t;
* is defined. Otherwise simple pairwise merging is used.) * is defined. Otherwise simple pairwise merging is used.)
*/ */
static void 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 (*cmp)(const void *, const void *))
{ {
int i, length, size2, tmp, sense; 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; size2 = size*2;
if (n <= 5) { if (n <= 5) {
insertionsort(list1, n, size, cmp); insertionsort(list1, n, size, cmp);
*EVAL(list2) = (u_char*) list2 + n*size; *EVAL(list2) = (unsigned char*) list2 + n*size;
return; return;
} }
/* /*
@ -328,10 +329,10 @@ setup(u_char *list1, u_char *list2, size_t n, size_t size,
* last 4 elements. * last 4 elements.
*/ */
static void 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 *)) int (*cmp)(const void *, const void *))
{ {
u_char *ai, *s, *t, *u, tmp; unsigned char *ai, *s, *t, *u, tmp;
int i; int i;
for (ai = a+size; --n >= 1; ai += size) for (ai = a+size; --n >= 1; ai += size)

View File

@ -117,7 +117,7 @@ __aout_fdnlist(int fd, struct nlist *list)
struct nlist *p, *symtab; struct nlist *p, *symtab;
caddr_t strtab, a_out_mmap; caddr_t strtab, a_out_mmap;
off_t stroff, symoff; off_t stroff, symoff;
u_long symsize; unsigned long symsize;
int nent; int nent;
struct exec * exec; struct exec * exec;
struct stat st; struct stat st;

View File

@ -59,14 +59,14 @@ __RCSID("$NetBSD: radixsort.c,v 1.18 2009/08/21 20:49:50 dsl Exp $");
#include <errno.h> #include <errno.h>
typedef struct { typedef struct {
const u_char **sa; const unsigned char **sa;
int sn, si; int sn, si;
} stack; } stack;
static inline void simplesort(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 u_char **, int, int, const u_char *, u_int); static void r_sort_a(const unsigned char **, int, int, const unsigned char *, unsigned int);
static void r_sort_b(const u_char **, static void r_sort_b(const unsigned char **,
const u_char **, int, int, const u_char *, u_int); const unsigned char **, int, int, const unsigned char *, unsigned int);
#define THRESHOLD 20 /* Divert to simplesort(). */ #define THRESHOLD 20 /* Divert to simplesort(). */
#define SIZE 512 /* Default stack size. */ #define SIZE 512 /* Default stack size. */
@ -91,11 +91,12 @@ static void r_sort_b(const u_char **,
} }
int 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; const unsigned char *tr;
u_int c; unsigned int c;
u_char tr0[256]; unsigned char tr0[256];
SETUP; SETUP;
r_sort_a(a, n, 0, tr, endch); 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 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; const unsigned char *tr, **ta;
u_int c; unsigned int c;
u_char tr0[256]; unsigned char tr0[256];
if (a == NULL) { if (a == NULL) {
errno = EFAULT; errno = EFAULT;
@ -134,14 +136,15 @@ sradixsort(const u_char **a, int n, const u_char *tab, u_int endch)
/* Unstable, in-place sort. */ /* Unstable, in-place sort. */
static void 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; static unsigned int count[256], nc, bmin;
u_int c; unsigned int c;
const u_char **ak, *r; const unsigned char **ak, *r;
stack s[SIZE], *sp, *sp0, *sp1, temp; stack s[SIZE], *sp, *sp0, *sp1, temp;
u_int *cp, bigc; unsigned int *cp, bigc;
const u_char **an, *t, **aj, **top[256]; const unsigned char **an, *t, **aj, **top[256];
/* Set up stack. */ /* Set up stack. */
sp = s; 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 at position i, move on to the next
* character. * character.
*/ */
if (nc == 1 && count[bmin] == (u_int)n) { if (nc == 1 && count[bmin] == (unsigned int)n) {
push(a, n, i+1); push(a, n, i+1);
nc = count[bmin] = 0; nc = count[bmin] = 0;
continue; 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. */ /* Stable sort, requiring additional memory. */
static void static void
r_sort_b(const u_char **a, const u_char **ta, int n, int i, const u_char *tr, r_sort_b(const unsigned char **a, const unsigned char **ta, int n, int i,
u_int endch) const unsigned char *tr, unsigned int endch)
{ {
static u_int count[256], nc, bmin; static unsigned int count[256], nc, bmin;
u_int c; unsigned int c;
const u_char **ak, **ai; const unsigned char **ak, **ai;
stack s[512], *sp, *sp0, *sp1, temp; stack s[512], *sp, *sp0, *sp1, temp;
const u_char **top[256]; const unsigned char **top[256];
u_int *cp, bigc; unsigned int *cp, bigc;
sp = s; sp = s;
push(a, n, i); 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 */ /* insertion sort */
static inline void 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; unsigned char ch;
const u_char **ak, **ai, *s, *t; const unsigned char **ak, **ai, *s, *t;
for (ak = a+1; --n >= 1; ak++) for (ak = a+1; --n >= 1; ak++)
for (ai = ak; ai > a; ai--) { for (ai = ak; ai > a; ai--) {

View File

@ -45,8 +45,11 @@
#define S_HTTP 0x080 /* %HEXHEX escape */ #define S_HTTP 0x080 /* %HEXHEX escape */
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') #define isoctal(c) \
#define ishex(c) ((((u_char)(c)) >= '0' && ((u_char)(c)) <= '9') || (((u_char)(c)) >= 'a' && ((u_char)(c)) <= 'f')) (((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 * unvis - decode characters previously encoded by vis

View File

@ -35,17 +35,20 @@
#include <stdio.h> #include <stdio.h>
#include <vis.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) \ #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) != '#') || \ (((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_SP) == 0 && (c) == ' ') || \
((flag & VIS_TAB) == 0 && (c) == '\t') || \ ((flag & VIS_TAB) == 0 && (c) == '\t') || \
((flag & VIS_NL) == 0 && (c) == '\n') || \ ((flag & VIS_NL) == 0 && (c) == '\n') || \
((flag & VIS_SAFE) && ((c) == '\b' || \ ((flag & VIS_SAFE) && ((c) == '\b' || \
(c) == '\007' || (c) == '\r' || \ (c) == '\007' || (c) == '\r' || \
isgraph((u_char)(c))))) isgraph((unsigned char)(c)))))
/* /*
* vis - visually encode characters * 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)) { if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) {
*dst++ = '\\'; *dst++ = '\\';
*dst++ = ((u_char)c >> 6 & 07) + '0'; *dst++ = ((unsigned char)c >> 6 & 07) + '0';
*dst++ = ((u_char)c >> 3 & 07) + '0'; *dst++ = ((unsigned char)c >> 3 & 07) + '0';
*dst++ = ((u_char)c & 07) + '0'; *dst++ = ((unsigned char)c & 07) + '0';
goto done; goto done;
} }
if ((flag & VIS_NOSLASH) == 0) if ((flag & VIS_NOSLASH) == 0)