Make valid C99 and cleanup warnings using stricter flags
Flags used for these changes: -Wall -Wextra -Werror -Wno-unused-parameter -std=c99 -pedantic Note: the strcasecmp()/strncasecmp() implementations are kind of a hack and should at least be factored out into a compat file or some such.
This commit is contained in:
parent
da501075ce
commit
0d7d3bf9c8
@ -3,12 +3,37 @@
|
||||
* Change log:
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cfuhash.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(HAVE_STRNCASECMP) && defined(HAVE_STRINGS_H)
|
||||
# include <strings.h>
|
||||
#else /* If strncasecmp() isn't available use this one */
|
||||
static inline int
|
||||
strncasecmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
assert(s1 && s2);
|
||||
if (n != 0) {
|
||||
const unsigned char *us1 = (const unsigned char *) s1,
|
||||
const unsigned char *us2 = (const unsigned char *) s2;
|
||||
do {
|
||||
if (tolower(*us1) != tolower(*us2++))
|
||||
return (tolower(*us1) - tolower(*--us2));
|
||||
if (*us1++ == '\0')
|
||||
break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
remove_func(void *key, size_t key_size, void *data, size_t data_size, void *arg) {
|
||||
data_size = data_size;
|
||||
|
@ -27,7 +27,7 @@ dup_str(const char *str) {
|
||||
static u_int32_t
|
||||
hash_func1(const void *key, size_t length) {
|
||||
size_t i = length;
|
||||
u_int hash = 0;
|
||||
unsigned int hash = 0;
|
||||
char *s = (char *)key;
|
||||
while (i--) hash = hash * 33 + *s++;
|
||||
|
||||
@ -50,7 +50,7 @@ hash_func1(const void *key, size_t length) {
|
||||
|
||||
typedef u_int32_t ub4;
|
||||
|
||||
static u_int
|
||||
static unsigned int
|
||||
hash_func_tc(const void *key, size_t length)
|
||||
{
|
||||
register ub4 a,b,c,len;
|
||||
@ -98,7 +98,6 @@ hash_func_tc(const void *key, size_t length)
|
||||
static int
|
||||
time_it(cfuhash_function_t hf, double *elapsed_time, u_int32_t num_tests) {
|
||||
cfuhash_table_t *hash = cfuhash_new_with_initial_size(30);
|
||||
u_int32_t flags = 0;
|
||||
char key[32];
|
||||
char value[32];
|
||||
size_t i;
|
||||
@ -108,7 +107,7 @@ time_it(cfuhash_function_t hf, double *elapsed_time, u_int32_t num_tests) {
|
||||
cfutime_t *time = cfutime_new();
|
||||
|
||||
/* freeze the hash so that it won't shrink while we put in all the data */
|
||||
flags = cfuhash_set_flag(hash, CFUHASH_FROZEN_UNTIL_GROWS);
|
||||
cfuhash_set_flag(hash, CFUHASH_FROZEN_UNTIL_GROWS);
|
||||
cfuhash_set_hash_function(hash, hf);
|
||||
|
||||
cfutime_begin(time);
|
||||
|
@ -35,6 +35,10 @@
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cfu.h"
|
||||
#include "cfuconf.h"
|
||||
|
||||
@ -44,6 +48,21 @@
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
|
||||
#if defined(HAVE_STRCASECMP) && defined(HAVE_STRINGS_H)
|
||||
# include <strings.h>
|
||||
#else /* If strcasecmp() isn't available use this one */
|
||||
static inline int
|
||||
strcasecmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
int c1, c2;
|
||||
while (c1 = toupper(*s1++), c2 = toupper(*s2++), c1 == c2 && (c1 & c2))
|
||||
;
|
||||
if (c1 & c2)
|
||||
return c1 < c2 ? -1 : 1;
|
||||
return c1 ? 1 : (c2 ? -1 : 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct cfuconf {
|
||||
libcfu_type type;
|
||||
cfuhash_table_t *containers;
|
||||
@ -650,6 +669,7 @@ print_indent(size_t depth, FILE *fp) {
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 /* Not currently used */
|
||||
static void
|
||||
print_container(cfuhash_table_t *conf_hash, size_t depth) {
|
||||
char **keys = NULL;
|
||||
@ -702,6 +722,7 @@ print_container(cfuhash_table_t *conf_hash, size_t depth) {
|
||||
}
|
||||
free(keys);
|
||||
}
|
||||
#endif /* End currently unused function print_container() */
|
||||
|
||||
typedef struct directive_foreach_ds {
|
||||
size_t depth;
|
||||
|
@ -52,6 +52,27 @@
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STRNCASECMP) && defined(HAVE_STRINGS_H)
|
||||
# include <strings.h>
|
||||
#else /* If strncasecmp() isn't available use this one */
|
||||
static inline int
|
||||
strncasecmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
assert(s1 && s2);
|
||||
if (n != 0) {
|
||||
const unsigned char *us1 = (const unsigned char *) s1,
|
||||
const unsigned char *us2 = (const unsigned char *) s2;
|
||||
do {
|
||||
if (tolower(*us1) != tolower(*us2++))
|
||||
return (tolower(*us1) - tolower(*--us2));
|
||||
if (*us1++ == '\0')
|
||||
break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct cfuhash_event_flags {
|
||||
int resized:1;
|
||||
@ -89,8 +110,8 @@ struct cfuhash_table {
|
||||
static u_int32_t
|
||||
hash_func(const void *key, size_t length) {
|
||||
register size_t i = length;
|
||||
register u_int hv = 0; /* could put a seed here instead of zero */
|
||||
register const unsigned char *s = (char *)key;
|
||||
register unsigned int hv = 0; /* could put a seed here instead of zero */
|
||||
register const unsigned char *s = (unsigned char *)key;
|
||||
while (i--) {
|
||||
hv += *s++;
|
||||
hv += (hv << 10);
|
||||
@ -104,9 +125,9 @@ hash_func(const void *key, size_t length) {
|
||||
}
|
||||
|
||||
/* makes sure the real size of the buckets array is a power of 2 */
|
||||
static u_int
|
||||
hash_size(u_int s) {
|
||||
u_int i = 1;
|
||||
static unsigned int
|
||||
hash_size(unsigned int s) {
|
||||
unsigned int i = 1;
|
||||
while (i < s) i <<= 1;
|
||||
return i;
|
||||
}
|
||||
@ -127,9 +148,9 @@ hash_key_dup_lower_case(const void *key, size_t key_size) {
|
||||
}
|
||||
|
||||
/* returns the index into the buckets array */
|
||||
static inline u_int
|
||||
static inline unsigned int
|
||||
hash_value(cfuhash_table_t *ht, const void *key, size_t key_size, size_t num_buckets) {
|
||||
u_int hv = 0;
|
||||
unsigned int hv = 0;
|
||||
|
||||
if (key) {
|
||||
if (ht->flags & CFUHASH_IGNORE_CASE) {
|
||||
@ -320,7 +341,7 @@ cfuhash_unlock(cfuhash_table_t *ht) {
|
||||
/* uses the convention that zero means a match, like memcmp */
|
||||
|
||||
static inline int
|
||||
hash_cmp(const void *key, size_t key_size, cfuhash_entry *he, u_int case_insensitive) {
|
||||
hash_cmp(const void *key, size_t key_size, cfuhash_entry *he, unsigned int case_insensitive) {
|
||||
if (key_size != he->key_size) return 1;
|
||||
if (key == he->key) return 0;
|
||||
if (case_insensitive) {
|
||||
@ -330,7 +351,7 @@ hash_cmp(const void *key, size_t key_size, cfuhash_entry *he, u_int case_insensi
|
||||
}
|
||||
|
||||
static inline cfuhash_entry *
|
||||
hash_add_entry(cfuhash_table_t *ht, u_int hv, const void *key, size_t key_size,
|
||||
hash_add_entry(cfuhash_table_t *ht, unsigned int hv, const void *key, size_t key_size,
|
||||
void *data, size_t data_size) {
|
||||
cfuhash_entry *he = (cfuhash_entry *)calloc(1, sizeof(cfuhash_entry));
|
||||
|
||||
@ -357,7 +378,7 @@ hash_add_entry(cfuhash_table_t *ht, u_int hv, const void *key, size_t key_size,
|
||||
extern int
|
||||
cfuhash_get_data(cfuhash_table_t *ht, const void *key, size_t key_size, void **r,
|
||||
size_t *data_size) {
|
||||
u_int hv = 0;
|
||||
unsigned int hv = 0;
|
||||
cfuhash_entry *hr = NULL;
|
||||
|
||||
if (!ht) return 0;
|
||||
@ -424,7 +445,7 @@ cfuhash_exists(cfuhash_table_t *ht, const char *key) {
|
||||
extern int
|
||||
cfuhash_put_data(cfuhash_table_t *ht, const void *key, size_t key_size, void *data,
|
||||
size_t data_size, void **r) {
|
||||
u_int hv = 0;
|
||||
unsigned int hv = 0;
|
||||
cfuhash_entry *he = NULL;
|
||||
int added_an_entry = 0;
|
||||
|
||||
@ -513,7 +534,7 @@ cfuhash_clear(cfuhash_table_t *ht) {
|
||||
|
||||
extern void *
|
||||
cfuhash_delete_data(cfuhash_table_t *ht, const void *key, size_t key_size) {
|
||||
u_int hv = 0;
|
||||
unsigned int hv = 0;
|
||||
cfuhash_entry *he = NULL;
|
||||
cfuhash_entry *hep = NULL;
|
||||
void *r = NULL;
|
||||
@ -826,7 +847,7 @@ cfuhash_rehash(cfuhash_table_t *ht) {
|
||||
cfuhash_entry *he = ht->buckets[i];
|
||||
while (he) {
|
||||
cfuhash_entry *nhe = he->next;
|
||||
u_int hv = hash_value(ht, he->key, he->key_size, new_size);
|
||||
unsigned int hv = hash_value(ht, he->key, he->key_size, new_size);
|
||||
he->next = new_buckets[hv];
|
||||
new_buckets[hv] = he;
|
||||
he = nhe;
|
||||
|
@ -256,7 +256,6 @@ __cfustring_split_to_raw(cfustring_t *cfu_str, size_t *num_strings, size_t num_s
|
||||
char **ret_strings = (char **)calloc(2, sizeof(char *));
|
||||
unsigned int max_ret_strings = 2;
|
||||
unsigned int used_ret_strings = 0;
|
||||
char *start = NULL;
|
||||
char *end = NULL;
|
||||
char *next_str = NULL;
|
||||
int last = 0;
|
||||
@ -274,7 +273,7 @@ __cfustring_split_to_raw(cfustring_t *cfu_str, size_t *num_strings, size_t num_s
|
||||
sep_array[i] = _dup_str(sep);
|
||||
}
|
||||
|
||||
start = end = cfustring_get_buffer(cfu_str);
|
||||
end = cfustring_get_buffer(cfu_str);
|
||||
if (!end) {
|
||||
*num_strings = 0;
|
||||
free(ret_strings);
|
||||
|
@ -88,7 +88,7 @@ _run_queue(void *arg) {
|
||||
tq->init_fn(tq->init_arg);
|
||||
}
|
||||
|
||||
pthread_cleanup_push((void *)tq->cleanup_fn, tq->cleanup_arg);
|
||||
pthread_cleanup_push(tq->cleanup_fn, tq->cleanup_arg);
|
||||
|
||||
while (1) {
|
||||
pthread_mutex_lock(&tq->mutex);
|
||||
|
@ -43,12 +43,11 @@
|
||||
#include <assert.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
typedef struct cfutime {
|
||||
libcfu_type type;
|
||||
struct timeval begin_tv;
|
||||
struct timezone begin_tz;
|
||||
struct timeval end_tv;
|
||||
struct timezone end_tz;
|
||||
} cfutime;
|
||||
|
||||
extern cfutime_t *
|
||||
@ -60,12 +59,12 @@ cfutime_new() {
|
||||
|
||||
extern void
|
||||
cfutime_begin(cfutime_t *time) {
|
||||
gettimeofday(&(time->begin_tv), &(time->begin_tz));
|
||||
gettimeofday(&(time->begin_tv), NULL);
|
||||
}
|
||||
|
||||
extern void
|
||||
cfutime_end(cfutime_t *time) {
|
||||
gettimeofday(&(time->end_tv), &(time->end_tz));
|
||||
gettimeofday(&(time->end_tv), NULL);
|
||||
}
|
||||
|
||||
extern double
|
||||
|
Reference in New Issue
Block a user