From 3f96e6a7a317e70b85b32de4aa06681c11d79006 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 4 Aug 2011 20:31:24 +0400 Subject: [PATCH] Fix signness in arithmetic operations. --- CMakeLists.txt | 8 ------- lib/librspamdclient.c | 10 ++++----- src/binlog.c | 2 +- src/bloom.c | 2 +- src/buffer.c | 10 ++++----- src/cfg_utils.c | 2 +- src/cfg_xml.c | 4 ++-- src/classifiers/bayes.c | 8 +++---- src/classifiers/classifiers.c | 2 +- src/controller.c | 4 ++-- src/diff.c | 2 +- src/dns.c | 10 +++------ src/expressions.c | 2 +- src/fstring.c | 8 +++---- src/fuzzy.c | 10 ++++----- src/fuzzy_storage.c | 4 ++-- src/hash.c | 2 +- src/html.c | 4 ++-- src/lmtp_proto.c | 8 +++---- src/lua/lua_common.c | 3 ++- src/lua/lua_task.c | 2 +- src/main.c | 4 ++-- src/map.c | 18 ++++++++-------- src/map.h | 10 ++++----- src/mem_pool.c | 39 +++++++++++++++++------------------ src/memcached.c | 4 ++-- src/message.c | 4 ++-- src/plugins/chartable.c | 2 +- src/plugins/fuzzy_check.c | 10 ++++----- src/plugins/regexp.c | 8 +++---- src/plugins/surbl.c | 8 +++---- src/protocol.c | 2 +- src/settings.c | 8 +++---- src/smtp.c | 4 ++-- src/smtp_proto.c | 4 ++-- src/spf.c | 4 ++-- src/statfile.c | 8 +++---- src/statfile_sync.c | 6 +++--- src/symbols_cache.c | 21 ++++++++++--------- src/tokenizers/tokenizers.c | 2 +- src/trie.c | 4 ++-- src/upstream.c | 26 +++++++++++------------ src/url.c | 8 +++---- src/util.c | 6 +++--- src/view.c | 2 +- src/worker.c | 2 +- 46 files changed, 155 insertions(+), 166 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fc127958..09ca24275 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -502,9 +502,7 @@ CHECK_C_COMPILER_FLAG(-Wall SUPPORT_W) CHECK_C_COMPILER_FLAG(-Wpointer-arith SUPPORT_WPOINTER) CHECK_C_COMPILER_FLAG(-Wno-unused-parameter SUPPORT_WPARAM) CHECK_C_COMPILER_FLAG(-Wno-unused-function SUPPORT_WFUNCTION) -CHECK_C_COMPILER_FLAG(-Wno-sign-compare SUPPORT_WSIGNCOMPARE) CHECK_C_COMPILER_FLAG(-Wunused-variable SUPPORT_WUNUSED_VAR) -CHECK_C_COMPILER_FLAG(-Wno-declaration-after-statement SUPPORT_WDECL) CHECK_C_COMPILER_FLAG(-Wno-pointer-sign SUPPORT_WPOINTER_SIGN) CHECK_C_COMPILER_FLAG(-pedantic SUPPORT_PEDANTIC_FLAG) CHECK_C_COMPILER_FLAG("-std=c99" SUPPORT_STD_FLAG) @@ -526,15 +524,9 @@ ENDIF(SUPPORT_WPARAM) IF(SUPPORT_WFUNCTION) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-unused-function") ENDIF(SUPPORT_WFUNCTION) -IF(SUPPORT_WSIGNCOMPARE) - SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-sign-compare ") -ENDIF(SUPPORT_WSIGNCOMPARE) IF(SUPPORT_WUNUSED_VAR) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wunused-variable") ENDIF(SUPPORT_WUNUSED_VAR) -IF(SUPPORT_WDECL) - SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-declaration-after-statement") -ENDIF(SUPPORT_WDECL) IF(SUPPORT_WPOINTER_SIGN) SET(CMAKE_C_WARN_FLAGS "${CMAKE_C_WARN_FLAGS} -Wno-pointer-sign") ENDIF(SUPPORT_WPOINTER_SIGN) diff --git a/lib/librspamdclient.c b/lib/librspamdclient.c index e871c29f6..69c6edca8 100644 --- a/lib/librspamdclient.c +++ b/lib/librspamdclient.c @@ -439,7 +439,7 @@ parse_rspamd_metric_line (struct rspamd_connection *conn, guint len, GError **er case 1: /* Read boolean result */ if (*p == ';') { - if (p - c >= sizeof("Skip")) { + if (p - c >= (gint)sizeof("Skip")) { if (memcmp (c, "Skip", p - c - 1) == 0) { new->is_skipped = TRUE; } @@ -879,12 +879,12 @@ read_rspamd_reply_line (struct rspamd_connection *c, GError **err) /* Try to obtain string from the input buffer */ if (c->in_buf->len > 0) { len = 0; - while (len < c->in_buf->len) { + while (len < (gint)c->in_buf->len) { p = c->in_buf->str[len]; if (p == '\r' || p == '\n') { if (parse_rspamd_reply_line (c, len, err)) { /* Strip '\r\n' */ - while (len < c->in_buf->len && (p == '\r' || p == '\n')) { + while (len < (gint)c->in_buf->len && (p == '\r' || p == '\n')) { p = c->in_buf->str[++len]; } /* Move remaining buffer to the begin of string */ @@ -1116,7 +1116,7 @@ rspamd_send_controller_command (struct rspamd_connection *c, const gchar *line, } if ((r = read (c->socket, tmpbuf, sizeof (tmpbuf))) > 0) { /* Check the end of the buffer for END marker */ - if (r >= sizeof (end_marker) - 1 && + if (r >= (gint)sizeof (end_marker) - 1 && memcmp (tmpbuf + r - sizeof (end_marker) + 1, end_marker, sizeof (end_marker) - 1) == 0) { r -= sizeof (end_marker) - 1; /* Copy the rest to the result string */ @@ -1204,7 +1204,7 @@ rspamd_read_controller_greeting (struct rspamd_connection *c, GError **err) return FALSE; } if ((r = read (c->socket, inbuf, sizeof (inbuf))) > 0) { - if (r >= sizeof (greeting_str) - 1 && + if (r >= (gint)sizeof (greeting_str) - 1 && memcmp (inbuf, greeting_str, sizeof (greeting_str) - 1) == 0) { return TRUE; } diff --git a/src/binlog.c b/src/binlog.c index 2a1eb9fcb..f87a81b00 100644 --- a/src/binlog.c +++ b/src/binlog.c @@ -313,7 +313,7 @@ maybe_rotate_binlog (struct rspamd_binlog *log) { guint64 now = time (NULL); - if (log->rotate_time && ((now - log->header.create_time) > log->rotate_time + log->rotate_jitter)) { + if (log->rotate_time && ((now - log->header.create_time) > (guint)(log->rotate_time + log->rotate_jitter))) { return TRUE; } return FALSE; diff --git a/src/bloom.c b/src/bloom.c index 483d596d7..6488976f6 100644 --- a/src/bloom.c +++ b/src/bloom.c @@ -164,7 +164,7 @@ bloom_create (size_t size, size_t nfuncs, ...) { bloom_filter_t *bloom; va_list l; - gint n; + gsize n; if (!(bloom = g_malloc (sizeof (bloom_filter_t)))) { return NULL; diff --git a/src/buffer.c b/src/buffer.c index 666869d51..a1f4bee9b 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -101,7 +101,7 @@ sendfile_callback (rspamd_io_dispatcher_t *d) event_add (d->ev, d->tv); } } - else if (r + d->offset < d->file_size) { + else if (r + d->offset < (ssize_t)d->file_size) { debug_ip("partially write data, retry"); /* Wait for other event */ event_del (d->ev); @@ -334,7 +334,7 @@ read_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean skip_read) * c - pointer to current position (buffer->begin + r) * res - result string */ - while (r < len) { + while (r < (ssize_t)len) { if (*c == '\n') { res.begin = b; res.len = c - b; @@ -389,7 +389,7 @@ read_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean skip_read) break; case BUFFER_CHARACTER: r = d->nchars; - if (len >= r) { + if ((ssize_t)len >= r) { res.begin = b; res.len = r; c = b + r; @@ -398,7 +398,7 @@ read_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean skip_read) return; } /* Move remaining string to begin of buffer (draining) */ - if (len > r) { + if ((ssize_t)len > r) { len -= r; memmove (d->in_buf->data->begin, c, len); d->in_buf->data->len = len; @@ -409,7 +409,7 @@ read_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean skip_read) d->in_buf->data->len = 0; d->in_buf->pos = d->in_buf->data->begin; } - if (d->policy != saved_policy && len != r) { + if (d->policy != saved_policy && (ssize_t)len != r) { debug_ip("policy changed during callback, restart buffer's processing"); read_buffers (fd, d, TRUE); return; diff --git a/src/cfg_utils.c b/src/cfg_utils.c index e01360379..203133e77 100644 --- a/src/cfg_utils.c +++ b/src/cfg_utils.c @@ -521,7 +521,7 @@ parse_filters_str (struct config_file *cfg, const gchar *str) { gchar **strvec, **p; struct filter *cur; - gint i; + guint i; if (str == NULL) { return; diff --git a/src/cfg_xml.c b/src/cfg_xml.c index 27667649d..4acc48673 100644 --- a/src/cfg_xml.c +++ b/src/cfg_xml.c @@ -690,7 +690,7 @@ call_param_handler (struct rspamd_xml_userdata *ctx, const gchar *name, gchar *v { struct xml_parser_rule *rule; struct xml_config_param *param; - gint i; + guint i; /* First find required section */ for (i = 0; i < G_N_ELEMENTS (grammar); i ++) { @@ -1159,7 +1159,7 @@ handle_module_path (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GH glob_t globbuf; gchar *pattern; size_t len; - gint i; + guint i; if (stat (data, &st) == -1) { msg_err ("cannot stat path %s, %s", data, strerror (errno)); diff --git a/src/classifiers/bayes.c b/src/classifiers/bayes.c index 15a50b2da..bf7e4d9d4 100644 --- a/src/classifiers/bayes.c +++ b/src/classifiers/bayes.c @@ -110,7 +110,7 @@ bayes_classify_callback (gpointer key, gpointer value, gpointer data) token_node_t *node = key; struct bayes_callback_data *cd = data; double renorm = 0; - gint i; + guint i; double local_hits = 0; struct bayes_statfile_data *cur; @@ -183,7 +183,7 @@ bayes_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct bayes_callback_data data; gchar *value; gint nodes, i = 0, cnt, best_num = 0; - gsize minnodes; + gint minnodes; guint64 rev, total_learns = 0; double best = 0; struct statfile *st; @@ -287,7 +287,7 @@ bayes_learn (struct classifier_ctx* ctx, statfile_pool_t *pool, const char *symb struct bayes_callback_data data; gchar *value; gint nodes; - gsize minnodes; + gint minnodes; struct statfile *st, *sel_st = NULL; stat_file_t *to_learn; GList *cur; @@ -387,7 +387,7 @@ bayes_learn_spam (struct classifier_ctx* ctx, statfile_pool_t *pool, struct bayes_callback_data data; gchar *value; gint nodes; - gsize minnodes; + gint minnodes; struct statfile *st; stat_file_t *file; GList *cur; diff --git a/src/classifiers/classifiers.c b/src/classifiers/classifiers.c index d745a4d9d..85c018701 100644 --- a/src/classifiers/classifiers.c +++ b/src/classifiers/classifiers.c @@ -50,7 +50,7 @@ struct classifier classifiers[] = { struct classifier * get_classifier (char *name) { - int i; + guint i; for (i = 0; i < sizeof (classifiers) / sizeof (classifiers[0]); i++) { if (strcmp (classifiers[i].name, name) == 0) { diff --git a/src/controller.c b/src/controller.c index ca9cdce7a..cc62b63dd 100644 --- a/src/controller.c +++ b/src/controller.c @@ -210,7 +210,7 @@ write_whole_statfile (struct controller_session *session, gchar *symbol, struct stat_file_t *statfile; struct statfile *st; gchar out_buf[BUFSIZ]; - gint i; + guint i; guint64 rev, ti, len, pos, blocks; gchar *out; struct rspamd_binlog_element log_elt; @@ -807,7 +807,7 @@ process_custom_command (gchar *line, gchar **cmd_args, struct controller_session static struct controller_command * process_normal_command (const gchar *line) { - gint i; + guint i; struct controller_command *c; for (i = 0; i < G_N_ELEMENTS (commands); i ++) { diff --git a/src/diff.c b/src/diff.c index 45984ab38..56f4498ca 100644 --- a/src/diff.c +++ b/src/diff.c @@ -355,7 +355,7 @@ compare_diff_distance (f_str_t *s1, f_str_t *s2) { GArray *ses; struct diff_edit *e; - gint i; + guint i; guint32 distance = 0; ses = g_array_sized_new (FALSE, TRUE, sizeof (struct diff_edit), MAX_DIFF); diff --git a/src/dns.c b/src/dns.c index 40aaa08d8..f328b4e66 100644 --- a/src/dns.c +++ b/src/dns.c @@ -770,7 +770,7 @@ dns_parse_rr (guint8 *in, union rspamd_reply_element *elt, guint8 **pos, struct msg_info ("bad RR name"); return -1; } - if (p - *pos >= *remain - sizeof (guint16) * 5 || *remain <= 0) { + if ((gint)(p - *pos) >= (gint)(*remain - sizeof (guint16) * 5) || *remain <= 0) { msg_info ("stripped dns reply"); return -1; } @@ -875,7 +875,7 @@ dns_parse_rr (guint8 *in, union rspamd_reply_element *elt, guint8 **pos, struct p += datalen; } else { - if (p - *pos > *remain - sizeof (guint16) * 3) { + if (p - *pos > (gint)(*remain - sizeof (guint16) * 3)) { msg_info ("stripped dns reply while reading SRV record"); return -1; } @@ -937,10 +937,6 @@ dns_parse_reply (guint8 *in, gint r, struct rspamd_dns_resolver *resolver, if ((pos = dns_request_reply_cmp (req, in + sizeof (struct dns_header), r - sizeof (struct dns_header))) == NULL) { return FALSE; } - /* - * Remove delayed retransmits for this packet - */ - event_del (&req->timer_event); /* * Now pos is in answer section, so we should extract data and form reply */ @@ -1009,7 +1005,7 @@ dns_read_cb (gint fd, short what, void *arg) /* First read packet from socket */ r = read (fd, in, sizeof (in)); - if (r > sizeof (struct dns_header) + sizeof (struct dns_query)) { + if (r > (gint)(sizeof (struct dns_header) + sizeof (struct dns_query))) { if (dns_parse_reply (in, r, resolver, &req, &rep)) { /* Decrease errors count */ if (rep->request->resolver->errors > 0) { diff --git a/src/expressions.c b/src/expressions.c index a0bab2855..acf1b31a2 100644 --- a/src/expressions.c +++ b/src/expressions.c @@ -1731,7 +1731,7 @@ compare_subtype (struct worker_task *task, GMimeContentType * ct, gchar *subtype } static inline gboolean -compare_len (struct mime_part *part, gint min, gint max) +compare_len (struct mime_part *part, guint min, guint max) { if (min == 0 && max == 0) { return TRUE; diff --git a/src/fstring.c b/src/fstring.c index 3f7ae2195..c2d48603b 100644 --- a/src/fstring.c +++ b/src/fstring.c @@ -30,7 +30,7 @@ ssize_t fstrchr (f_str_t * src, gchar c) { - register ssize_t cur = 0; + register size_t cur = 0; while (cur < src->len) { if (*(src->begin + cur) == c) { @@ -66,7 +66,7 @@ fstrrchr (f_str_t * src, gchar c) ssize_t fstrstr (f_str_t * orig, f_str_t * pattern) { - register ssize_t cur = 0, pcur = 0; + register size_t cur = 0, pcur = 0; if (pattern->len > orig->len) { return -1; @@ -97,7 +97,7 @@ fstrstr (f_str_t * orig, f_str_t * pattern) ssize_t fstrstri (f_str_t * orig, f_str_t * pattern) { - register ssize_t cur = 0, pcur = 0; + register size_t cur = 0, pcur = 0; if (pattern->len > orig->len) { return -1; @@ -410,7 +410,7 @@ void fstrstrip (f_str_t * str) { gchar *p = str->begin; - gint r = 0; + guint r = 0; while (r < str->len) { if (g_ascii_isspace (*p)) { diff --git a/src/fuzzy.c b/src/fuzzy.c index dba76fe69..3901375ca 100644 --- a/src/fuzzy.c +++ b/src/fuzzy.c @@ -256,7 +256,7 @@ fuzzy_hash_t * fuzzy_init (f_str_t * in, memory_pool_t * pool) { fuzzy_hash_t *new; - gint i, repeats = 0; + guint i, repeats = 0; gchar *c = in->begin, last = '\0'; gsize real_len = 0; @@ -337,7 +337,7 @@ fuzzy_init_part (struct mime_text_part *part, memory_pool_t *pool, gsize max_dif if (part->is_utf) { while (c < end) { - if (cur_ex != NULL && cur_ex->pos == c - begin) { + if (cur_ex != NULL && (gint)cur_ex->pos == c - begin) { c += cur_ex->len + 1; cur_offset = g_list_next (cur_offset); if (cur_offset != NULL) { @@ -355,7 +355,7 @@ fuzzy_init_part (struct mime_text_part *part, memory_pool_t *pool, gsize max_dif } else { while (c < end) { - if (cur_ex != NULL && cur_ex->pos == c - begin) { + if (cur_ex != NULL && (gint)cur_ex->pos == c - begin) { c += cur_ex->len + 1; cur_offset = g_list_next (cur_offset); if (cur_offset != NULL) { @@ -394,7 +394,7 @@ fuzzy_init_part (struct mime_text_part *part, memory_pool_t *pool, gsize max_dif if (part->is_utf) { while (c < end) { - if (cur_ex != NULL && cur_ex->pos == c - begin) { + if (cur_ex != NULL && (gint)cur_ex->pos == c - begin) { c += cur_ex->len + 1; cur_offset = g_list_next (cur_offset); if (cur_offset != NULL) { @@ -415,7 +415,7 @@ fuzzy_init_part (struct mime_text_part *part, memory_pool_t *pool, gsize max_dif } else { while (c < end) { - if (cur_ex != NULL && cur_ex->pos == c - begin) { + if (cur_ex != NULL && (gint)cur_ex->pos == c - begin) { c += cur_ex->len + 1; cur_offset = g_list_next (cur_offset); if (cur_offset != NULL) { diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 45f24b950..b9b05cb87 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -364,7 +364,7 @@ read_hashes_file (struct rspamd_worker *wrk) } else { #endif - if (node->value > ctx->frequent_score) { + if (node->value > (gint)ctx->frequent_score) { g_queue_push_head (frequent, node); } else { @@ -453,7 +453,7 @@ check_hash_node (GQueue *hash, fuzzy_hash_t *s, gint update_value, struct rspamd h->value += update_value; msg_info ("new hash weight: %d", h->value); } - if (h->value > ctx->frequent_score) { + if (h->value > (gint)ctx->frequent_score) { g_queue_unlink (hash, cur); g_queue_push_head_link (frequent, cur); msg_info ("moved hash to frequent list"); diff --git a/src/hash.c b/src/hash.c index 1d10e1048..f5444ba5b 100644 --- a/src/hash.c +++ b/src/hash.c @@ -401,7 +401,7 @@ rspamd_lru_hash_insert (rspamd_lru_hash_t *hash, gpointer key, gpointer value, t rspamd_lru_element_t *res; gint removed = 0; - if (g_hash_table_size (hash->storage) >= hash->maxsize) { + if ((gint)g_hash_table_size (hash->storage) >= hash->maxsize) { /* Expire some elements */ res = g_queue_pop_tail (hash->q); while (res != NULL && now - res->store_time > hash->maxage) { diff --git a/src/html.c b/src/html.c index 9a6541610..04dfdfa89 100644 --- a/src/html.c +++ b/src/html.c @@ -685,7 +685,7 @@ check_phishing (struct worker_task *task, struct uri *href_url, const gchar *url break; } } - rspamd_strlcpy (tagbuf, c, MIN (sizeof(tagbuf), p - c + 1)); + rspamd_strlcpy (tagbuf, c, MIN ((gint)sizeof(tagbuf), p - c + 1)); if ((tag = get_tag_by_name (tagbuf)) != NULL) { if (tag->id == id) { break; @@ -797,7 +797,7 @@ parse_tag_url (struct worker_task *task, struct mime_text_part *part, tag_id_t i } len = 0; p = c; - while (*p && p - tag_text < tag_len) { + while (*p && (guint)(p - tag_text) < tag_len) { if (got_double_quote) { if (*p == '"') { break; diff --git a/src/lmtp_proto.c b/src/lmtp_proto.c index de2305924..a8c462b03 100644 --- a/src/lmtp_proto.c +++ b/src/lmtp_proto.c @@ -111,7 +111,7 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t * line) { gchar *c, *rcpt; f_str_t fstr; - guint i = 0, l = 0, size; + gint i = 0, l = 0, size; switch (lmtp->state) { case LMTP_READ_LHLO: @@ -125,7 +125,7 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t * line) i += lhlo_command.len; c = line->begin + i; /* Skip spaces */ - while (g_ascii_isspace (*c) && i < line->len) { + while (g_ascii_isspace (*c) && i < (gint)line->len) { i++; c++; } @@ -222,9 +222,9 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t * line) else { l = lmtp->task->msg->len; size = lmtp->task->msg->size; - if (l + line->len > size) { + if ((gint)(l + line->len) > size) { /* Grow buffer */ - if (line->len > size) { + if ((gint)line->len > size) { size += line->len << 1; } else { diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 1583ee8e3..84f3bb659 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -340,7 +340,8 @@ lua_call_filter (const gchar *function, struct worker_task *task) gint lua_call_chain_filter (const gchar *function, struct worker_task *task, gint *marks, guint number) { - gint result, i; + gint result; + guint i; lua_State *L = task->cfg->lua_state; lua_getglobal (L, function); diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index c08c88491..92c57a9d6 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -1333,7 +1333,7 @@ lua_textpart_get_language (lua_State * L) }; const gchar *sel; - if (part != NULL && part->script > 0 && part->script < G_N_ELEMENTS (languages)) { + if (part != NULL && part->script > 0 && part->script < (gint)G_N_ELEMENTS (languages)) { sel = languages[part->script]; if (*sel != '\0') { lua_pushstring (L, sel); diff --git a/src/main.c b/src/main.c index f043023a2..23c67912d 100644 --- a/src/main.c +++ b/src/main.c @@ -506,12 +506,12 @@ make_listen_key (struct in_addr *addr, gint port, gint family, gchar *path) if (family == AF_INET) { /* Make fnv hash from bytes of addr and port */ key = (gchar *)&addr->s_addr; - while (key - (gchar *)&addr->s_addr < sizeof (addr->s_addr)) { + while (key - (gchar *)&addr->s_addr < (gint)sizeof (addr->s_addr)) { res ^= (gchar)*key++; res += (res << 1) + (res << 4) + (res << 7) + (res << 8) + (res << 24); } key = (gchar *)&port; - while (key - (gchar *)&port < sizeof (addr->s_addr)) { + while (key - (gchar *)&port < (gint)sizeof (addr->s_addr)) { res ^= (gchar)*key++; res += (res << 1) + (res << 4) + (res << 7) + (res << 8) + (res << 24); } diff --git a/src/map.c b/src/map.c index ea047ba89..300f2eb83 100644 --- a/src/map.c +++ b/src/map.c @@ -103,7 +103,7 @@ write_http_request (struct rspamd_map *map, struct http_map_data *data, gint soc * FSM for parsing HTTP reply */ static gchar * -parse_http_reply (gchar * chunk, size_t len, struct http_reply *reply) +parse_http_reply (gchar * chunk, gint len, struct http_reply *reply) { gchar *s, *p, *err_str, *tmp; p = chunk; @@ -194,7 +194,7 @@ parse_http_reply (gchar * chunk, size_t len, struct http_reply *reply) * Read and parse chunked header */ static gint -read_chunk_header (gchar * buf, size_t len, struct http_map_data *data) +read_chunk_header (gchar * buf, gint len, struct http_map_data *data) { gchar chunkbuf[32], *p, *c, *err_str; gint skip = 0; @@ -202,7 +202,7 @@ read_chunk_header (gchar * buf, size_t len, struct http_map_data *data) p = chunkbuf; c = buf; /* Find hex digits */ - while (g_ascii_isxdigit (*c) && p - chunkbuf < sizeof (chunkbuf) - 1 && skip < len) { + while (g_ascii_isxdigit (*c) && p - chunkbuf < (gint)(sizeof (chunkbuf) - 1) && skip < len) { *p++ = *c++; skip++; } @@ -517,7 +517,7 @@ add_map (const gchar *map_line, map_cb_t read_callback, map_fin_cb_t fin_callbac hostend = p; i = 0; p++; - while (g_ascii_isdigit (*p) && i < sizeof (portbuf) - 1) { + while (g_ascii_isdigit (*p) && i < (gint)sizeof (portbuf) - 1) { portbuf[i++] = *p++; } if (*p != '/') { @@ -573,7 +573,7 @@ add_map (const gchar *map_line, map_cb_t read_callback, map_fin_cb_t fin_callbac * FSM for parsing lists */ gchar * -abstract_parse_kv_list (memory_pool_t * pool, gchar * chunk, size_t len, struct map_cb_data *data, insert_func func) +abstract_parse_kv_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data, insert_func func) { gchar *c, *p, *key = NULL, *value = NULL; @@ -665,7 +665,7 @@ abstract_parse_kv_list (memory_pool_t * pool, gchar * chunk, size_t len, struct } gchar * -abstract_parse_list (memory_pool_t * pool, gchar * chunk, size_t len, struct map_cb_data *data, insert_func func) +abstract_parse_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data, insert_func func) { gchar *s, *p, *str, *start; @@ -804,7 +804,7 @@ radix_tree_insert_helper (gpointer st, gconstpointer key, gpointer value) /* Helpers */ gchar * -read_host_list (memory_pool_t * pool, gchar * chunk, size_t len, struct map_cb_data *data) +read_host_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { if (data->cur_data == NULL) { data->cur_data = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); @@ -821,7 +821,7 @@ fin_host_list (memory_pool_t * pool, struct map_cb_data *data) } gchar * -read_kv_list (memory_pool_t * pool, gchar * chunk, size_t len, struct map_cb_data *data) +read_kv_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { if (data->cur_data == NULL) { data->cur_data = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); @@ -838,7 +838,7 @@ fin_kv_list (memory_pool_t * pool, struct map_cb_data *data) } gchar * -read_radix_list (memory_pool_t * pool, gchar * chunk, size_t len, struct map_cb_data *data) +read_radix_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { if (data->cur_data == NULL) { data->cur_data = radix_tree_create (); diff --git a/src/map.h b/src/map.h index ce4a257da..23e38a786 100644 --- a/src/map.h +++ b/src/map.h @@ -52,7 +52,7 @@ struct http_map_data { /** * Callback types */ -typedef gchar* (*map_cb_t)(memory_pool_t *pool, gchar *chunk, size_t len, struct map_cb_data *data); +typedef gchar* (*map_cb_t)(memory_pool_t *pool, gchar *chunk, gint len, struct map_cb_data *data); typedef void (*map_fin_cb_t)(memory_pool_t *pool, struct map_cb_data *data); /** @@ -97,24 +97,24 @@ typedef void (*insert_func) (gpointer st, gconstpointer key, /** * Radix list is a list like ip/mask */ -gchar* read_radix_list (memory_pool_t *pool, gchar *chunk, size_t len, struct map_cb_data *data); +gchar* read_radix_list (memory_pool_t *pool, gchar *chunk, gint len, struct map_cb_data *data); void fin_radix_list (memory_pool_t *pool, struct map_cb_data *data); /** * Host list is an ordinal list of hosts or domains */ -gchar* read_host_list (memory_pool_t *pool, gchar *chunk, size_t len, struct map_cb_data *data); +gchar* read_host_list (memory_pool_t *pool, gchar *chunk, gint len, struct map_cb_data *data); void fin_host_list (memory_pool_t *pool, struct map_cb_data *data); /** * Kv list is an ordinal list of keys and values separated by whitespace */ -gchar* read_kv_list (memory_pool_t *pool, gchar *chunk, size_t len, struct map_cb_data *data); +gchar* read_kv_list (memory_pool_t *pool, gchar *chunk, gint len, struct map_cb_data *data); void fin_kv_list (memory_pool_t *pool, struct map_cb_data *data); /** * FSM for lists parsing (support comments, blank lines and partial replies) */ -gchar * abstract_parse_list (memory_pool_t * pool, gchar * chunk, size_t len, struct map_cb_data *data, insert_func func); +gchar * abstract_parse_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data, insert_func func); #endif diff --git a/src/mem_pool.c b/src/mem_pool.c index 170aed854..252fa54f9 100644 --- a/src/mem_pool.c +++ b/src/mem_pool.c @@ -58,13 +58,10 @@ static memory_pool_stat_t *mem_pool_stat = NULL; * Function that return free space in pool page * @param x pool page struct */ -static gsize +static gint pool_chain_free (struct _pool_chain *chain) { - guint8 *p; - - p = align_ptr (chain->pos, MEM_ALIGNMENT); - return chain->len - (p - chain->begin); + return (gint)chain->len - (chain->pos - chain->begin + MEM_ALIGNMENT); } static struct _pool_chain * @@ -87,8 +84,8 @@ pool_chain_new (gsize size) abort (); } - chain->len = size; chain->pos = align_ptr (chain->begin, MEM_ALIGNMENT); + chain->len = size; chain->next = NULL; STAT_LOCK (); mem_pool_stat->bytes_allocated += size; @@ -129,9 +126,8 @@ pool_chain_new_shared (gsize size) #else # error No mmap methods are defined #endif - chain->len = size; - chain->pos = chain->begin; chain->pos = align_ptr (chain->begin, MEM_ALIGNMENT); + chain->len = size; chain->lock = NULL; chain->next = NULL; STAT_LOCK (); @@ -204,7 +200,7 @@ memory_pool_alloc (memory_pool_t * pool, gsize size) { guint8 *tmp; struct _pool_chain *new, *cur; - gsize free; + gint free; if (pool) { #ifdef MEMORY_GREEDY @@ -213,27 +209,29 @@ memory_pool_alloc (memory_pool_t * pool, gsize size) cur = pool->cur_pool; #endif /* Find free space in pool chain */ - while ((free = pool_chain_free (cur)) < size && cur->next) { + while ((free = pool_chain_free (cur)) < (gint)size && cur->next) { cur = cur->next; } - if (free < size && cur->next == NULL) { + if (free < (gint)size && cur->next == NULL) { /* Allocate new pool */ - if (cur->len >= size) { + if (cur->len >= size + MEM_ALIGNMENT) { new = pool_chain_new (cur->len); } else { mem_pool_stat->oversized_chunks++; - new = pool_chain_new (size + pool->first_pool->len); + new = pool_chain_new (size + pool->first_pool->len + MEM_ALIGNMENT); } /* Attach new pool to chain */ cur->next = new; pool->cur_pool = new; - new->pos += size; - - return new->begin; + /* No need to align again */ + tmp = new->pos; + new->pos = tmp + size; + return tmp; } tmp = align_ptr (cur->pos, MEM_ALIGNMENT); cur->pos = tmp + size; + g_assert (cur->pos - cur->begin <= (gint)cur->len); return tmp; } return NULL; @@ -315,6 +313,7 @@ memory_pool_alloc_shared (memory_pool_t * pool, gsize size) { guint8 *tmp; struct _pool_chain_shared *new, *cur; + gint free; if (pool) { g_return_val_if_fail (size > 0, NULL); @@ -326,17 +325,17 @@ memory_pool_alloc_shared (memory_pool_t * pool, gsize size) } /* Find free space in pool chain */ - while (pool_chain_free ((struct _pool_chain *)cur) < size && cur->next) { + while ((free = pool_chain_free ((struct _pool_chain *)cur)) < (gint)size && cur->next) { cur = cur->next; } - if (cur->next == NULL) { + if (free < (gint)size && cur->next == NULL) { /* Allocate new pool */ - if (cur->len >= size) { + if (cur->len >= size + MEM_ALIGNMENT) { new = pool_chain_new_shared (cur->len); } else { mem_pool_stat->oversized_chunks++; - new = pool_chain_new_shared (size + cur->len); + new = pool_chain_new_shared (size + pool->first_pool->len + MEM_ALIGNMENT); } /* Attach new pool to chain */ cur->next = new; diff --git a/src/memcached.c b/src/memcached.c index 135c7cb68..ac1d3a281 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -283,7 +283,7 @@ read_handler (gint fd, short what, memcached_ctx_t * ctx) return; } /* Check if we already have all data in buffer */ - if (r >= datalen + sizeof (END_TRAILER) + sizeof (CRLF) - 2) { + if (r >= (ssize_t)(datalen + sizeof (END_TRAILER) + sizeof (CRLF) - 2)) { /* Store all data in param's buffer */ memcpy (ctx->param->buf + ctx->param->bufpos, p, datalen); /* Increment count */ @@ -355,7 +355,7 @@ delete_handler (gint fd, short what, memcached_ctx_t * ctx) iov[1].iov_base = read_buf; iov[1].iov_len = r; ctx->param->bufpos = writev (ctx->sock, iov, 2); - if (ctx->param->bufpos == -1) { + if (ctx->param->bufpos == (size_t)-1) { memc_log (ctx, __LINE__, "memc_write: writev failed: %s", strerror (errno)); } } diff --git a/src/message.c b/src/message.c index 93c9fb622..a61784806 100644 --- a/src/message.c +++ b/src/message.c @@ -56,7 +56,7 @@ strip_html_tags (struct worker_task *task, memory_pool_t * pool, struct mime_tex end = src->data + src->len; br = 0; - while (i < src->len) { + while (i < (gint)src->len) { switch (c) { case '\0': break; @@ -233,7 +233,7 @@ unbreak_tag: break; } i++; - if (i < src->len) { + if (i < (gint)src->len) { c = *(++p); } } diff --git a/src/plugins/chartable.c b/src/plugins/chartable.c index cdf7e3e4e..6458b3e2d 100644 --- a/src/plugins/chartable.c +++ b/src/plugins/chartable.c @@ -146,7 +146,7 @@ check_part (struct mime_text_part *part, gboolean raw_mode) } scc = g_unichar_get_script (c); - if (scc < G_N_ELEMENTS (scripts)) { + if (scc < (gint)G_N_ELEMENTS (scripts)) { scripts[scc] ++; } p1 = g_utf8_next_char (p); diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 0e581e41f..622d169fa 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -84,13 +84,13 @@ struct fuzzy_ctx { gint servers_num; memory_pool_t *fuzzy_pool; double max_score; - gint32 min_hash_len; + guint32 min_hash_len; radix_tree_t *whitelist; GHashTable *mappings; GList *mime_types; - gint32 min_bytes; - gint32 min_height; - gint32 min_width; + guint32 min_bytes; + guint32 min_height; + guint32 min_width; guint32 io_timeout; }; @@ -240,7 +240,7 @@ parse_servers_string (gchar *str) if ((p = strchr (strvec[i], ':')) != NULL) { j = 0; p++; - while (g_ascii_isdigit (*(p + j)) && j < sizeof (portbuf) - 1) { + while (g_ascii_isdigit (*(p + j)) && j < (gint)sizeof (portbuf) - 1) { portbuf[j] = *(p + j); j++; } diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 644522d87..008d85f39 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -169,7 +169,7 @@ parse_regexp_ipmask (const gchar *begin, struct dynamic_map_item *addr) break; case 1: /* Begin parse ip */ - if (p - ip_buf >= sizeof (ip_buf) || dots > 3) { + if (p - ip_buf >= (gint)sizeof (ip_buf) || dots > 3) { return FALSE; } if (g_ascii_isdigit (*pos)) { @@ -254,10 +254,10 @@ read_regexp_expression (memory_pool_t * pool, struct regexp_module_item *chain, /* Callbacks for reading json dynamic rules */ gchar * -json_regexp_read_cb (memory_pool_t * pool, gchar * chunk, size_t len, struct map_cb_data *data) +json_regexp_read_cb (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { struct regexp_json_buf *jb; - size_t free, off; + gint free, off; if (data->cur_data == NULL) { jb = g_malloc (sizeof (struct regexp_json_buf)); @@ -297,7 +297,7 @@ void json_regexp_fin_cb (memory_pool_t * pool, struct map_cb_data *data) { struct regexp_json_buf *jb; - gint nelts, i, j; + guint nelts, i, j; json_t *js, *cur_elt, *cur_nm, *it_val; json_error_t je; gchar *cur_rule, *cur_symbol; diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 700c86ad1..d0a51d59b 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -105,7 +105,7 @@ exception_insert (gpointer st, gconstpointer key, gpointer value) } static gchar * -read_exceptions_list (memory_pool_t * pool, gchar * chunk, size_t len, struct map_cb_data *data) +read_exceptions_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { if (data->cur_data == NULL) { data->cur_data = memory_pool_alloc0 (pool, sizeof (GHashTable *) * MAX_LEVELS); @@ -179,7 +179,7 @@ redirector_item_free (gpointer p) } static gchar * -read_redirectors_list (memory_pool_t * pool, gchar * chunk, size_t len, struct map_cb_data *data) +read_redirectors_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { if (data->cur_data == NULL) { data->cur_data = g_hash_table_new_full (rspamd_strcase_hash, rspamd_strcase_equal, g_free, redirector_item_free); @@ -500,7 +500,7 @@ format_surbl_request (memory_pool_t * pool, f_str_t * hostname, struct suffix_it len = hostname->len + slen + 2; p = hostname->begin; - while (p - hostname->begin < hostname->len && dots_num < MAX_LEVELS) { + while (p - hostname->begin < (gint)hostname->len && dots_num < MAX_LEVELS) { if (*p == '.') { dots[dots_num] = p; dots_num ++; @@ -748,7 +748,7 @@ memcached_callback (memcached_ctx_t * ctx, memc_error_t error, void *data) else { url_count = (gint *)param->ctx->param->buf; /* Do not check DNS for urls that have count more than max_urls */ - if (*url_count > surbl_module_ctx->max_urls) { + if (*url_count > (gint)surbl_module_ctx->max_urls) { msg_info ("url '%s' has count %d, max: %d", struri (param->url), *url_count, surbl_module_ctx->max_urls); /* * XXX: try to understand why we should use memcached here diff --git a/src/protocol.c b/src/protocol.c index efce45f7a..84eb050c1 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -126,7 +126,7 @@ rspamc_proto_str (guint ver) static gchar * separate_command (f_str_t * in, gchar c) { - gint r = 0; + guint r = 0; gchar *p = in->begin, *b; b = p; diff --git a/src/settings.c b/src/settings.c index b5786d393..31cc95b1c 100644 --- a/src/settings.c +++ b/src/settings.c @@ -111,7 +111,7 @@ settings_unref (struct rspamd_settings *s) gchar * -json_read_cb (memory_pool_t * pool, gchar * chunk, size_t len, struct map_cb_data *data) +json_read_cb (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { struct json_buf *jb; size_t free, off; @@ -137,7 +137,7 @@ json_read_cb (memory_pool_t * pool, gchar * chunk, size_t len, struct map_cb_dat off = jb->pos - jb->buf; free = jb->buflen - off; - if (free < len) { + if ((gint)free < len) { jb->buflen = MAX (jb->buflen * 2, jb->buflen + len * 2); jb->buf = g_realloc (jb->buf, jb->buflen); jb->pos = jb->buf + off; @@ -415,12 +415,12 @@ check_setting (struct worker_task *task, struct rspamd_settings **user_settings, field ++; } len = strcspn (field, ">"); - rspamd_strlcpy (cmp_buf, field, MIN (sizeof (cmp_buf), len + 1)); + rspamd_strlcpy (cmp_buf, field, MIN ((gint)sizeof (cmp_buf), len + 1)); *user_settings = g_hash_table_lookup (task->cfg->user_settings, cmp_buf); } if (domain != NULL) { len = strcspn (domain, ">"); - rspamd_strlcpy (cmp_buf, domain, MIN (sizeof (cmp_buf), len + 1)); + rspamd_strlcpy (cmp_buf, domain, MIN ((gint)sizeof (cmp_buf), len + 1)); *domain_settings = g_hash_table_lookup (task->cfg->domain_settings, cmp_buf); } diff --git a/src/smtp.c b/src/smtp.c index c2fa22980..0c8b8d5aa 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -282,7 +282,7 @@ process_smtp_data (struct smtp_session *session) } /* Now mmap temp file if it is small enough */ session->temp_size = st.st_size; - if (session->ctx->max_size == 0 || st.st_size < session->ctx->max_size) { + if (session->ctx->max_size == 0 || st.st_size < (off_t)session->ctx->max_size) { session->task = construct_task (session->worker); session->task->resolver = session->resolver; session->task->fin_callback = smtp_write_socket; @@ -405,7 +405,7 @@ smtp_read_socket (f_str_t * in, void *arg) return process_smtp_data (session); } - if (write (session->temp_fd, in->begin, in->len) != in->len) { + if (write (session->temp_fd, in->begin, in->len) != (ssize_t)in->len) { msg_err ("cannot write to temp file: %s", strerror (errno)); session->error = SMTP_ERROR_FILE; session->state = SMTP_STATE_CRITICAL_ERROR; diff --git a/src/smtp_proto.c b/src/smtp_proto.c index 5a3ccebd8..d443a1fb3 100644 --- a/src/smtp_proto.c +++ b/src/smtp_proto.c @@ -62,7 +62,7 @@ parse_smtp_command (struct smtp_session *session, f_str_t *line, struct smtp_com SMTP_PARSE_DONE } state; gchar *p, *c, ch, cmd_buf[4]; - gint i; + guint i; f_str_t *arg = NULL; struct smtp_command *pcmd; @@ -202,7 +202,7 @@ end: static gboolean check_smtp_path (f_str_t *path) { - gint i; + guint i; gchar *p; p = path->begin; diff --git a/src/spf.c b/src/spf.c index c6498f69b..ef64551b7 100644 --- a/src/spf.c +++ b/src/spf.c @@ -227,7 +227,7 @@ parse_spf_ipmask (const gchar *begin, struct spf_addr *addr) break; case 1: /* Begin parse ip */ - if (p - ip_buf >= sizeof (ip_buf) || dots > 3) { + if (p - ip_buf >= (gint)sizeof (ip_buf) || dots > 3) { return FALSE; } if (g_ascii_isdigit (*pos)) { @@ -686,7 +686,7 @@ reverse_spf_ip (gchar *ip, gint len) gchar ipbuf[sizeof("255.255.255.255") - 1], *p, *c; gint t = 0, l = len; - if (len > sizeof (ipbuf)) { + if (len > (gint)sizeof (ipbuf)) { msg_info ("cannot reverse string of length %d", len); return; } diff --git a/src/statfile.c b/src/statfile.c index 215378749..efdb6ad56 100644 --- a/src/statfile.c +++ b/src/statfile.c @@ -265,7 +265,7 @@ statfile_pool_reindex (statfile_pool_t * pool, gchar *filename, size_t old_size, } pos = map + (sizeof (struct stat_file) - sizeof (struct stat_file_block)); - while (pos - map < old_size) { + while (pos - map < (gint)old_size) { block = (struct stat_file_block *)pos; if (block->hash1 != 0 && block->value != 0) { statfile_pool_set_block_common (pool, new, block->hash1, block->hash2, 0, block->value, FALSE); @@ -331,13 +331,13 @@ statfile_pool_open (statfile_pool_t * pool, gchar *filename, size_t size, gboole return NULL; } - if (!forced && st.st_size > pool->max) { + if (!forced && (gsize)st.st_size > pool->max) { msg_info ("cannot attach file to pool, too large: %Hz", (size_t) st.st_size); return NULL; } memory_pool_lock_mutex (pool->lock); - if (!forced && abs (st.st_size - size) > sizeof (struct stat_file)) { + if (!forced && abs (st.st_size - size) > (gint)sizeof (struct stat_file)) { memory_pool_unlock_mutex (pool->lock); msg_warn ("need to reindex statfile old size: %Hz, new size: %Hz", st.st_size, size); return statfile_pool_reindex (pool, filename, st.st_size, size); @@ -684,7 +684,7 @@ statfile_pool_set_section (statfile_pool_t * pool, stat_file_t * file, guint32 c else { cur_offset = file->seek_pos - sizeof (struct stat_file_section); } - while (cur_offset < file->len) { + while (cur_offset < (off_t)file->len) { sec = (struct stat_file_section *)((gchar *)file->map + cur_offset); if (sec->code == code) { file->cur_section.code = code; diff --git a/src/statfile_sync.c b/src/statfile_sync.c index 44e34454b..e96555c15 100644 --- a/src/statfile_sync.c +++ b/src/statfile_sync.c @@ -83,7 +83,7 @@ log_next_sync (const gchar *symbol, time_t delay) static gboolean parse_revision_line (struct rspamd_sync_ctx *ctx, f_str_t *in) { - gint i, state = 0; + guint i, state = 0; gchar *p, *c, numbuf[sizeof("18446744073709551615")]; guint64 *val; @@ -111,7 +111,7 @@ parse_revision_line (struct rspamd_sync_ctx *ctx, f_str_t *in) /* One more character */ p ++; } - rspamd_strlcpy (numbuf, c, MIN (p - c + 1, sizeof (numbuf))); + rspamd_strlcpy (numbuf, c, MIN (p - c + 1, (gint)sizeof (numbuf))); errno = 0; *val = strtoull (numbuf, NULL, 10); if (errno != 0) { @@ -147,7 +147,7 @@ static gboolean read_blocks (struct rspamd_sync_ctx *ctx, f_str_t *in) { struct rspamd_binlog_element *elt; - gint i; + guint i; statfile_pool_lock_file (ctx->pool, ctx->real_statfile); elt = (struct rspamd_binlog_element *)in->begin; diff --git a/src/symbols_cache.c b/src/symbols_cache.c index 1f4b90198..5940bb4c2 100644 --- a/src/symbols_cache.c +++ b/src/symbols_cache.c @@ -364,6 +364,7 @@ register_dynamic_symbol (memory_pool_t *dynamic_pool, struct symbols_cache **cac double *w; guint32 mask = 0xFFFFFFFF; struct dynamic_map_item *it; + gint rr; if (*cache == NULL) { pcache = g_new0 (struct symbols_cache, 1); @@ -412,19 +413,19 @@ register_dynamic_symbol (memory_pool_t *dynamic_pool, struct symbols_cache **cac t = g_list_prepend (t, item); /* Replace pointers in radix tree and in destructor function */ memory_pool_replace_destructor (dynamic_pool, (pool_destruct_func)g_list_free, (gpointer)r, t); - r = radix32tree_replace (pcache->negative_dynamic_map, ntohl (it->addr.s_addr), mask, (uintptr_t)t); - if (r == -1) { + rr = radix32tree_replace (pcache->negative_dynamic_map, ntohl (it->addr.s_addr), mask, (uintptr_t)t); + if (rr == -1) { msg_warn ("cannot replace ip to tree: %s, mask %X", inet_ntoa (it->addr), mask); } } else { t = g_list_prepend (NULL, item); memory_pool_add_destructor (dynamic_pool, (pool_destruct_func)g_list_free, t); - r = radix32tree_insert (pcache->negative_dynamic_map, ntohl (it->addr.s_addr), mask, (uintptr_t)t); - if (r == -1) { + rr = radix32tree_insert (pcache->negative_dynamic_map, ntohl (it->addr.s_addr), mask, (uintptr_t)t); + if (rr == -1) { msg_warn ("cannot insert ip to tree: %s, mask %X", inet_ntoa (it->addr), mask); } - else if (r == 1) { + else if (rr == 1) { msg_warn ("ip %s, mask %X, value already exists", inet_ntoa (it->addr), mask); } } @@ -437,19 +438,19 @@ register_dynamic_symbol (memory_pool_t *dynamic_pool, struct symbols_cache **cac t = g_list_prepend (t, item); /* Replace pointers in radix tree and in destructor function */ memory_pool_replace_destructor (dynamic_pool, (pool_destruct_func)g_list_free, (gpointer)r, t); - r = radix32tree_replace (pcache->dynamic_map, ntohl (it->addr.s_addr), mask, (uintptr_t)t); - if (r == -1) { + rr = radix32tree_replace (pcache->dynamic_map, ntohl (it->addr.s_addr), mask, (uintptr_t)t); + if (rr == -1) { msg_warn ("cannot replace ip to tree: %s, mask %X", inet_ntoa (it->addr), mask); } } else { t = g_list_prepend (NULL, item); memory_pool_add_destructor (dynamic_pool, (pool_destruct_func)g_list_free, t); - r = radix32tree_insert (pcache->dynamic_map, ntohl (it->addr.s_addr), mask, (uintptr_t)t); - if (r == -1) { + rr = radix32tree_insert (pcache->dynamic_map, ntohl (it->addr.s_addr), mask, (uintptr_t)t); + if (rr == -1) { msg_warn ("cannot insert ip to tree: %s, mask %X", inet_ntoa (it->addr), mask); } - else if (r == 1) { + else if (rr == 1) { msg_warn ("ip %s, mask %X, value already exists", inet_ntoa (it->addr), mask); } } diff --git a/src/tokenizers/tokenizers.c b/src/tokenizers/tokenizers.c index 051e5bc4e..902245e7d 100644 --- a/src/tokenizers/tokenizers.c +++ b/src/tokenizers/tokenizers.c @@ -79,7 +79,7 @@ const gchar t_delimiters[255] = { struct tokenizer * get_tokenizer (char *name) { - int i; + guint i; for (i = 0; i < sizeof (tokenizers) / sizeof (tokenizers[0]); i++) { if (strcmp (tokenizers[i].name, name) == 0) { diff --git a/src/trie.c b/src/trie.c index 21743d856..2a22fe6fa 100644 --- a/src/trie.c +++ b/src/trie.c @@ -54,7 +54,7 @@ rspamd_trie_create (gboolean icase) * Insert a single character as level of binary trie */ static struct rspamd_trie_state * -rspamd_trie_insert_char (rspamd_trie_t *trie, gint depth, struct rspamd_trie_state *q, gchar c) +rspamd_trie_insert_char (rspamd_trie_t *trie, guint depth, struct rspamd_trie_state *q, gchar c) { struct rspamd_trie_match *m; @@ -103,7 +103,7 @@ rspamd_trie_insert (rspamd_trie_t *trie, const gchar *pattern, gint pattern_id) const guchar *p = pattern; struct rspamd_trie_state *q, *q1, *r; struct rspamd_trie_match *m, *n; - gint i, depth = 0; + guint i, depth = 0; gchar c; /* Insert pattern to the trie */ diff --git a/src/upstream.c b/src/upstream.c index aaefd740f..d167c88ec 100644 --- a/src/upstream.c +++ b/src/upstream.c @@ -156,9 +156,9 @@ upstream_ok (struct upstream *up, time_t now) void revive_all_upstreams (void *ups, size_t members, size_t msize) { - gint i; - struct upstream *cur; - u_char *p; + guint i; + struct upstream *cur; + guchar *p; U_WLOCK (); p = ups; @@ -180,9 +180,9 @@ revive_all_upstreams (void *ups, size_t members, size_t msize) static gint rescan_upstreams (void *ups, size_t members, size_t msize, time_t now, time_t error_timeout, time_t revive_timeout, size_t max_errors) { - gint i, alive; + guint i, alive; struct upstream *cur; - u_char *p; + guchar *p; /* Recheck all upstreams */ p = ups; @@ -209,7 +209,7 @@ rescan_upstreams (void *ups, size_t members, size_t msize, time_t now, time_t er static struct upstream * get_upstream_by_number (void *ups, size_t members, size_t msize, gint selected) { - gint i; + guint i; u_char *p, *c; struct upstream *cur; @@ -231,7 +231,7 @@ get_upstream_by_number (void *ups, size_t members, size_t msize, gint selected) continue; } /* Return selected upstream */ - if (i == selected) { + if ((gint)i == selected) { U_UNLOCK (); return cur; } @@ -334,7 +334,7 @@ get_upstream_by_hash (void *ups, size_t members, size_t msize, time_t now, time_ struct upstream * get_upstream_round_robin (void *ups, size_t members, size_t msize, time_t now, time_t error_timeout, time_t revive_timeout, size_t max_errors) { - gint alive, max_weight, i; + guint alive, max_weight, i; struct upstream *cur, *selected = NULL; u_char *p; @@ -348,7 +348,7 @@ get_upstream_round_robin (void *ups, size_t members, size_t msize, time_t now, t for (i = 0; i < members; i++) { cur = (struct upstream *)p; if (!cur->dead) { - if (max_weight < cur->weight) { + if (max_weight < (guint)cur->weight) { max_weight = cur->weight; selected = cur; } @@ -383,7 +383,7 @@ get_upstream_round_robin (void *ups, size_t members, size_t msize, time_t now, t struct upstream * get_upstream_master_slave (void *ups, size_t members, size_t msize, time_t now, time_t error_timeout, time_t revive_timeout, size_t max_errors) { - gint alive, max_weight, i; + guint alive, max_weight, i; struct upstream *cur, *selected = NULL; u_char *p; @@ -427,7 +427,7 @@ upstream_ketama_add (struct upstream *up, gchar *up_key, size_t keylen, size_t k { guint32 h = 0; gchar tmp[4]; - gint i; + guint i; /* Allocate ketama points array */ if (up->ketama_points == NULL) { @@ -461,7 +461,7 @@ upstream_ketama_add (struct upstream *up, gchar *up_key, size_t keylen, size_t k struct upstream * get_upstream_by_hash_ketama (void *ups, size_t members, size_t msize, time_t now, time_t error_timeout, time_t revive_timeout, size_t max_errors, gchar *key, size_t keylen) { - gint alive, i; + guint alive, i; guint32 h = 0, step, middle, d, min_diff = UINT_MAX; gchar *p; struct upstream *cur = NULL, *nearest = NULL; @@ -485,7 +485,7 @@ get_upstream_by_hash_ketama (void *ups, size_t members, size_t msize, time_t now middle = step; while (step != 1) { d = cur->ketama_points[middle] - h; - if (abs (d) < min_diff) { + if (abs (d) < (gint)min_diff) { min_diff = abs (d); nearest = cur; } diff --git a/src/url.c b/src/url.c index 3ab8359a9..2d61e107d 100644 --- a/src/url.c +++ b/src/url.c @@ -216,7 +216,7 @@ check_uri_file (gchar *name) static gint url_init (void) { - gint i; + guint i; if (url_scanner == NULL) { url_scanner = g_malloc (sizeof (struct url_match_scanner)); url_scanner->matchers = matchers; @@ -918,7 +918,7 @@ url_file_end (const gchar *begin, const gchar *end, const gchar *pos, url_match_ { const gchar *p; gchar stop; - gint i; + guint i; p = pos + strlen (match->pattern); if (*p == '/') { @@ -964,9 +964,9 @@ url_web_end (const gchar *begin, const gchar *end, const gchar *pos, url_match_t { const gchar *p, *c; gchar open_brace = '\0', close_brace = '\0'; - gint i, brace_stack = 0; + gint brace_stack = 0; gboolean passwd = FALSE; - guint port; + guint port, i; p = pos + strlen (match->pattern); for (i = 0; i < G_N_ELEMENTS (url_braces) / 2; i += 2) { diff --git a/src/util.c b/src/util.c index 16ed43786..5ff70c9fd 100644 --- a/src/util.c +++ b/src/util.c @@ -897,7 +897,7 @@ fstr_strcase_hash (gconstpointer key) guint h = 0; p = f->begin; - while (p - f->begin < f->len) { + while (p - f->begin < (gint)f->len) { h = (h << 5) - h + g_tolower (*p); p++; } @@ -1347,12 +1347,12 @@ escape_braces_addr_fstr (memory_pool_t *pool, f_str_t *in) gchar *res, *orig, *p; orig = in->begin; - while ((g_ascii_isspace (*orig) || *orig == '<') && orig - in->begin < in->len) { + while ((g_ascii_isspace (*orig) || *orig == '<') && orig - in->begin < (gint)in->len) { orig ++; } p = orig; - while ((!g_ascii_isspace (*p) && *p != '>') && p - in->begin < in->len) { + while ((!g_ascii_isspace (*p) && *p != '>') && p - in->begin < (gint)in->len) { p ++; len ++; } diff --git a/src/view.c b/src/view.c index 24fbcf195..7b70a07ca 100644 --- a/src/view.c +++ b/src/view.c @@ -229,7 +229,7 @@ check_view_rcpt (struct rspamd_view *v, struct worker_task *task) cur = task->rcpt; while (cur) { if ((p = strchr (cur->data, '@')) != NULL) { - l = MIN (sizeof (rcpt_user) - 1, p - (gchar *)cur->data); + l = MIN ((gint)sizeof (rcpt_user) - 1, p - (gchar *)cur->data); memcpy (rcpt_user, cur->data, l); rcpt_user[l] = '\0'; /* First try to lookup in hashtable */ diff --git a/src/worker.c b/src/worker.c index 16e33ed9e..538218d14 100644 --- a/src/worker.c +++ b/src/worker.c @@ -566,7 +566,7 @@ load_custom_filters (struct rspamd_worker *worker, const gchar * path) return FALSE; } - for (i = 0; i < gp.gl_pathc; i++) { + for (i = 0; i < (gint)gp.gl_pathc; i++) { if (!load_custom_filter (worker->srv->cfg, gp.gl_pathv[i], ctx)) { globfree (&gp); return FALSE; -- 2.39.5