]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
coverity: most of the remaining unsigned comparisons >= 0 warnings
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 8 Oct 2023 07:21:12 +0000 (09:21 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 8 Oct 2023 07:21:12 +0000 (09:21 +0200)
18 files changed:
VEX/priv/guest_arm64_toIR.c
VEX/priv/guest_arm_toIR.c
VEX/priv/guest_ppc_helpers.c
VEX/priv/guest_ppc_toIR.c
VEX/priv/host_arm64_isel.c
VEX/priv/host_generic_reg_alloc2.c
VEX/priv/ir_opt.c
auxprogs/valgrind-di-server.c
cachegrind/cg_arch.c
callgrind/main.c
coregrind/m_debuginfo/d3basics.c
coregrind/m_debuginfo/image.c
coregrind/m_execontext.c
coregrind/m_transtab.c
helgrind/hg_main.c
helgrind/hg_wordset.c
helgrind/libhb_core.c
memcheck/mc_main.c

index e6aaf896c91ba7bf304dfe1dd856e20cbc000d11..577751437917e5daf412a22f0156fb40e147e201 100644 (file)
@@ -10377,7 +10377,7 @@ Bool dis_AdvSIMD_scalar_shift_by_imm(/*MB_OUT*/DisResult* dres, UInt insn)
       UInt shift = 0;
       Bool ok    = getLaneInfo_IMMH_IMMB(&shift, &size, immh, immb);
       if (!ok) return False;
-      vassert(size >= 0 && size <= 3);
+      vassert(size <= 3);
       /* The shift encoding has opposite sign for the leftwards case.
          Adjust shift to compensate. */
       UInt lanebits = 8 << size;
@@ -11774,7 +11774,7 @@ Bool dis_AdvSIMD_shift_by_immediate(/*MB_OUT*/DisResult* dres, UInt insn)
       Bool isQ   = bitQ == 1;
       Bool ok    = getLaneInfo_IMMH_IMMB(&shift, &size, immh, immb);
       if (!ok || (bitQ == 0 && size == X11)) return False;
-      vassert(size >= 0 && size <= 3);
+      vassert(size <= 3);
       UInt lanebits = 8 << size;
       vassert(shift >= 1 && shift <= lanebits);
       IRExpr* src = getQReg128(nn);
index 58d4ed6b1e5a19065944d6a0500541dc47bd0345..12acfbc865e72cc61d1cf49465d5dcaabe1b626f 100644 (file)
@@ -12797,7 +12797,7 @@ static Bool decode_V8_instruction (
         const HChar* iNames[4]
            = { "aese", "aesd", "aesmc", "aesimc" };
 
-        vassert(opc >= 0 && opc <= 3);
+        vassert(opc <= 3);
         void*        helper = helpers[opc];
         const HChar* hname  = hNames[opc];
 
index 1a8e9fbf716d9ff58e7a30d4d4bb1be307dfb7a0..2611e52107e43670dd50e093c24cc511907afa9a 100644 (file)
@@ -1545,8 +1545,8 @@ void get_ACC_entry (VexGuestPPC64State* gst, UInt offset, UInt acc, UInt reg,
    acc_word[1] = 0xBAD;
    acc_word[0] = 0xBEEF;
 
-   vassert( (acc >= 0) && (acc < 8) );
-   vassert( (reg >= 0) && (reg < 4) );
+   vassert(acc < 8);
+   vassert(reg < 4);
 
    pU128_src = (U128*) (((UChar*)gst) + offset + acc*4*sizeof(U128)
                         + reg*sizeof(U128));
index f0c6ea85645aec6bb48cc607ad7bb2229d1f61e8..d05cce394d88bdd7ed15f66167c19090b4644ba2 100644 (file)
@@ -5917,7 +5917,7 @@ static void vector_gen_pvc_mask ( const VexAbiInfo* vbi,
 
    IRDirty* d;
 
-   vassert( (VSX_addr >= 0) && (VSX_addr < 64) );
+   vassert(VSX_addr < 64);
    UInt reg_offset = offsetofPPCGuestState( guest_VSR0 )
       + sizeof(U128) * VSX_addr;
 
index 4b75a0867296916b33f96cf4fcab405f5b23feab..b4b7d802119e74f48a121e9eea92693aa356090b 100644 (file)
@@ -119,7 +119,6 @@ static HReg lookupIRTemp ( ISelEnv* env, IRTemp tmp )
 static void lookupIRTempPair ( HReg* vrHI, HReg* vrLO, 
                                ISelEnv* env, IRTemp tmp )
 {
-   vassert(tmp >= 0);
    vassert(tmp < env->n_vregmap);
    vassert(! hregIsInvalid(env->vregmapHI[tmp]));
    *vrLO = env->vregmap[tmp];
index ceea1f4d61aad76fc6b694ef5300ad7045f111da..d94d2c92a72831103d7861369234b1c1875984e6 100644 (file)
@@ -137,6 +137,7 @@ typedef
 #define INVALID_RREG_NO ((Short)(-1))
 
 #define IS_VALID_VREGNO(_zz) ((_zz) >= 0 && (_zz) < n_vregs)
+#define IS_VALID_UNSIGNED_VREGNO(_zz) ((_zz) < n_vregs)
 #define IS_VALID_RREGNO(_zz) ((_zz) >= 0 && (_zz) < n_rregs)
 
 
@@ -1055,8 +1056,8 @@ HInstrArray* doRegisterAllocation_v2 (
          /* Finally, we can do the coalescing.  It's trivial -- merely
             claim vregS's register for vregD. */
          rreg_state[n].vreg = vregD;
-         vassert(IS_VALID_VREGNO(hregIndex(vregD)));
-         vassert(IS_VALID_VREGNO(hregIndex(vregS)));
+         vassert(IS_VALID_UNSIGNED_VREGNO(hregIndex(vregD)));
+         vassert(IS_VALID_UNSIGNED_VREGNO(hregIndex(vregS)));
          vreg_state[hregIndex(vregD)] = toShort(n);
          vreg_state[hregIndex(vregS)] = INVALID_RREG_NO;
 
@@ -1080,7 +1081,7 @@ HInstrArray* doRegisterAllocation_v2 (
          if (rreg_state[j].disp != Bound)
             continue;
          UInt vregno = hregIndex(rreg_state[j].vreg);
-         vassert(IS_VALID_VREGNO(vregno));
+         vassert(IS_VALID_UNSIGNED_VREGNO(vregno));
          if (vreg_lrs[vregno].dead_before <= ii) {
             rreg_state[j].disp = Free;
             rreg_state[j].eq_spill_slot = False;
index 93dd6188ef3d8b4708dea55d0436fc3dcb4cc271..f918e9f8584386f415e93ec158b28bcceb93b4bc 100644 (file)
@@ -6371,7 +6371,7 @@ static Bool do_XOR_TRANSFORM_IRSB ( IRSB* sb )
       if (st->tag != Ist_WrTmp)
          continue;
       IRTemp t = st->Ist.WrTmp.tmp;
-      vassert(t >= 0 && t < n_tmps);
+      vassert(t < n_tmps);
       env[t] = st->Ist.WrTmp.data;
    }
 
index 028948db04c1df25d6865e34c73e78ae05258d35..1b6506e3da61dc147cd2cec4a99b147d45b99298 100644 (file)
@@ -650,7 +650,7 @@ static UInt calc_gnu_debuglink_crc32(/*OUT*/Bool* ok, int fd, ULong size)
       ULong img_szB  = size;
       ULong curr_off = 0;
       while (1) {
-         assert(curr_off >= 0 && curr_off <= img_szB);
+         assert(curr_off <= img_szB);
          if (curr_off == img_szB) break;
          ULong avail = img_szB - curr_off;
          assert(avail > 0 && avail <= img_szB);
index dac22feb2af04e5630f6b410a4a7628e3cd152ed..68314c9dbebd9274e08230dc119d752433dcf6b8 100644 (file)
@@ -306,7 +306,7 @@ void VG_(post_clo_init_configure_caches)(cache_t* I1c,
    check_cache_or_override ("LL", LLc, DEFINED(clo_LLc));
 
    // Then replace with any defined on the command line.  (Already checked in
-   // VG(parse_clo_cache_opt)().)
+   // VG(str_clo_cache_opt)().)
    if (DEFINED(clo_I1c)) { *I1c = *clo_I1c; }
    if (DEFINED(clo_D1c)) { *D1c = *clo_D1c; }
    if (DEFINED(clo_LLc)) { *LLc = *clo_LLc; }
index 0c2467a90fb1c05677eb74c23d80a1cc793bcc7b..4a14d5fe265160ae8bb47afca4806ef28a5d383e 100644 (file)
@@ -777,7 +777,6 @@ static
 InstrInfo* next_InstrInfo ( ClgState* clgs, UInt instr_size )
 {
    InstrInfo* ii;
-   tl_assert(clgs->ii_index >= 0);
    tl_assert(clgs->ii_index < clgs->bb->instr_count);
    ii = &clgs->bb->instr[ clgs->ii_index ];
 
index e9e8944af8d62f8a553c758ab91f77187f1f3f78..bcfd456151745f615b7d3c124f63326195e9d317 100644 (file)
@@ -648,7 +648,6 @@ GXResult ML_(evaluate_Dwarf3_Expr) ( const UChar* expr, UWord exprszB,
 
    sp = -1;
    vg_assert(expr);
-   vg_assert(exprszB >= 0);
    limit = expr + exprszB;
 
    /* Deal with the case where the entire expression is a single
index ede83573093d3da3bdd1d1a218f848682900b26b..02e5090713ddc25d7beaa03de6ebe80747a3af25 100644 (file)
@@ -775,7 +775,7 @@ static UChar get_slowcase ( DiImage* img, DiOffT off )
       if (!img->ces[i]->fromC)
          break;
    }
-   vg_assert(i >= 0 && i < CACHE_N_ENTRIES);
+   vg_assert(i < CACHE_N_ENTRIES);
 
    realloc_CEnt(img, i, size, /*fromC?*/cslc != NULL);
    img->ces[i]->size = size;
@@ -1166,7 +1166,7 @@ SizeT ML_(img_get_some)(/*OUT*/void* dst,
    vg_assert(is_in_CEnt(ce, offset));
    SizeT nToCopy = size - 1;
    SizeT nAvail  = (SizeT)(ce->used - (offset + 1 - ce->off));
-   vg_assert(nAvail >= 0 && nAvail <= ce->used-1);
+   vg_assert(nAvail <= ce->used-1);
    if (nAvail < nToCopy) nToCopy = nAvail;
    VG_(memcpy)(&dstU[1], &ce->data[offset + 1 - ce->off], nToCopy);
    return nToCopy + 1;
index 9305f316efe9669fadb8b5e3645f6bc29b4d27a9..b00db18861c8dbd9ab015eab8d1269930edf9087 100644 (file)
@@ -546,7 +546,7 @@ static ExeContext* record_ExeContext_wrk2 ( const Addr* ips, UInt n_ips )
 
    /* Resize the hash table, maybe? */
    if ( ((ULong)ec_totstored) > ((ULong)ec_htab_size) ) {
-      vg_assert(ec_htab_size_idx >= 0 && ec_htab_size_idx < N_EC_PRIMES);
+      vg_assert(ec_htab_size_idx < N_EC_PRIMES);
       if (ec_htab_size_idx < N_EC_PRIMES-1)
          resize_ec_htab();
    }
index 724ea6b1fc4fc48914493dc8fbd5f868368f5c23..ce54ce7108544b68795bfc7eaa72dd7d2e2a50a6 100644 (file)
@@ -1710,7 +1710,7 @@ static void initialiseSector ( SECno sno )
          if (sector_search_order[ix] == sno)
             break;
       }
-      vg_assert(ix >= 0 && ix < n_sectors);
+      vg_assert(ix < n_sectors);
 
       if (VG_(clo_verbosity) > 2)
          VG_(message)(Vg_DebugMsg, "TT/TC: recycle sector %d\n", sno);
@@ -2029,7 +2029,7 @@ static void delete_tte ( /*OUT*/Addr* ga_deleted,
    /* sec and secNo are mutually redundant; cross-check. */
    vg_assert(sec == &sectors[secNo]);
 
-   vg_assert(tteno >= 0 && tteno < N_TTES_PER_SECTOR);
+   vg_assert(tteno < N_TTES_PER_SECTOR);
    TTEntryC* tteC = &sec->ttC[tteno];
    TTEntryH* tteH = &sec->ttH[tteno];
    vg_assert(tteH->status == InUse);
@@ -2104,7 +2104,7 @@ SizeT delete_translations_in_sector_eclass ( /*OUT*/Addr* ga_deleted,
    TTEno    tteno;
    SizeT    numDeld = 0;
 
-   vg_assert(ec >= 0 && ec < ECLASS_N);
+   vg_assert(ec < ECLASS_N);
 
    for (i = 0; i < sec->ec2tte_used[ec]; i++) {
 
index a31aacf5c7250a9357f8e2fc62e0f5223ed3e197..6a6e6294df880bf7f28f7c7852669c34949d2ee4 100644 (file)
@@ -685,7 +685,7 @@ static ThreadId map_threads_maybe_reverse_lookup_SLOW ( Thread* thr )
    ThreadId tid;
    tl_assert(HG_(is_sane_Thread)(thr));
    /* Check nobody used the invalid-threadid slot */
-   tl_assert(VG_INVALID_THREADID >= 0 && VG_INVALID_THREADID < VG_N_THREADS);
+   tl_assert(VG_INVALID_THREADID < VG_N_THREADS);
    tl_assert(map_threads[VG_INVALID_THREADID] == NULL);
    tid = thr->coretid;
    tl_assert(HG_(is_sane_ThreadId)(tid));
index 1f9e30ddcc9e34a78e74dc3612fec87338d62348..70164245d91d8ece5cd2ffa512554275279cb071 100644 (file)
@@ -111,7 +111,6 @@ typedef
       WCache* _cache = &(_zzcache);                                  \
       tl_assert(_cache->dynMax >= 1);                                \
       tl_assert(_cache->dynMax <= N_WCACHE_STAT_MAX);                \
-      tl_assert(_cache->inUse >= 0);                                 \
       tl_assert(_cache->inUse <= _cache->dynMax);                    \
       if (_cache->inUse < _cache->dynMax)                            \
          _cache->inUse++;                                            \
@@ -666,7 +665,7 @@ WordSet HG_(delFromWS) ( WordSetU* wsu, WordSet ws, UWord w )
    }
    /* So w is present in ws, and the new set will be one element
       smaller. */
-   tl_assert(i >= 0 && i < wv->size);
+   tl_assert(i < wv->size);
    tl_assert(wv->size > 0);
 
    wv_new = new_WV_of_size( wsu, wv->size - 1 );
index cb3daaa1399b7aa3ab0eec8d43ee47b657c18385..0a084dd60d4ae7f7f1b9f9735211a76dbdcf015b 100644 (file)
@@ -1033,7 +1033,6 @@ static void rcdec_LineZ ( LineZ* lineZ ) {
 inline
 static void write_twobit_array ( UChar* arr, UWord ix, UWord b2 ) {
    Word bix, shft, mask, prep;
-   tl_assert(ix >= 0);
    bix  = ix >> 2;
    shft = 2 * (ix & 3); /* 0, 2, 4 or 6 */
    mask = 3 << shft;
@@ -1044,7 +1043,6 @@ static void write_twobit_array ( UChar* arr, UWord ix, UWord b2 ) {
 inline
 static UWord read_twobit_array ( UChar* arr, UWord ix ) {
    Word bix, shft;
-   tl_assert(ix >= 0);
    bix  = ix >> 2;
    shft = 2 * (ix & 3); /* 0, 2, 4 or 6 */
    return (arr[bix] >> shft) & 3;
@@ -2364,7 +2362,7 @@ static void VTS__tick ( /*OUT*/VTS* out, Thr* me, VTS* vts )
            copy it to the output but increment its timestamp value.
            Then copy the remaining entries.  (c) is the common case.
    */
-   tl_assert(i >= 0 && i <= n);
+   tl_assert(i <= n);
    if (i == n) { /* case (a) */
       UInt hi = out->usedTS++;
       out->ts[hi].thrid = me_thrid;
index e6e9ef80aafdd83691ed701d3132d399ef190232..3a2a81741a749f883d04c98934eed93c2b59a9e8 100644 (file)
@@ -2946,8 +2946,7 @@ void make_aligned_word64_undefined_w_otag ( Addr a, UInt otag )
    //// Set the origins for a+0 .. a+7
    { OCacheLine* line;
      UWord lineoff = oc_line_offset(a);
-     tl_assert(lineoff >= 0
-               && lineoff < OC_W32S_PER_LINE -1/*'cos 8-aligned*/);
+     tl_assert(lineoff < OC_W32S_PER_LINE -1/*'cos 8-aligned*/);
      line = find_OCacheLine( a );
      line->u.main.descr[lineoff+0] = 0xF;
      line->u.main.descr[lineoff+1] = 0xF;
@@ -7120,7 +7119,7 @@ static Bool mc_handle_client_request ( ThreadId tid, UWord* arg, UWord* ret )
              (cgbs[arg[2]].start == 0 && cgbs[arg[2]].size == 0)) {
             *ret = 1;
          } else {
-            tl_assert(arg[2] >= 0 && arg[2] < cgb_used);
+            tl_assert(arg[2] < cgb_used);
             cgbs[arg[2]].start = cgbs[arg[2]].size = 0;
             VG_(free)(cgbs[arg[2]].desc);
             cgb_discards++;