]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
coverity: deadcode and unsigned comparison with 0 warnings
authorPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 28 Nov 2023 08:03:22 +0000 (09:03 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 28 Nov 2023 08:03:22 +0000 (09:03 +0100)
VEX/priv/guest_x86_helpers.c
coregrind/m_transtab.c
coregrind/vgdb.c
drd/drd_pthread_intercepts.c
helgrind/hg_wordset.c

index 1764f58f0ba12fb19fafc7b02c12eea025cc41ef..0c0c1ad2c86535eb5b09eb9738ed3e47176a6dbd 100644 (file)
@@ -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)
index 9794713069767f9fda0a5f95a994caae6eb5905a..b4b44b7a37f99dc76c57e66187cd94f8a6e531a9 100644 (file)
@@ -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])
index 40292bab237fe7c24948a4294010c0a3fc36faeb..dce85b5c960160ff63ab2df5eb0539a106053f77 100644 (file)
@@ -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];
index b1b4762d633b9d4a1263c83392dce47342259ed1..806aee74aa3ea79919b0bd03b3be5449aef760b3 100644 (file)
@@ -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)
index 5d8a51a132d361ecaccc3c955effc47b1db85baf..ac4a700191643138b6941f3902b232b474539ed0 100644 (file)
@@ -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. */