summaryrefslogtreecommitdiff
path: root/event_tagging.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-09-23 22:45:55 -0400
committerNick Mathewson <nickm@torproject.org>2010-09-23 22:45:55 -0400
commit9c8db0f804360325e37f032c56c46ef627d2aaf7 (patch)
treeb41270caa2ab37509228528f4b69d0599412f5c2 /event_tagging.c
parent045eef4cdea75c12be49327f961d6d2002c105dd (diff)
downloadlibevent-9c8db0f804360325e37f032c56c46ef627d2aaf7.tar.gz
Fix all warnings in the main codebase flagged by -Wsigned-compare
Remember, the code int is_less_than(int a, unsigned b) { return a < b; } is buggy, since the C integer promotion rules basically turn it into int is_less_than(int a, unsigned b) { return ((unsigned)a) < b; } and we really want something closer to int is_less_than(int a, unsigned b) { return a < 0 || ((unsigned)a) < b; } . Suggested by an example from Ralph Castain
Diffstat (limited to 'event_tagging.c')
-rw-r--r--event_tagging.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/event_tagging.c b/event_tagging.c
index 9ee10113..2e31b825 100644
--- a/event_tagging.c
+++ b/event_tagging.c
@@ -194,9 +194,10 @@ static int
decode_tag_internal(ev_uint32_t *ptag, struct evbuffer *evbuf, int dodrain)
{
ev_uint32_t number = 0;
- int len = evbuffer_get_length(evbuf);
+ size_t len = evbuffer_get_length(evbuf);
ev_uint8_t *data;
- int count = 0, shift = 0, done = 0;
+ size_t count = 0;
+ int shift = 0, done = 0;
/*
* the encoding of a number is at most one byte more than its
@@ -225,7 +226,7 @@ decode_tag_internal(ev_uint32_t *ptag, struct evbuffer *evbuf, int dodrain)
if (ptag != NULL)
*ptag = number;
- return (count);
+ return count > INT_MAX ? INT_MAX : (int)(count);
}
int
@@ -524,11 +525,11 @@ evtag_unmarshal_fixed(struct evbuffer *src, ev_uint32_t need_tag, void *data,
int tag_len;
/* Now unmarshal a tag and check that it matches the tag we want */
- if ((tag_len = evtag_unmarshal_header(src, &tag)) == -1 ||
+ if ((tag_len = evtag_unmarshal_header(src, &tag)) < 0 ||
tag != need_tag)
return (-1);
- if (tag_len != len)
+ if ((size_t)tag_len != len)
return (-1);
evbuffer_remove(src, data, len);