Fix various little bugs and loosen up various warnings

Change-Id: Iead48ac030290290c7c448b6f72a31380c2e8326
diff --git a/third_party/libevent/BUILD b/third_party/libevent/BUILD
index 7c3fc10..50f714a 100644
--- a/third_party/libevent/BUILD
+++ b/third_party/libevent/BUILD
@@ -48,5 +48,15 @@
   copts = [
     '-Ithird_party/libevent/compat',
     '-Ithird_party/libevent/include',
+
+    # TODO(Brian): Fix the places in the code it uses char* as an intermediate
+    # type while doing offsetof stuff.
+    '-Wno-cast-align',
+
+    '-Wno-unused-parameter',
+    '-Wno-format-nonliteral',
+    '-Wno-cast-qual',
+    '-Wno-incompatible-pointer-types-discards-qualifiers',
+    '-Wno-unused-function',
   ],
 )
diff --git a/third_party/libevent/buffer.c b/third_party/libevent/buffer.c
index 8510955..80a9e1b 100644
--- a/third_party/libevent/buffer.c
+++ b/third_party/libevent/buffer.c
@@ -1680,7 +1680,7 @@
 		} else if (chain->misalign) {
 			/* we can only fit some of the data. */
 			memcpy(chain->buffer,
-			    (char*)data + datlen - chain->misalign,
+			    (const char*)data + datlen - chain->misalign,
 			    (size_t)chain->misalign);
 			chain->off += (size_t)chain->misalign;
 			buf->total_len += (size_t)chain->misalign;
@@ -2749,7 +2749,7 @@
 	if (!chain)
 		return (-1);
 	chain->flags |= EVBUFFER_REFERENCE | EVBUFFER_IMMUTABLE;
-	chain->buffer = (u_char *)data;
+	chain->buffer = (const u_char *)data;
 	chain->buffer_len = datlen;
 	chain->off = datlen;
 
diff --git a/third_party/libevent/evdns.c b/third_party/libevent/evdns.c
index 60b1048..3ae5d8b 100644
--- a/third_party/libevent/evdns.c
+++ b/third_party/libevent/evdns.c
@@ -2471,7 +2471,7 @@
 	ASSERT_LOCKED(base);
 	if (server) {
 		do {
-			if (!evutil_sockaddr_cmp((struct sockaddr*)&server->address, address, 1)) return 3;
+			if (!evutil_sockaddr_cmp((const struct sockaddr*)&server->address, address, 1)) return 3;
 			server = server->next;
 		} while (server != started_at);
 	}
diff --git a/third_party/libevent/event_tagging.c b/third_party/libevent/event_tagging.c
index eea4bfc..ece9a0d 100644
--- a/third_party/libevent/event_tagging.c
+++ b/third_party/libevent/event_tagging.c
@@ -250,7 +250,7 @@
 {
 	evtag_encode_tag(evbuf, tag);
 	evtag_encode_int(evbuf, len);
-	evbuffer_add(evbuf, (void *)data, len);
+	evbuffer_add(evbuf, (const void *)data, len);
 }
 
 void
diff --git a/third_party/libevent/evutil_rand.c b/third_party/libevent/evutil_rand.c
index 284341c..8641f3d 100644
--- a/third_party/libevent/evutil_rand.c
+++ b/third_party/libevent/evutil_rand.c
@@ -174,7 +174,7 @@
 void
 evutil_secure_rng_add_bytes(const char *buf, size_t n)
 {
-	arc4random_addrandom((unsigned char*)buf,
+	arc4random_addrandom((const unsigned char*)buf,
 	    n>(size_t)INT_MAX ? INT_MAX : (int)n);
 }
 
diff --git a/third_party/libevent/ht-internal.h b/third_party/libevent/ht-internal.h
index 4673825..a56c4a6 100644
--- a/third_party/libevent/ht-internal.h
+++ b/third_party/libevent/ht-internal.h
@@ -137,7 +137,7 @@
   /* Helper: returns a pointer to the right location in the table       \
    * 'head' to find or insert the element 'elm'. */                     \
   static inline struct type **                                          \
-  _##name##_HT_FIND_P(struct name *head, struct type *elm)              \
+  _##name##_HT_FIND_P(const struct name *head, struct type *elm)        \
   {                                                                     \
     struct type **p;                                                    \
     if (!head->hth_table)                                               \
@@ -156,7 +156,7 @@
   name##_HT_FIND(const struct name *head, struct type *elm)             \
   {                                                                     \
     struct type **p;                                                    \
-    struct name *h = (struct name *) head;                              \
+    const struct name *h = (const struct name *) head;                  \
     _HT_SET_HASH(elm, field, hashfn);                                   \
     p = _##name##_HT_FIND_P(h, elm);                                    \
     return p ? *p : NULL;                                               \