Made some changes to make Clang Happy

Someone should double check that that I didn't change
the behavior of any of the code.  I'm not using most (if any)
of the code I touched, just wanted it to compile...
This commit is contained in:
Dave Butler 2017-08-25 08:02:35 -09:00
parent 9d9f75eb68
commit f57bc38ff6

71
stb.h
View File

@ -1795,7 +1795,7 @@ STB_EXTERN int stb_prefix (char *s, char *t);
STB_EXTERN char * stb_strichr(char *s, char t);
STB_EXTERN char * stb_stristr(char *s, char *t);
STB_EXTERN int stb_prefix_count(char *s, char *t);
STB_EXTERN char * stb_plural(int n); // "s" or ""
STB_EXTERN const char * stb_plural(int n); // "s" or ""
STB_EXTERN size_t stb_strscpy(char *d, const char *s, size_t n);
STB_EXTERN char **stb_tokens(char *src, char *delimit, int *count);
@ -1822,7 +1822,7 @@ size_t stb_strscpy(char *d, const char *s, size_t n)
return len + 1;
}
char *stb_plural(int n)
const char *stb_plural(int n)
{
return n == 1 ? "" : "s";
}
@ -3362,7 +3362,7 @@ unsigned int stb_hashlen(char *str, int len)
unsigned int stb_hashptr(void *p)
{
unsigned int x = (unsigned int) p;
unsigned int x = (unsigned int)(size_t) p;
// typically lacking in low bits and high bits
x = stb_rehash(x);
@ -3411,7 +3411,7 @@ unsigned int stb_hash_fast(void *p, int len)
if (len <= 0 || q == NULL) return 0;
/* Main loop */
if (((int) q & 1) == 0) {
if (((int)(size_t) q & 1) == 0) {
for (;len > 3; len -= 4) {
unsigned int val;
hash += stb__get16(q);
@ -3737,7 +3737,7 @@ int stb_ischar(char c, char *set)
static unsigned char (*tables)[256];
static char ** sets = NULL;
int z = stb_perfect_hash(&p, (int) set);
int z = stb_perfect_hash(&p, (int)(size_t) set);
if (z < 0) {
int i,k,n,j,f;
// special code that means free all existing data
@ -3756,7 +3756,7 @@ int stb_ischar(char c, char *set)
tables = (unsigned char (*)[256]) realloc(tables, sizeof(*tables) * k);
memset(tables, 0, sizeof(*tables) * k);
for (i=0; i < stb_arr_len(sets); ++i) {
k = stb_perfect_hash(&p, (int) sets[i]);
k = stb_perfect_hash(&p, (int)(size_t) sets[i]);
assert(k >= 0);
n = k >> 3;
f = bit[k&7];
@ -3764,7 +3764,7 @@ int stb_ischar(char c, char *set)
tables[n][(unsigned char) sets[i][j]] |= f;
}
}
z = stb_perfect_hash(&p, (int) set);
z = stb_perfect_hash(&p, (int)(size_t) set);
}
return tables[z >> 3][(unsigned char) c] & bit[z & 7];
}
@ -7631,14 +7631,14 @@ static stb_ps_hash *stb_ps_makehash(int size, int old_size, void **old_data)
h->any_offset = 0;
memset(h->table, 0, size * sizeof(h->table[0]));
for (i=0; i < old_size; ++i)
if (!stb_ps_empty(old_data[i]))
if (!stb_ps_empty((size_t)old_data[i]))
stb_ps_add(EncodeHash(h), old_data[i]);
return h;
}
void stb_ps_delete(stb_ps *ps)
{
switch (3 & (int) ps) {
switch (3 & (int)(size_t) ps) {
case STB_ps_direct: break;
case STB_ps_bucket: stb_bucket_free(GetBucket(ps)); break;
case STB_ps_array : free(GetArray(ps)); break;
@ -7650,7 +7650,7 @@ stb_ps *stb_ps_copy(stb_ps *ps)
{
int i;
// not a switch: order based on expected performance/power-law distribution
switch (3 & (int) ps) {
switch (3 & (int)(size_t) ps) {
case STB_ps_direct: return ps;
case STB_ps_bucket: {
stb_ps_bucket *n = (stb_ps_bucket *) malloc(sizeof(*n));
@ -7677,8 +7677,8 @@ stb_ps *stb_ps_copy(stb_ps *ps)
int stb_ps_find(stb_ps *ps, void *value)
{
int i, code = 3 & (int) ps;
assert((3 & (int) value) == STB_ps_direct);
int i, code = 3 & (int)(size_t) ps;
assert((3 & (int)(size_t) value) == STB_ps_direct);
assert(stb_ps_fastlist_valid(value));
// not a switch: order based on expected performance/power-law distribution
if (code == STB_ps_direct)
@ -7719,11 +7719,11 @@ stb_ps * stb_ps_add (stb_ps *ps, void *value)
assert(!stb_ps_find(ps,value));
#endif
if (value == NULL) return ps; // ignore NULL adds to avoid bad breakage
assert((3 & (int) value) == STB_ps_direct);
assert((3 & (int)(size_t) value) == STB_ps_direct);
assert(stb_ps_fastlist_valid(value));
assert(value != STB_DEL); // STB_DEL is less likely
switch (3 & (int) ps) {
switch (3 & (int)(size_t) ps) {
case STB_ps_direct:
if (ps == NULL) return (stb_ps *) value;
return EncodeBucket(stb_bucket_create2(ps,value));
@ -7772,11 +7772,11 @@ stb_ps * stb_ps_add (stb_ps *ps, void *value)
stb_uint32 n = hash & h->mask;
void **t = h->table;
// find first NULL or STB_DEL entry
if (!stb_ps_empty(t[n])) {
if (!stb_ps_empty((size_t)t[n])) {
stb_uint32 s = stb_rehash(hash) | 1;
do {
n = (n + s) & h->mask;
} while (!stb_ps_empty(t[n]));
} while (!stb_ps_empty((size_t)t[n]));
}
if (t[n] == STB_DEL)
-- h->count_deletes;
@ -7803,9 +7803,9 @@ stb_ps *stb_ps_remove(stb_ps *ps, void *value)
#ifdef STB_DEBUG
assert(stb_ps_find(ps, value));
#endif
assert((3 & (int) value) == STB_ps_direct);
assert((3 & (int)(size_t) value) == STB_ps_direct);
if (value == NULL) return ps; // ignore NULL removes to avoid bad breakage
switch (3 & (int) ps) {
switch (3 & (int)(size_t) ps) {
case STB_ps_direct:
return ps == value ? NULL : ps;
case STB_ps_bucket: {
@ -7864,7 +7864,7 @@ stb_ps *stb_ps_remove(stb_ps *ps, void *value)
stb_ps_array *a = (stb_ps_array *) malloc(sizeof(*a) + (n-1) * sizeof(a->p[0]));
int i,j=0;
for (i=0; i < h->size; ++i)
if (!stb_ps_empty(t[i]))
if (!stb_ps_empty((size_t)t[i]))
a->p[j++] = t[i];
assert(j == h->count);
a->count = j;
@ -7886,7 +7886,7 @@ stb_ps *stb_ps_remove(stb_ps *ps, void *value)
stb_ps *stb_ps_remove_any(stb_ps *ps, void **value)
{
assert(ps != NULL);
switch (3 & (int) ps) {
switch (3 & (int)(size_t) ps) {
case STB_ps_direct:
*value = ps;
return NULL;
@ -7919,7 +7919,7 @@ stb_ps *stb_ps_remove_any(stb_ps *ps, void **value)
stb_ps_hash *h = GetHash(ps);
void **t = h->table;
stb_uint32 n = h->any_offset;
while (stb_ps_empty(t[n]))
while (stb_ps_empty((size_t)t[n]))
n = (n + 1) & h->mask;
*value = t[n];
h->any_offset = (n+1) & h->mask;
@ -7940,7 +7940,7 @@ void ** stb_ps_getlist(stb_ps *ps, int *count)
{
int i,n=0;
void **p = NULL;
switch (3 & (int) ps) {
switch (3 & (int)(size_t) ps) {
case STB_ps_direct:
if (ps == NULL) { *count = 0; return NULL; }
p = (void **) malloc(sizeof(*p) * 1);
@ -7966,7 +7966,7 @@ void ** stb_ps_getlist(stb_ps *ps, int *count)
stb_ps_hash *h = GetHash(ps);
p = (void **) malloc(sizeof(*p) * h->count);
for (i=0; i < h->size; ++i)
if (!stb_ps_empty(h->table[i]))
if (!stb_ps_empty((size_t)h->table[i]))
p[n++] = h->table[i];
break;
}
@ -7978,7 +7978,7 @@ void ** stb_ps_getlist(stb_ps *ps, int *count)
int stb_ps_writelist(stb_ps *ps, void **list, int size )
{
int i,n=0;
switch (3 & (int) ps) {
switch (3 & (int)(size_t) ps) {
case STB_ps_direct:
if (ps == NULL || size <= 0) return 0;
list[0] = ps;
@ -8000,7 +8000,7 @@ int stb_ps_writelist(stb_ps *ps, void **list, int size )
stb_ps_hash *h = GetHash(ps);
if (size <= 0) return 0;
for (i=0; i < h->count; ++i) {
if (!stb_ps_empty(h->table[i])) {
if (!stb_ps_empty((size_t)h->table[i])) {
list[n++] = h->table[i];
if (n == size) break;
}
@ -8014,7 +8014,7 @@ int stb_ps_writelist(stb_ps *ps, void **list, int size )
int stb_ps_enum(stb_ps *ps, void *data, int (*func)(void *value, void *data))
{
int i;
switch (3 & (int) ps) {
switch (3 & (int)(size_t) ps) {
case STB_ps_direct:
if (ps == NULL) return STB_TRUE;
return func(ps, data);
@ -8036,7 +8036,7 @@ int stb_ps_enum(stb_ps *ps, void *data, int (*func)(void *value, void *data))
case STB_ps_hash: {
stb_ps_hash *h = GetHash(ps);
for (i=0; i < h->count; ++i)
if (!stb_ps_empty(h->table[i]))
if (!stb_ps_empty((size_t)h->table[i]))
if (!func(h->table[i], data))
return STB_FALSE;
return STB_TRUE;
@ -8047,7 +8047,7 @@ int stb_ps_enum(stb_ps *ps, void *data, int (*func)(void *value, void *data))
int stb_ps_count (stb_ps *ps)
{
switch (3 & (int) ps) {
switch (3 & (int)(size_t) ps) {
case STB_ps_direct:
return ps != NULL;
case STB_ps_bucket: {
@ -8071,7 +8071,7 @@ void ** stb_ps_fastlist(stb_ps *ps, int *count)
{
static void *storage;
switch (3 & (int) ps) {
switch (3 & (int)(size_t) ps) {
case STB_ps_direct:
if (ps == NULL) { *count = 0; return NULL; }
storage = ps;
@ -9118,7 +9118,7 @@ static void stb__add_epsilon(stb_matcher *matcher, int from, int to)
static void stb__add_edge(stb_matcher *matcher, int from, int to, int type)
{
stb_nfa_edge z = { type, to };
stb_nfa_edge z = { (stb_int16)type, (stb_uint16)to };
if (matcher->nodes[from].out == NULL)
stb_arr_malloc((void **) &matcher->nodes[from].out, matcher);
stb_arr_push(matcher->nodes[from].out, z);
@ -9831,7 +9831,7 @@ int stb_regex(char *regex, char *str)
static char ** regexps;
static char ** regexp_cache;
static unsigned short *mapping;
int z = stb_perfect_hash(&p, (int) regex);
int z = stb_perfect_hash(&p, (int)(size_t) regex);
if (z >= 0) {
if (strcmp(regex, regexp_cache[(int) mapping[z]])) {
int i = mapping[z];
@ -9862,8 +9862,8 @@ int stb_regex(char *regex, char *str)
n = stb_perfect_create(&p, (unsigned int *) (char **) regexps, stb_arr_len(regexps));
mapping = (unsigned short *) realloc(mapping, n * sizeof(*mapping));
for (i=0; i < stb_arr_len(regexps); ++i)
mapping[stb_perfect_hash(&p, (int) regexps[i])] = i;
z = stb_perfect_hash(&p, (int) regex);
mapping[stb_perfect_hash(&p, (int)(size_t) regexps[i])] = i;
z = stb_perfect_hash(&p, (int)(size_t) regex);
}
return stb_matcher_find(matchers[(int) mapping[z]], str);
}
@ -10357,7 +10357,7 @@ static void stb__write(unsigned char v)
++stb__outbytes;
}
#define stb_out(v) (stb__out ? *stb__out++ = (stb_uchar) (v) : stb__write((stb_uchar) (v)))
#define stb_out(v) (stb__out ? (void)(*stb__out++ = (stb_uchar) (v)) : stb__write((stb_uchar) (v)))
static void stb_out2(stb_uint v)
{
@ -10620,7 +10620,8 @@ static size_t stb_out_backpatch_id(void)
static void stb_out_backpatch(size_t id, stb_uint value)
{
stb_uchar data[4] = { value >> 24, value >> 16, value >> 8, value };
stb_uchar data[4] = { (stb_uchar)(value >> 24), (stb_uchar)(value >> 16), (stb_uchar)(value >> 8), (stb_uchar)(value) };
if (stb__out) {
memcpy((void *) id, data, 4);
} else {