From: Paul Floyd Date: Tue, 28 Nov 2023 08:03:22 +0000 (+0100) Subject: coverity: deadcode and unsigned comparison with 0 warnings X-Git-Tag: VALGRIND_3_23_0~234 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b0d87cc46d7cd85f164ff2e032672d56fad69d87;p=thirdparty%2Fvalgrind.git coverity: deadcode and unsigned comparison with 0 warnings --- diff --git a/VEX/priv/guest_x86_helpers.c b/VEX/priv/guest_x86_helpers.c index 1764f58f0b..0c0c1ad2c8 100644 --- a/VEX/priv/guest_x86_helpers.c +++ b/VEX/priv/guest_x86_helpers.c @@ -2799,10 +2799,13 @@ ULong x86g_use_seg_selector ( HWord ldt, HWord gdt, /* If this isn't true, we're in Big Trouble. */ vassert(8 == sizeof(VexGuestX86SegDescr)); - if (verboze) + if (verboze) { + // Coverity is right but this is unimportant + // coverity[DEADCODE:FALSE] vex_printf("x86h_use_seg_selector: " "seg_selector = 0x%x, vaddr = 0x%x\n", seg_selector, virtual_addr); + } /* Check for wildly invalid selector. */ if (seg_selector & ~0xFFFF) diff --git a/coregrind/m_transtab.c b/coregrind/m_transtab.c index 9794713069..b4b44b7a37 100644 --- a/coregrind/m_transtab.c +++ b/coregrind/m_transtab.c @@ -1303,7 +1303,7 @@ static Bool sanity_check_eclasses_in_sector ( const Sector* sec ) for (j = 0; j < tteC->n_tte2ec; j++) { ec_num = tteC->tte2ec_ec[j]; - if (ec_num < 0 || ec_num >= ECLASS_N) + if (ec_num >= ECLASS_N) BAD("tteC->tte2ec_ec[..] out of range"); ec_idx = tteC->tte2ec_ix[j]; if (ec_idx < 0 || ec_idx >= sec->ec2tte_used[ec_num]) diff --git a/coregrind/vgdb.c b/coregrind/vgdb.c index 40292bab23..dce85b5c96 100644 --- a/coregrind/vgdb.c +++ b/coregrind/vgdb.c @@ -82,7 +82,7 @@ char timestamp_out[20]; static char *vgdb_prefix = NULL; static char *valgrind_path = NULL; static char **vargs; -static char cvargs = 0; +static int cvargs = 0; char *timestamp_str (Bool produce) { @@ -2294,7 +2294,7 @@ void parse_options(int argc, char** argv, // argc - i is the number of left over arguments // allocate enough space, put all args in it. cvargs = argc - i - 1; - vargs = vmalloc (cvargs * sizeof(vargs)); + vargs = vmalloc (cvargs * sizeof(*vargs)); i++; for (int j = 0; i < argc; i++) { vargs[j] = argv[i]; diff --git a/drd/drd_pthread_intercepts.c b/drd/drd_pthread_intercepts.c index b1b4762d63..806aee74aa 100644 --- a/drd/drd_pthread_intercepts.c +++ b/drd/drd_pthread_intercepts.c @@ -360,25 +360,28 @@ static MutexT DRD_(pthread_to_drd_mutex_type)(int kind) kind &= PTHREAD_MUTEX_RECURSIVE | PTHREAD_MUTEX_ERRORCHECK | PTHREAD_MUTEX_NORMAL | PTHREAD_MUTEX_DEFAULT; - if (kind == PTHREAD_MUTEX_RECURSIVE) + if (kind == PTHREAD_MUTEX_RECURSIVE) { return mutex_type_recursive_mutex; - else if (kind == PTHREAD_MUTEX_ERRORCHECK) + } + if (kind == PTHREAD_MUTEX_ERRORCHECK) { return mutex_type_errorcheck_mutex; - else if (kind == PTHREAD_MUTEX_NORMAL) + } + if (kind == PTHREAD_MUTEX_NORMAL) { return mutex_type_default_mutex; - else if (kind == PTHREAD_MUTEX_DEFAULT) - // @todo PJF what about Solaris? -#if defined(VGO_freebsd) - return mutex_type_errorcheck_mutex; -#else + } + if (kind == PTHREAD_MUTEX_DEFAULT) { + // On FreeBSD PTHREAD_MUTEX_DEFAULT is the same as PTHREAD_MUTEX_ERRORCHECK + // so this code is unreachable, but that's not true for all platforms + // so just ignore the warning + // coverity[DEADCODE:FALSE] return mutex_type_default_mutex; -#endif + } #if defined(HAVE_PTHREAD_MUTEX_ADAPTIVE_NP) - else if (kind == PTHREAD_MUTEX_ADAPTIVE_NP) + if (kind == PTHREAD_MUTEX_ADAPTIVE_NP) { return mutex_type_default_mutex; + } #endif - else - return mutex_type_invalid_mutex; + return mutex_type_invalid_mutex; } #if defined(VGO_solaris) diff --git a/helgrind/hg_wordset.c b/helgrind/hg_wordset.c index 5d8a51a132..ac4a700191 100644 --- a/helgrind/hg_wordset.c +++ b/helgrind/hg_wordset.c @@ -498,7 +498,7 @@ Bool HG_(saneWS_SLOW) ( WordSetU* wsu, WordSet ws ) WordVec* wv; UWord i; if (wsu == NULL) return False; - if (ws < 0 || ws >= wsu->ix2vec_used) + if (ws >= wsu->ix2vec_used) return False; wv = do_ix2vec( wsu, ws ); /* can never happen .. do_ix2vec will assert instead. Oh well. */