From 9d943b7f6ff1e149fac3d574fbd95dbcd3d06d61 Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Wed, 22 Nov 2023 21:22:18 +0100 Subject: [PATCH] coverity: unsigned comparisons with 0 --- VEX/priv/guest_s390_helpers.c | 2 +- VEX/priv/ir_defs.c | 4 ++-- coregrind/m_mallocfree.c | 2 +- coregrind/m_syswrap/syswrap-generic.c | 3 +-- coregrind/m_transtab.c | 2 +- helgrind/hg_wordset.c | 1 - 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/VEX/priv/guest_s390_helpers.c b/VEX/priv/guest_s390_helpers.c index 693e96bf6f..008f8c6c8c 100644 --- a/VEX/priv/guest_s390_helpers.c +++ b/VEX/priv/guest_s390_helpers.c @@ -570,7 +570,7 @@ s390_do_cu24(UInt srcval, UInt low_surrogate) srcval &= 0xffff; - if ((srcval >= 0x0000 && srcval <= 0xd7ff) || + if ((srcval <= 0xd7ff) || (srcval >= 0xdc00 && srcval <= 0xffff)) { retval = srcval; } else { diff --git a/VEX/priv/ir_defs.c b/VEX/priv/ir_defs.c index 31710eb33a..0ef49eaa6a 100644 --- a/VEX/priv/ir_defs.c +++ b/VEX/priv/ir_defs.c @@ -4552,7 +4552,7 @@ static void useBeforeDef_Temp ( const IRSB* bb, const IRStmt* stmt, IRTemp tmp, Int* def_counts ) { - if (tmp < 0 || tmp >= bb->tyenv->types_used) + if (tmp >= bb->tyenv->types_used) sanityCheckFail(bb,stmt, "out of range Temp in IRExpr"); if (def_counts[tmp] < 1) sanityCheckFail(bb,stmt, "IRTemp use before def in IRExpr"); @@ -4564,7 +4564,7 @@ void assignedOnce_Temp(const IRSB *bb, const IRStmt *stmt, IRTemp tmp, const HChar *err_msg_out_of_range, const HChar *err_msg_assigned_more_than_once) { - if (tmp < 0 || tmp >= n_def_counts) { + if (tmp >= n_def_counts) { sanityCheckFail(bb, stmt, err_msg_out_of_range); } diff --git a/coregrind/m_mallocfree.c b/coregrind/m_mallocfree.c index 96104c8d57..dbbcb93961 100644 --- a/coregrind/m_mallocfree.c +++ b/coregrind/m_mallocfree.c @@ -1001,7 +1001,7 @@ Superblock* maybe_findSb ( Arena* a, Addr ad ) while (min <= max) { Superblock * sb; SizeT pos = min + (max - min)/2; - if (pos < 0 || pos >= a->sblocks_used) + if (pos >= a->sblocks_used) return NULL; sb = a->sblocks[pos]; if ((Addr)&sb->payload_bytes[0] <= ad diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index d2ff8c0f44..8550ef942c 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -4351,8 +4351,7 @@ PRE(sys_poll) POST(sys_poll) { - // RES is UWord so always >= 0 - if (SUCCESS && RES >= 0) { + if (SUCCESS) { UInt i; struct vki_pollfd* ufds = (struct vki_pollfd *)(Addr)ARG1; for (i = 0; i < ARG2; i++) diff --git a/coregrind/m_transtab.c b/coregrind/m_transtab.c index 3c45ef43b3..9794713069 100644 --- a/coregrind/m_transtab.c +++ b/coregrind/m_transtab.c @@ -1264,7 +1264,7 @@ static Bool sanity_check_eclasses_in_sector ( const Sector* sec ) && tteC->tte2ec_ec[k] >= tteC->tte2ec_ec[k+1]) BAD("tteC->tte2ec_ec[..] out of order"); ec_num = tteC->tte2ec_ec[k]; - if (ec_num < 0 || ec_num >= ECLASS_N) + if (ec_num >= ECLASS_N) BAD("tteC->tte2ec_ec[..] out of range"); if (ec_num != i) continue; diff --git a/helgrind/hg_wordset.c b/helgrind/hg_wordset.c index 70164245d9..5d8a51a132 100644 --- a/helgrind/hg_wordset.c +++ b/helgrind/hg_wordset.c @@ -503,7 +503,6 @@ Bool HG_(saneWS_SLOW) ( WordSetU* wsu, WordSet ws ) wv = do_ix2vec( wsu, ws ); /* can never happen .. do_ix2vec will assert instead. Oh well. */ if (wv->owner != wsu) return False; - if (wv->size < 0) return False; if (wv->size > 0) { for (i = 0; i < wv->size-1; i++) { if (wv->words[i] >= wv->words[i+1]) -- 2.47.2