From d20a5986f4c99ce582232bec4272b729dfbff7a5 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 9 May 2019 19:52:51 +0300 Subject: [PATCH] global: Add asserts to make static analyzers happy --- src/lib-auth/auth-master.c | 1 + src/lib-imap-storage/imap-msgpart.c | 2 ++ src/lib-mail/istream-binary-converter.c | 2 ++ src/lib/istream-crlf.c | 1 + src/plugins/fts-lucene/lucene-wrapper.cc | 4 +++- 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib-auth/auth-master.c b/src/lib-auth/auth-master.c index 753df511b3..ac43712960 100644 --- a/src/lib-auth/auth-master.c +++ b/src/lib-auth/auth-master.c @@ -289,6 +289,7 @@ static bool auth_lookup_reply_callback(const char *cmd, const char *const *args, ctx->return_value = parse_reply(ctx, cmd, args); len = str_array_length(args); + i_assert(*args != NULL || len == 0); /* for static analyzer */ if (ctx->return_value >= 0) { ctx->fields = p_new(ctx->pool, const char *, len + 1); for (i = 0; i < len; i++) diff --git a/src/lib-imap-storage/imap-msgpart.c b/src/lib-imap-storage/imap-msgpart.c index 9ee93895e5..5ad5954d89 100644 --- a/src/lib-imap-storage/imap-msgpart.c +++ b/src/lib-imap-storage/imap-msgpart.c @@ -579,6 +579,8 @@ imap_msgpart_open_normal(struct mail *mail, struct imap_msgpart *msgpart, if (*msgpart->section_number != '\0') { /* find the MIME part */ + i_assert(part != NULL); + if (mail_get_stream_because(mail, NULL, NULL, "MIME part", &input) < 0) return -1; diff --git a/src/lib-mail/istream-binary-converter.c b/src/lib-mail/istream-binary-converter.c index 953e815d59..201a588152 100644 --- a/src/lib-mail/istream-binary-converter.c +++ b/src/lib-mail/istream-binary-converter.c @@ -43,6 +43,8 @@ stream_finish_convert_decision(struct binary_converter_istream *bstream) buffer_t *buf = bstream->hdr_buf; const unsigned char *data; + i_assert(bstream->convert_part != NULL); + bstream->hdr_buf = NULL; if (!part_can_convert(bstream->convert_part)) { bstream->convert_part = NULL; diff --git a/src/lib/istream-crlf.c b/src/lib/istream-crlf.c index 150195a013..6e07bb31aa 100644 --- a/src/lib/istream-crlf.c +++ b/src/lib/istream-crlf.c @@ -68,6 +68,7 @@ static ssize_t i_stream_crlf_read_crlf(struct istream_private *stream) } while (dest < dest_end) { + i_assert(src <= src_end); ptr = memchr(src, '\n', src_end - src); if (ptr == NULL) ptr = src_end; diff --git a/src/plugins/fts-lucene/lucene-wrapper.cc b/src/plugins/fts-lucene/lucene-wrapper.cc index 38b2fc78c2..4e12a4402e 100644 --- a/src/plugins/fts-lucene/lucene-wrapper.cc +++ b/src/plugins/fts-lucene/lucene-wrapper.cc @@ -1177,8 +1177,10 @@ lucene_get_query_str(struct lucene_index *index, wvalue = t_lucene_utf8_to_tchar(index, str); analyzer = guess_analyzer(index, str, strlen(str)); - if (analyzer == NULL) + if (analyzer == NULL) { analyzer = index->default_analyzer; + i_assert(analyzer != NULL); + } return getFieldQuery(analyzer, key, wvalue, fuzzy); } -- 2.47.3