From f0ff792afabecc032bc9f92e504ff6601057b415 Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Sat, 30 Jun 2007 18:58:34 +0000 Subject: [PATCH] fixes from Joerg Sonnenberger: http.c is a violation of the ctype(3) interface and an unused function. test/regress_http.c are incorrect format strings. test/regress.c uses raise(3) from signal.h. evdns.c: evdns_error_strings is unused. The GET* macros can eat the semicolon from the expression. pos is passed in as off_t, so just pass that down. When assigning negativ values to unsigned variables, an explicit cast is considered good style. svn:r367 --- buffer.c | 2 +- evdns.c | 16 +++++++--------- event.h | 1 + event_tagging.c | 2 +- http.c | 7 ++++--- test/regress.c | 1 + test/regress_http.c | 4 ++-- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/buffer.c b/buffer.c index 6b558a83..0a57dda3 100644 --- a/buffer.c +++ b/buffer.c @@ -249,7 +249,7 @@ evbuffer_readline(struct evbuffer *buffer) /* Adds data to an event buffer */ -static inline void +static void evbuffer_align(struct evbuffer *buf) { memmove(buf->orig_buffer, buf->buffer, buf->off); diff --git a/evdns.c b/evdns.c index 068dc7df..7c45d782 100644 --- a/evdns.c +++ b/evdns.c @@ -307,8 +307,6 @@ static int global_max_nameserver_timeout = 3; static const struct timeval global_nameserver_timeouts[] = {{10, 0}, {60, 0}, {300, 0}, {900, 0}, {3600, 0}}; static const int global_nameserver_timeouts_length = sizeof(global_nameserver_timeouts)/sizeof(struct timeval); -static const char *const evdns_error_strings[] = {"no error", "The name server was unable to interpret the query", "The name server suffered an internal error", "The requested domain name does not exist", "The name server refused to reply to the request"}; - static struct nameserver *nameserver_pick(void); static void evdns_request_insert(struct request *req, struct request **head); static void nameserver_ready_callback(int fd, short events, void *arg); @@ -744,14 +742,14 @@ reply_handle(struct request *const req, u16 flags, u32 ttl, struct reply *reply) } } -static inline int +static int name_parse(u8 *packet, int length, int *idx, char *name_out, int name_out_len) { int name_end = -1; int j = *idx; int ptr_count = 0; -#define GET32(x) do { if (j + 4 > length) goto err; memcpy(&_t32, packet + j, 4); j += 4; x = ntohl(_t32); } while(0); -#define GET16(x) do { if (j + 2 > length) goto err; memcpy(&_t, packet + j, 2); j += 2; x = ntohs(_t); } while(0); -#define GET8(x) do { if (j >= length) goto err; x = packet[j++]; } while(0); +#define GET32(x) do { if (j + 4 > length) goto err; memcpy(&_t32, packet + j, 4); j += 4; x = ntohl(_t32); } while(0) +#define GET16(x) do { if (j + 2 > length) goto err; memcpy(&_t, packet + j, 2); j += 2; x = ntohs(_t); } while(0) +#define GET8(x) do { if (j >= length) goto err; x = packet[j++]; } while(0) char *cp = name_out; const char *const end = name_out + name_out_len; @@ -1226,7 +1224,7 @@ server_port_ready_callback(int fd, short events, void *arg) { * functions, so that is can be safely replaced with something smarter later. */ #define MAX_LABELS 128 // Structures used to implement name compression -struct dnslabel_entry { char *v; int pos; }; +struct dnslabel_entry { char *v; off_t pos; }; struct dnslabel_table { int n_labels; // number of current entries // map from name to position in message @@ -1265,7 +1263,7 @@ dnslabel_table_get_pos(const struct dnslabel_table *table, const char *label) // remember that we've used the label at position pos static int -dnslabel_table_add(struct dnslabel_table *table, const char *label, int pos) +dnslabel_table_add(struct dnslabel_table *table, const char *label, off_t pos) { char *v; int p; @@ -1483,7 +1481,7 @@ evdns_server_request_add_reply(struct evdns_server_request *_req, int section, c free(item); return -1; } - item->datalen = -1; + item->datalen = (u16)-1; } else { if (!(item->data = malloc(datalen))) { free(item->name); diff --git a/event.h b/event.h index 8687f194..753008a7 100644 --- a/event.h +++ b/event.h @@ -31,6 +31,7 @@ extern "C" { #endif +#include #include #ifdef WIN32 diff --git a/event_tagging.c b/event_tagging.c index 7a82b829..6bb44e23 100644 --- a/event_tagging.c +++ b/event_tagging.c @@ -149,7 +149,7 @@ evtag_marshal_timeval(struct evbuffer *evbuf, u_int8_t tag, struct timeval *tv) EVBUFFER_LENGTH(_buf)); } -static int inline +static int decode_int_internal(u_int32_t *pnumber, struct evbuffer *evbuf, int dodrain) { u_int32_t number = 0; diff --git a/http.c b/http.c index 7b654c7f..be9421f2 100644 --- a/http.c +++ b/http.c @@ -1735,8 +1735,8 @@ evhttp_decode_uri(const char *uri) in_query = 1; } else if (c == '+' && in_query) { c = ' '; - } else if (c == '%' && isxdigit(uri[i+1]) && - isxdigit(uri[i+2])) { + } else if (c == '%' && isxdigit((unsigned char)uri[i+1]) && + isxdigit((unsigned char)uri[i+2])) { char tmp[] = { uri[i+1], uri[i+2], '\0' }; c = (char)strtol(tmp, NULL, 16); i += 2; @@ -2178,7 +2178,7 @@ evhttp_get_request(struct evhttp *http, int fd, * Network helper functions that we do not want to export to the rest of * the world. */ - +#if 0 /* Unused */ static struct addrinfo * addr_from_name(char *address) { @@ -2203,6 +2203,7 @@ addr_from_name(char *address) return NULL; // XXXXX Use gethostbyname, if this function is ever used. #endif } +#endif static void name_from_addr(struct sockaddr *sa, socklen_t salen, diff --git a/test/regress.c b/test/regress.c index 455604d5..602449d1 100644 --- a/test/regress.c +++ b/test/regress.c @@ -48,6 +48,7 @@ #endif #include #include +#include #include #include #include diff --git a/test/regress_http.c b/test/regress_http.c index 3fdaacb4..33f070b8 100644 --- a/test/regress_http.c +++ b/test/regress_http.c @@ -389,7 +389,7 @@ http_post_cb(struct evhttp_request *req, void *arg) } if (EVBUFFER_LENGTH(req->input_buffer) != strlen(POST_DATA)) { - fprintf(stdout, "FAILED (length: %ld vs %ld)\n", + fprintf(stdout, "FAILED (length: %zu vs %zu)\n", EVBUFFER_LENGTH(req->input_buffer), strlen(POST_DATA)); exit(1); } @@ -427,7 +427,7 @@ http_postrequest_done(struct evhttp_request *req, void *arg) } if (EVBUFFER_LENGTH(req->input_buffer) != strlen(what)) { - fprintf(stderr, "FAILED (length %ld vs %ld)\n", + fprintf(stderr, "FAILED (length %zu vs %zu)\n", EVBUFFER_LENGTH(req->input_buffer), strlen(what)); exit(1); }