From 4347b8987732b5bea83ddb8fb9605cf2c4a1c2fe Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 18 Feb 2010 18:44:38 -0800 Subject: http: avoid signedness warnings We never come close to the signed limits anywhere, so it should be safe either way, but make paranoid compiler settings less noisy if possible. --- ext/unicorn_http/common_field_optimization.h | 6 +++--- ext/unicorn_http/ext_help.h | 4 ++-- ext/unicorn_http/unicorn_http.rl | 13 ++++++------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/ext/unicorn_http/common_field_optimization.h b/ext/unicorn_http/common_field_optimization.h index 850fb90..42c5430 100644 --- a/ext/unicorn_http/common_field_optimization.h +++ b/ext/unicorn_http/common_field_optimization.h @@ -67,7 +67,7 @@ static void init_common_fields(void) char tmp[64]; memcpy(tmp, HTTP_PREFIX, HTTP_PREFIX_LEN); - for(i = 0; i < ARRAY_SIZE(common_http_fields); cf++, i++) { + for(i = ARRAY_SIZE(common_http_fields); --i >= 0; cf++) { /* Rack doesn't like certain headers prefixed with "HTTP_" */ if (!strcmp("CONTENT_LENGTH", cf->name) || !strcmp("CONTENT_TYPE", cf->name)) { @@ -87,8 +87,8 @@ static VALUE find_common_field(const char *field, size_t flen) int i; struct common_field *cf = common_http_fields; - for(i = 0; i < ARRAY_SIZE(common_http_fields); i++, cf++) { - if (cf->len == flen && !memcmp(cf->name, field, flen)) + for(i = ARRAY_SIZE(common_http_fields); --i >= 0; cf++) { + if (cf->len == (long)flen && !memcmp(cf->name, field, flen)) return cf->value; } return Qnil; diff --git a/ext/unicorn_http/ext_help.h b/ext/unicorn_http/ext_help.h index 7df73f7..888bd36 100644 --- a/ext/unicorn_http/ext_help.h +++ b/ext/unicorn_http/ext_help.h @@ -47,7 +47,7 @@ static void rb_18_str_set_len(VALUE str, long len) # define rb_str_modify(x) do {} while (0) #endif /* ! defined(HAVE_RB_STR_MODIFY) */ -static inline int str_cstr_eq(VALUE val, const char *ptr, size_t len) +static inline int str_cstr_eq(VALUE val, const char *ptr, long len) { return (RSTRING_LEN(val) == len && !memcmp(ptr, RSTRING_PTR(val), len)); } @@ -56,7 +56,7 @@ static inline int str_cstr_eq(VALUE val, const char *ptr, size_t len) str_cstr_eq(val, const_str, sizeof(const_str) - 1) /* strcasecmp isn't locale independent */ -static int str_cstr_case_eq(VALUE val, const char *ptr, size_t len) +static int str_cstr_case_eq(VALUE val, const char *ptr, long len) { if (RSTRING_LEN(val) == len) { const char *v = RSTRING_PTR(val); diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl index a95224c..eeef5e1 100644 --- a/ext/unicorn_http/unicorn_http.rl +++ b/ext/unicorn_http/unicorn_http.rl @@ -236,10 +236,9 @@ static void write_value(VALUE req, struct http_parser *hp, rb_hash_aset(req, g_http_host, STR_NEW(mark, fpc)); } action request_uri { - size_t len = LEN(mark, fpc); VALUE str; - VALIDATE_MAX_LENGTH(len, REQUEST_URI); + VALIDATE_MAX_LENGTH(LEN(mark, fpc), REQUEST_URI); str = rb_hash_aset(req, g_request_uri, STR_NEW(mark, fpc)); /* * "OPTIONS * HTTP/1.1\r\n" is a valid request, but we can't have '*' @@ -263,9 +262,8 @@ static void write_value(VALUE req, struct http_parser *hp, action http_version { http_version(hp, req, PTR_TO(mark), LEN(mark, fpc)); } action request_path { VALUE val; - size_t len = LEN(mark, fpc); - VALIDATE_MAX_LENGTH(len, REQUEST_PATH); + VALIDATE_MAX_LENGTH(LEN(mark, fpc), REQUEST_PATH); val = rb_hash_aset(req, g_request_path, STR_NEW(mark, fpc)); /* rack says PATH_INFO must start with "/" or be empty */ @@ -314,13 +312,13 @@ static void write_value(VALUE req, struct http_parser *hp, action skip_chunk_data { skip_chunk_data_hack: { - size_t nr = MIN(hp->len.chunk, REMAINING); + size_t nr = MIN((size_t)hp->len.chunk, REMAINING); memcpy(RSTRING_PTR(req) + hp->s.dest_offset, fpc, nr); hp->s.dest_offset += nr; hp->len.chunk -= nr; p += nr; assert(hp->len.chunk >= 0 && "negative chunk length"); - if (hp->len.chunk > REMAINING) { + if ((size_t)hp->len.chunk > REMAINING) { HP_FL_SET(hp, INCHUNK); goto post_exec; } else { @@ -360,7 +358,8 @@ static void http_parser_execute(struct http_parser *hp, p = buffer+off; pe = buffer+len; - assert(pe - p == len - off && "pointers aren't same distance"); + assert((void *)(pe - p) == (void *)(len - off) && + "pointers aren't same distance"); if (HP_FL_TEST(hp, INCHUNK)) { HP_FL_UNSET(hp, INCHUNK); -- cgit v1.2.3-24-ge0c7