Fix warnings found by clang r180088.

This commit is contained in:
Emil Mikulic 2013-04-28 21:24:33 +10:00
parent f29b75fb1d
commit efe37364eb
2 changed files with 42 additions and 56 deletions

View File

@ -76,10 +76,6 @@ static const int debug = 1;
# endif # endif
#endif #endif
#ifndef min
#define min(a,b) ( ((a)<(b)) ? (a) : (b) )
#endif
#if defined(O_EXCL) && !defined(O_EXLOCK) #if defined(O_EXCL) && !defined(O_EXLOCK)
# define O_EXLOCK O_EXCL # define O_EXLOCK O_EXCL
#endif #endif
@ -172,20 +168,11 @@ struct { \
#define LIST_FIRST(head) ((head)->lh_first) #define LIST_FIRST(head) ((head)->lh_first)
#define LIST_FOREACH(var, head, field) \
for ((var) = LIST_FIRST((head)); \
(var); \
(var) = LIST_NEXT((var), field))
#define LIST_FOREACH_SAFE(var, head, field, tvar) \ #define LIST_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = LIST_FIRST((head)); \ for ((var) = LIST_FIRST((head)); \
(var) && ((tvar) = LIST_NEXT((var), field), 1); \ (var) && ((tvar) = LIST_NEXT((var), field), 1); \
(var) = (tvar)) (var) = (tvar))
#define LIST_INIT(head) do { \
LIST_FIRST((head)) = NULL; \
} while (0)
#define LIST_INSERT_HEAD(head, elm, field) do { \ #define LIST_INSERT_HEAD(head, elm, field) do { \
if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \ if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\ LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
@ -203,7 +190,7 @@ struct { \
} while (0) } while (0)
/* [<-] */ /* [<-] */
LIST_HEAD(conn_list_head, connection) connlist = static LIST_HEAD(conn_list_head, connection) connlist =
LIST_HEAD_INITIALIZER(conn_list_head); LIST_HEAD_INITIALIZER(conn_list_head);
struct connection { struct connection {
@ -244,9 +231,9 @@ struct mime_mapping {
char *extension, *mimetype; char *extension, *mimetype;
}; };
struct mime_mapping *mime_map = NULL; static struct mime_mapping *mime_map = NULL;
size_t mime_map_size = 0; static size_t mime_map_size = 0;
size_t longest_ext = 0; static size_t longest_ext = 0;
/* If a connection is idle for idletime seconds or more, it gets closed and /* If a connection is idle for idletime seconds or more, it gets closed and
* removed from the connlist. Set to 0 to remove the timeout * removed from the connlist. Set to 0 to remove the timeout
@ -569,7 +556,7 @@ static char *make_safe_url(char *url) {
* unsorted order. Makes copies of extension and mimetype strings. * unsorted order. Makes copies of extension and mimetype strings.
*/ */
static void add_mime_mapping(const char *extension, const char *mimetype) { static void add_mime_mapping(const char *extension, const char *mimetype) {
unsigned int i; size_t i;
assert(strlen(extension) > 0); assert(strlen(extension) > 0);
assert(strlen(mimetype) > 0); assert(strlen(mimetype) > 0);
@ -1687,7 +1674,7 @@ static void generate_dir_listing(struct connection *conn, const char *path) {
append(listing, "\n</body>\n</html>\n"); append(listing, "\n</body>\n</html>\n");
conn->reply = listing->str; conn->reply = listing->str;
conn->reply_length = listing->length; conn->reply_length = (off_t)listing->length;
free(listing); /* don't free inside of listing */ free(listing); /* don't free inside of listing */
conn->header_length = xasprintf(&(conn->header), conn->header_length = xasprintf(&(conn->header),
@ -2067,7 +2054,10 @@ static ssize_t send_from_file(const int s, const int fd,
size = 1<<20; size = 1<<20;
return sendfile(s, fd, &ofs, size); return sendfile(s, fd, &ofs, size);
#else #else
/* Fake sendfile() with read(). */
# ifndef min
# define min(a,b) ( ((a)<(b)) ? (a) : (b) )
# endif
char buf[1<<15]; char buf[1<<15];
size_t amount = min(sizeof(buf), size); size_t amount = min(sizeof(buf), size);
ssize_t numread; ssize_t numread;
@ -2191,8 +2181,6 @@ static void httpd_poll(void) {
MAX_FD_SET(conn->socket, &send_set); MAX_FD_SET(conn->socket, &send_set);
bother_with_timeout = 1; bother_with_timeout = 1;
break; break;
default: errx(1, "invalid state");
} }
} }
#undef MAX_FD_SET #undef MAX_FD_SET
@ -2237,8 +2225,6 @@ static void httpd_poll(void) {
case DONE: case DONE:
/* (handled later; ignore for now as it's a valid state) */ /* (handled later; ignore for now as it's a valid state) */
break; break;
default: errx(1, "invalid state");
} }
if (conn->state == DONE) { if (conn->state == DONE) {
@ -2320,7 +2306,7 @@ static void daemonize_finish(void) {
close(fd_null); close(fd_null);
} }
/* [<-] pidfile helpers, based on FreeBSD src/lib/libutil/pidfile.c,v 1.3 /* [->] pidfile helpers, based on FreeBSD src/lib/libutil/pidfile.c,v 1.3
* Original was copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org> * Original was copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
*/ */
static int pidfile_fd = -1; static int pidfile_fd = -1;
@ -2343,7 +2329,7 @@ static int pidfile_read(void) {
if (fd == -1) if (fd == -1)
err(1, " after create failed"); err(1, " after create failed");
i = read(fd, buf, sizeof(buf) - 1); i = (int)read(fd, buf, sizeof(buf) - 1);
if (i == -1) if (i == -1)
err(1, "read from pidfile failed"); err(1, "read from pidfile failed");
xclose(fd); xclose(fd);

View File

@ -7,7 +7,7 @@ TARGET=$(dirname $0)/../darkhttpd.c
# Adjust to suit: # Adjust to suit:
LLVM=$HOME/llvm LLVM=$HOME/llvm
$LLVM/install/bin/clang \ $LLVM/install/bin/clang -Weverything -O \
-Weverything -Wno-unreachable-code -Wno-padded \ -Wno-unreachable-code -Wno-padded -Wno-disabled-macro-expansion \
-O $TARGET $TARGET
rm -f a.out rm -f a.out