Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed compiler warnings and increased warning level

  • Loading branch information...
commit df1b7e42959a9c055a7320a14fa5f80b4f22f6a8 1 parent 1f48dc4
Trond Norbye authored dustin committed
View
1  .gitignore
@@ -21,4 +21,5 @@ missing
stamp-h1
tags
cscope.out
+memcached_dtrace.h
*~
View
14 configure.ac
@@ -6,6 +6,7 @@ AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
AM_CONFIG_HEADER(config.h)
AC_PROG_CC
+AC_PROG_CC_C99
AM_PROG_CC_C_O
AC_PROG_INSTALL
@@ -216,6 +217,7 @@ if test "x$ac_cv_search_pthread_create" != "xno"; then
])
],[
CFLAGS="-mt $CFLAGS"
+ SUNSTUDIO=true
])
else
AC_MSG_ERROR([Can't enable threads without the POSIX thread library.])
@@ -225,5 +227,17 @@ AC_CHECK_FUNCS(mlockall)
AC_CHECK_FUNCS(getpagesizes)
AC_CHECK_FUNCS(memcntl)
+dnl Let the compiler be a bit more picky. Please note that you cannot
+dnl specify these flags to the compiler before AC_CHECK_FUNCS, because
+dnl the test program will generate a compilation warning and hence fail
+dnl to detect the function ;-)
+if test "$GCC" = "yes"
+then
+ CFLAGS="$CFLAGS -Werror -pedantic -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls"
+elif test "$SUNSTUDIO" = "true"
+then
+ CFLAGS="$CFLAGS -errfmt=error -errwarn -errshort=tags"
+fi
+
AC_CONFIG_FILES(Makefile doc/Makefile)
AC_OUTPUT
View
2  daemon.c
@@ -38,6 +38,8 @@
#include <stdlib.h>
#include <unistd.h>
+#include "memcached.h"
+
int daemon(int nochdir, int noclose)
{
int fd;
View
4 items.c
@@ -17,7 +17,7 @@
/* Forward Declarations */
static void item_link_q(item *it);
static void item_unlink_q(item *it);
-static uint64_t get_cas_id();
+static uint64_t get_cas_id(void);
/*
* We only reposition items in the LRU queue if they haven't been repositioned
@@ -49,7 +49,7 @@ void item_init(void) {
}
/* Get the next CAS id for a new item. */
-uint64_t get_cas_id() {
+uint64_t get_cas_id(void) {
static uint64_t cas_id = 0;
return ++cas_id;
}
View
31 memcached.c
@@ -53,10 +53,6 @@ std *
#endif
#endif
-#ifndef HAVE_DAEMON
-extern int daemon(int nochdir, int noclose);
-#endif
-
/*
* forward declarations
*/
@@ -759,7 +755,7 @@ static int build_udp_headers(conn *c) {
hdr = c->hdrbuf;
for (i = 0; i < c->msgused; i++) {
- c->msglist[i].msg_iov[0].iov_base = hdr;
+ c->msglist[i].msg_iov[0].iov_base = (void*)hdr;
c->msglist[i].msg_iov[0].iov_len = UDP_HEADER_SIZE;
*hdr++ = c->request_id / 256;
*hdr++ = c->request_id % 256;
@@ -769,7 +765,7 @@ static int build_udp_headers(conn *c) {
*hdr++ = c->msgused % 256;
*hdr++ = 0;
*hdr++ = 0;
- assert((void *) hdr == (void *)c->msglist[i].msg_iov[0].iov_base + UDP_HEADER_SIZE);
+ assert((void *) hdr == (caddr_t)c->msglist[i].msg_iov[0].iov_base + UDP_HEADER_SIZE);
}
return 0;
@@ -1045,7 +1041,6 @@ static void complete_incr_bin(conn *c) {
if (it && (c->binary_header.request.cas == 0 || c->binary_header.request.cas == it->cas_id)) {
/* Weird magic in add_delta forces me to pad here */
char tmpbuf[INCR_MAX_STORAGE_LEN];
- uint64_t l = 0;
add_delta(c, it, c->cmd == PROTOCOL_BINARY_CMD_INCREMENT,
req->message.body.delta, tmpbuf);
rsp->message.body.value = swap64(strtoull(tmpbuf, NULL, 10));
@@ -1155,7 +1150,6 @@ static void process_bin_get(conn *c) {
item *it;
protocol_binary_response_get* rsp = (protocol_binary_response_get*)c->wbuf;
- protocol_binary_request_get* req = binary_get_request(c);
char* key = binary_get_key(c);
size_t nkey = c->binary_header.request.keylen;
@@ -1349,7 +1343,6 @@ static void bin_read_key(conn *c, enum bin_substates next_substate, int extra) {
}
static void dispatch_bin_command(conn *c) {
- time_t exptime = 0;
int protocol_error = 0;
int extlen = c->binary_header.request.extlen;
@@ -1535,7 +1528,6 @@ static void process_bin_append_prepend(conn *c) {
int nkey;
int vlen;
item *it;
- protocol_binary_request_append* req = binary_get_request(c);
assert(c != NULL);
@@ -1607,14 +1599,12 @@ static void process_bin_flush(conn *c) {
static void process_bin_delete(conn *c) {
item *it;
- protocol_binary_response_delete* rsp = (protocol_binary_response_delete*)c->wbuf;
protocol_binary_request_delete* req = binary_get_request(c);
char* key = binary_get_key(c);
size_t nkey = c->binary_header.request.keylen;
assert(c != NULL);
- assert(c->wsize >= sizeof(*rsp));
if (settings.verbose) {
fprintf(stderr, "Deleting %s\n", key);
@@ -1937,7 +1927,7 @@ static char *server_stats(bool binprot, int *buflen) {
#endif /* !WIN32 */
STATS_LOCK();
- pos += sprintf(pos, "STAT pid %u\r\n", pid);
+ pos += sprintf(pos, "STAT pid %lu\r\n", (long)pid);
pos += sprintf(pos, "STAT uptime %u\r\n", now);
pos += sprintf(pos, "STAT time %ld\r\n", now + stats.started);
pos += sprintf(pos, "STAT version " VERSION "\r\n");
@@ -2025,7 +2015,6 @@ uint32_t append_ascii_stats(char *buf, const char *key, const uint16_t klen,
}
static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
- rel_time_t now = current_time;
char *command;
char *subcommand;
@@ -2358,9 +2347,9 @@ static void process_update_command(conn *c, token_t *tokens, const size_t ntoken
size_t nkey;
int flags;
time_t exptime;
- int vlen, old_vlen;
+ int vlen;
uint64_t req_cas_id=0;
- item *it, *old_it;
+ item *it;
assert(c != NULL);
@@ -2988,7 +2977,7 @@ static int transmit(conn *c) {
/* Might have written just part of the last iovec entry;
adjust it so the next write will do the rest. */
if (res > 0) {
- m->msg_iov->iov_base += res;
+ m->msg_iov->iov_base = (caddr_t)m->msg_iov->iov_base + res;
m->msg_iov->iov_len -= res;
}
return TRANSMIT_INCOMPLETE;
@@ -3275,6 +3264,10 @@ static void drive_machine(conn *c) {
conn_close(c);
stop = true;
break;
+
+ case conn_max_state:
+ assert(false);
+ break;
}
}
@@ -3740,7 +3733,7 @@ static void sig_handler(const int sig) {
* On systems that supports multiple page sizes we may reduce the
* number of TLB-misses by using the biggest available page size
*/
-int enable_large_pages(void) {
+static int enable_large_pages(void) {
int ret = -1;
size_t sizes[32];
int avail = getpagesizes(sizes, 32);
@@ -3789,11 +3782,9 @@ int main (int argc, char **argv) {
struct rlimit rlim;
/* listening sockets */
static int *l_socket = NULL;
- static int *bl_socket = NULL;
/* udp socket */
static int *u_socket = NULL;
- static int u_socket_count = 0;
/* handle SIGINT */
signal(SIGINT, sig_handler);
View
11 memcached.h
@@ -272,15 +272,22 @@ extern volatile rel_time_t current_time;
* Functions
*/
-conn *do_conn_from_freelist();
+conn *do_conn_from_freelist(void);
bool do_conn_add_to_freelist(conn *c);
-char *do_suffix_from_freelist();
+char *do_suffix_from_freelist(void);
bool do_suffix_add_to_freelist(char *s);
char *do_add_delta(conn *c, item *item, const bool incr, const int64_t delta,
char *buf);
int do_store_item(item *item, int comm, conn* c);
conn *conn_new(const int sfd, const enum conn_states init_state, const int event_flags, const int read_buffer_size, enum protocol prot, struct event_base *base);
+uint32_t append_bin_stats(char *buf, const char *key, const uint16_t klen,
+ const char *val, const uint32_t vlen);
+uint32_t append_ascii_stats(char *buf, const char *key, const uint16_t klen,
+ const char *val, const uint32_t vlen);
+#ifndef HAVE_DAEMON
+extern int daemon(int nochdir, int noclose);
+#endif
#include "stats.h"
#include "slabs.h"
View
8 protocol_binary.h
@@ -54,7 +54,7 @@ extern "C"
*/
typedef enum {
PROTOCOL_BINARY_REQ = 0x80,
- PROTOCOL_BINARY_RES = 0x81,
+ PROTOCOL_BINARY_RES = 0x81
} protocol_binary_magic;
/**
@@ -69,7 +69,7 @@ extern "C"
PROTOCOL_BINARY_RESPONSE_EINVAL = 0x04,
PROTOCOL_BINARY_RESPONSE_NOT_STORED = 0x05,
PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND = 0x81,
- PROTOCOL_BINARY_RESPONSE_ENOMEM = 0x82,
+ PROTOCOL_BINARY_RESPONSE_ENOMEM = 0x82
} protocol_binary_response_status;
/**
@@ -93,7 +93,7 @@ extern "C"
PROTOCOL_BINARY_CMD_GETKQ = 0x0d,
PROTOCOL_BINARY_CMD_APPEND = 0x0e,
PROTOCOL_BINARY_CMD_PREPEND = 0x0f,
- PROTOCOL_BINARY_CMD_STAT = 0x10,
+ PROTOCOL_BINARY_CMD_STAT = 0x10
} protocol_binary_command;
/**
@@ -101,7 +101,7 @@ extern "C"
* See section 3.4 Data Types
*/
typedef enum {
- PROTOCOL_BINARY_RAW_BYTES = 0x00,
+ PROTOCOL_BINARY_RAW_BYTES = 0x00
} protocol_binary_datatypes;
/**
View
30 slabs.c
@@ -264,7 +264,7 @@ void *do_slabs_alloc(const size_t size, unsigned int id) {
assert(p->end_page_ptr != NULL);
ret = p->end_page_ptr;
if (--p->end_page_free != 0) {
- p->end_page_ptr += p->size;
+ p->end_page_ptr = ((caddr_t)p->end_page_ptr) + p->size;
} else {
p->end_page_ptr = 0;
}
@@ -329,7 +329,7 @@ char *get_stats(const char *stat_type, uint32_t (*add_stats)(char *buf,
pos = buf;
/* prepare general statistics for the engine */
- sprintf(val, "%llu", stats.curr_bytes);
+ sprintf(val, "%llu", (unsigned long long)stats.curr_bytes);
size = add_stats(pos, "bytes", strlen("bytes"), val, strlen(val));
*buflen += size;
pos += size;
@@ -346,7 +346,7 @@ char *get_stats(const char *stat_type, uint32_t (*add_stats)(char *buf,
*buflen += size;
pos += size;
- sprintf(val, "%llu", stats.evictions);
+ sprintf(val, "%llu", (unsigned long long)stats.evictions);
size = add_stats(pos, "evictions", strlen("evictions"), val,
strlen(val));
*buflen += size;
@@ -385,61 +385,61 @@ char *get_stats(const char *stat_type, uint32_t (*add_stats)(char *buf,
char val[128];
uint32_t nbytes = 0;
- sprintf(val, "%d", info.arena);
+ sprintf(val, "%ld", info.arena);
nbytes = add_stats(pos, "arena_size", strlen("arena_size"), val,
strlen(val));
linelen += nbytes;
pos += nbytes;
- sprintf(val, "%d", info.ordblks);
+ sprintf(val, "%ld", info.ordblks);
nbytes = add_stats(pos, "free_chunks", strlen("free_chunks"), val,
strlen(val));
linelen += nbytes;
pos += nbytes;
- sprintf(val, "%d", info.smblks);
+ sprintf(val, "%ld", info.smblks);
nbytes = add_stats(pos, "fastbin_blocks", strlen("fastbin_blocks"),
val, strlen(val));
linelen += nbytes;
pos += nbytes;
- sprintf(val, "%d", info.hblks);
+ sprintf(val, "%ld", info.hblks);
nbytes = add_stats(pos, "mmapped_regions", strlen("mmapped_regions"),
val, strlen(val));
linelen += nbytes;
pos += nbytes;
- sprintf(val, "%d", info.hblkhd);
+ sprintf(val, "%ld", info.hblkhd);
nbytes = add_stats(pos, "mmapped_space", strlen("mmapped_space"),
val, strlen(val));
linelen += nbytes;
pos += nbytes;
- sprintf(val, "%d", info.usmblks);
+ sprintf(val, "%ld", info.usmblks);
nbytes = add_stats(pos, "max_total_alloc", strlen("max_total_alloc"),
val, strlen(val));
linelen += nbytes;
pos += nbytes;
- sprintf(val, "%d", info.fsmblks);
+ sprintf(val, "%ld", info.fsmblks);
nbytes = add_stats(pos, "fastbin_space", strlen("fastbin_space"),
val, strlen(val));
linelen += nbytes;
pos += nbytes;
- sprintf(val, "%d", info.uordblks);
+ sprintf(val, "%ld", info.uordblks);
nbytes = add_stats(pos, "total_alloc", strlen("total_alloc"), val,
strlen(val));
linelen += nbytes;
pos += nbytes;
- sprintf(val, "%d", info.fordblks);
+ sprintf(val, "%ld", info.fordblks);
nbytes = add_stats(pos, "total_free", strlen("total_free"), val,
strlen(val));
linelen += nbytes;
pos += nbytes;
- sprintf(val, "%d", info.keepcost);
+ sprintf(val, "%ld", info.keepcost);
nbytes = add_stats(pos, "releasable_space",
strlen("releasable_space"), val, strlen(val));
linelen += nbytes;
@@ -542,7 +542,7 @@ char *do_slabs_stats(uint32_t (*add_stats)(char *buf, const char *key,
bufcurr += nbytes;
sprintf(key, "total_malloced");
- sprintf(val, "%llu", (uint64_t)mem_malloced);
+ sprintf(val, "%llu", (unsigned long long)mem_malloced);
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
linelen += nbytes;
bufcurr += nbytes;
@@ -643,7 +643,7 @@ static void *memory_allocate(size_t size) {
size += CHUNK_ALIGN_BYTES - (size % CHUNK_ALIGN_BYTES);
}
- mem_current += size;
+ mem_current = ((char*)mem_current) + size;
if (size < mem_avail) {
mem_avail -= size;
} else {
View
5 thread.c
@@ -155,7 +155,7 @@ static void cq_push(CQ *cq, CQ_ITEM *item) {
/*
* Returns a fresh connection queue item.
*/
-static CQ_ITEM *cqi_new() {
+static CQ_ITEM *cqi_new(void) {
CQ_ITEM *item = NULL;
pthread_mutex_lock(&cqi_freelist_lock);
if (cqi_freelist) {
@@ -321,7 +321,8 @@ static void *worker_libevent(void *arg) {
pthread_cond_signal(&init_cond);
pthread_mutex_unlock(&init_lock);
- return (void*) event_base_loop(me->base, 0);
+ event_base_loop(me->base, 0);
+ return NULL;
}
Please sign in to comment.
Something went wrong with that request. Please try again.