From 09718fb9b3d27e87e2a51730c4618de2e7d2c023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Thu, 17 Nov 2022 00:04:39 +0000 Subject: [PATCH] CMake: Move clang warnings Move clang warnings to normal set. Let the CMake compatibility check control the warning. Fix or work-around -Wunreachable warnings in the code. --- CMakeLists.txt | 19 ++++++++----------- epan/dissectors/packet-ipsec.c | 3 +-- epan/dissectors/packet-mac-nr.c | 8 ++++---- epan/dissectors/packet-sftp.c | 4 +--- epan/dtd_grammar.lemon | 4 ++++ epan/proto.c | 20 ++++++++++---------- epan/protobuf_lang_parser.lemon | 4 ++++ plugins/epan/mate/mate_grammar.lemon | 3 +++ ui/qt/conversation_hash_tables_dialog.cpp | 2 +- wiretap/ascend_parser.lemon | 3 +++ 10 files changed, 39 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 858baca93b..01a6792d57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -645,6 +645,8 @@ else() # ! MSVC -Wcomma # Clang-only -Wshorten-64-to-32 # Clang-only -Wredundant-decls + -Wunreachable-code # Clang-only + -Wdocumentation # Clang-only # # Disable errors unconditionally for some static analysis warnings # that are dormant at lower optimizations levels and also @@ -771,18 +773,13 @@ else() # ! MSVC # -Wcast-align # - # Works only with Clang + # Doesn't warn of interesting issues. Usually the + # duplicated branches are protocol constants that + # happen to be equal and are relevant for documentation + # and readability and are trivially optimized by the + # compiler. # - -Wunreachable-code - # - # Works only with Clang but generates a lot of warnings - # (about glib library not using Doxygen) - # - -Wdocumentation - # - # Works only with GCC 7 - # - -Wduplicated-branches + -Wduplicated-branches # GCC-only # # No longer supported by El Capitan clang on C++ # XXX - is this one of those where CMake's check diff --git a/epan/dissectors/packet-ipsec.c b/epan/dissectors/packet-ipsec.c index 01745bd089..7a8667b142 100644 --- a/epan/dissectors/packet-ipsec.c +++ b/epan/dissectors/packet-ipsec.c @@ -2134,10 +2134,9 @@ dissect_esp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) if (err) { + gcry_cipher_close(*cipher_hd); REPORT_DISSECTOR_BUG(" Error in Algorithm %s, Mode %d, gcry_cipher_decrypt failed: %s\n", gcry_cipher_algo_name(crypt_algo_libgcrypt), crypt_mode_libgcrypt, gcry_strerror(err)); - gcry_cipher_close(*cipher_hd); - decrypt_ok = FALSE; } else { diff --git a/epan/dissectors/packet-mac-nr.c b/epan/dissectors/packet-mac-nr.c index 1c9b445ee0..b31ba2e835 100644 --- a/epan/dissectors/packet-mac-nr.c +++ b/epan/dissectors/packet-mac-nr.c @@ -1308,10 +1308,10 @@ static void dissect_rar(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, write_pdu_label_and_info(pdu_ti, subheader_ti, pinfo, "(RAPID=%u TA=%u Temp C-RNTI=%u) ", rapid, ta, c_rnti); } - else { - write_pdu_label_and_info(pdu_ti, subheader_ti, pinfo, - "(RAPID=%u) ", rapid); - } + //else { + // write_pdu_label_and_info(pdu_ti, subheader_ti, pinfo, + // "(RAPID=%u) ", rapid); + //} } /* Set subheader (+subpdu..) length */ proto_item_set_end(subheader_ti, tvb, offset); diff --git a/epan/dissectors/packet-sftp.c b/epan/dissectors/packet-sftp.c index bae6653000..c513100b6a 100644 --- a/epan/dissectors/packet-sftp.c +++ b/epan/dissectors/packet-sftp.c @@ -484,7 +484,7 @@ static int dissect_sftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi return offset; } -static int dissect_sftp_attrs(tvbuff_t *packet_tvb, packet_info *pinfo, +static int dissect_sftp_attrs(tvbuff_t *packet_tvb, packet_info *pinfo _U_, int offset, proto_item *msg_type_tree) { wmem_strbuf_t *title = wmem_strbuf_new(wmem_packet_scope(), "SFTP attributes"); @@ -527,8 +527,6 @@ static int dissect_sftp_attrs(tvbuff_t *packet_tvb, packet_info *pinfo, proto_item_set_len(sftp_attrs_tree, offset - offset0); return offset - offset0; - -(void)pinfo; } void diff --git a/epan/dtd_grammar.lemon b/epan/dtd_grammar.lemon index 342d7f1772..58f9c7ff0c 100644 --- a/epan/dtd_grammar.lemon +++ b/epan/dtd_grammar.lemon @@ -18,9 +18,13 @@ #include #include #include +#include #include "dtd.h" #include "dtd_parse.h" +/* Generated lemon code warns on this. */ +DIAG_OFF(unreachable-code) + static dtd_named_list_t* dtd_named_list_new(gchar* name, GPtrArray* list) { dtd_named_list_t* nl = g_new(dtd_named_list_t,1); diff --git a/epan/proto.c b/epan/proto.c index ab1473ea7e..43f43c7344 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -8668,7 +8668,7 @@ tmp_fld_check_assert(header_field_info *hfinfo) " but is being displayed as %s", hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type), tmp_str); - wmem_free(NULL, tmp_str); + //wmem_free(NULL, tmp_str); } if (hfinfo->display & BASE_UNIT_STRING) { REPORT_DISSECTOR_BUG("Field '%s' (%s) is a character value (%s) but has a unit string", @@ -8698,7 +8698,7 @@ tmp_fld_check_assert(header_field_info *hfinfo) REPORT_DISSECTOR_BUG("Field '%s' (%s) is signed (%s) but is being displayed unsigned (%s)", hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type), tmp_str); - wmem_free(NULL, tmp_str); + //wmem_free(NULL, tmp_str); } /* FALL THROUGH */ case FT_UINT8: @@ -8792,7 +8792,7 @@ tmp_fld_check_assert(header_field_info *hfinfo) " but is being displayed as %s", hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type), tmp_str); - wmem_free(NULL, tmp_str); + //wmem_free(NULL, tmp_str); } break; case FT_BYTES: @@ -8811,7 +8811,7 @@ tmp_fld_check_assert(header_field_info *hfinfo) tmp_str = val_to_str_wmem(NULL, hfinfo->display, hf_display, "(Bit count: %d)"); REPORT_DISSECTOR_BUG("Field '%s' (%s) is an byte array but is being displayed as %s instead of BASE_NONE, SEP_DOT, SEP_DASH, SEP_COLON, or SEP_SPACE", hfinfo->name, hfinfo->abbrev, tmp_str); - wmem_free(NULL, tmp_str); + //wmem_free(NULL, tmp_str); } if (hfinfo->bitmask != 0) REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a bitmask", @@ -8831,7 +8831,7 @@ tmp_fld_check_assert(header_field_info *hfinfo) REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE", hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type), tmp_str); - wmem_free(NULL, tmp_str); + //wmem_free(NULL, tmp_str); } if (hfinfo->bitmask != 0) REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a bitmask", @@ -8850,7 +8850,7 @@ tmp_fld_check_assert(header_field_info *hfinfo) tmp_str = val_to_str_wmem(NULL, hfinfo->display, hf_display, "(Bit count: %d)"); REPORT_DISSECTOR_BUG("Field '%s' (%s) is a %s but is being displayed as %s instead of as a time", hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type), tmp_str); - wmem_free(NULL, tmp_str); + //wmem_free(NULL, tmp_str); } if (hfinfo->bitmask != 0) REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a bitmask", @@ -8874,7 +8874,7 @@ tmp_fld_check_assert(header_field_info *hfinfo) " but is being displayed as %s", hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type), tmp_str); - wmem_free(NULL, tmp_str); + //wmem_free(NULL, tmp_str); } if (hfinfo->bitmask != 0) @@ -8899,7 +8899,7 @@ tmp_fld_check_assert(header_field_info *hfinfo) " but is being displayed as %s", hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type), tmp_str); - wmem_free(NULL, tmp_str); + //wmem_free(NULL, tmp_str); break; } break; @@ -8918,7 +8918,7 @@ tmp_fld_check_assert(header_field_info *hfinfo) " but is being displayed as %s", hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type), tmp_str); - wmem_free(NULL, tmp_str); + //wmem_free(NULL, tmp_str); } if (hfinfo->bitmask != 0) REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a bitmask", @@ -8936,7 +8936,7 @@ tmp_fld_check_assert(header_field_info *hfinfo) hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type), tmp_str); - wmem_free(NULL, tmp_str); + //wmem_free(NULL, tmp_str); } if (hfinfo->bitmask != 0) REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a bitmask", diff --git a/epan/protobuf_lang_parser.lemon b/epan/protobuf_lang_parser.lemon index 936527cf88..11034febff 100644 --- a/epan/protobuf_lang_parser.lemon +++ b/epan/protobuf_lang_parser.lemon @@ -24,11 +24,15 @@ #include #include #include +#include #include #include "protobuf_lang_tree.h" #include "protobuf_lang_parser.h" #include "protobuf_lang_scanner_lex.h" +/* Generated lemon code warns on this. */ +DIAG_OFF(unreachable-code) + #define NAME_TO_BE_SET "" #define NEED_NOT_NAME "" diff --git a/plugins/epan/mate/mate_grammar.lemon b/plugins/epan/mate/mate_grammar.lemon index 1a95b4db2c..802c6b8dab 100644 --- a/plugins/epan/mate/mate_grammar.lemon +++ b/plugins/epan/mate/mate_grammar.lemon @@ -26,6 +26,9 @@ #include #include +/* Generated lemon code warns on this. */ +DIAG_OFF(unreachable-code) + #define DUMMY void* typedef struct _extraction { diff --git a/ui/qt/conversation_hash_tables_dialog.cpp b/ui/qt/conversation_hash_tables_dialog.cpp index 1e0de6b01d..d36907a7dc 100644 --- a/ui/qt/conversation_hash_tables_dialog.cpp +++ b/ui/qt/conversation_hash_tables_dialog.cpp @@ -62,9 +62,9 @@ fill_named_table(gpointer key, gpointer value _U_, gpointer user_data) } html_table->append(QString("%1").arg(title)); } +title_done: html_table->append("\n"); } -title_done: html_table->append(""); diff --git a/wiretap/ascend_parser.lemon b/wiretap/ascend_parser.lemon index 08c77fea1a..f9192f210a 100644 --- a/wiretap/ascend_parser.lemon +++ b/wiretap/ascend_parser.lemon @@ -140,6 +140,9 @@ static void AscendParserFree(void *p, void (*freeProc)(void*)); #define ascend_debug(...) #endif +/* Generated lemon code warns on this. */ +DIAG_OFF(unreachable-code) + } // %include %name AscendParser