Blob Blame History Raw
From ea6cd1d0b631da5bf64b2b0ab7c5e1d4e0e95562 Mon Sep 17 00:00:00 2001
From: Coiby Xu <coiby.xu@gmail.com>
Date: Tue, 15 Jun 2021 10:47:03 +0800
Subject: [PATCH 4/8] fix Error: CONSTANT_EXPRESSION_RESULT detected by covscan

This commit fixes the following error found by conscan,

    Error: CONSTANT_EXPRESSION_RESULT (CWE-569): [#def1]
    python-dmidecode-3.12.2/src/dmidecode.c:225: logical_vs_bitwise: The expression "16 && i < h->length - (row << 4)" is suspicious because it performs a Boolean operation on a constant other than 0 or 1.
    #  223|                   memset(tmp_s, 0, (h->length * 2) + 2);
    #  224|
    #  225|->                 for(i = 0; i < (16 && i < h->length - (row << 4)); i++) {
    #  226|                           snprintf(tmp_s + strlen(tmp_s), (h->length * 2)-strlen(tmp_s),
    #  227|                                    "0x%02x", (h->data)[(row << 4) + i]);

Signed-off-by: Coiby Xu <coiby.xu@gmail.com>
---
 src/dmidecode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/dmidecode.c b/src/dmidecode.c
index d2bed53..9efab60 100644
--- a/src/dmidecode.c
+++ b/src/dmidecode.c
@@ -222,7 +222,7 @@ void dmi_dump(xmlNode *node, struct dmi_header * h)
         for(row = 0; row < ((h->length - 1) >> 4) + 1; row++) {
                 memset(tmp_s, 0, (h->length * 2) + 2);
 
-                for(i = 0; i < (16 && i < h->length - (row << 4)); i++) {
+                for(i = 0; i < 16 && (i < h->length - (row << 4)); i++) {
                         snprintf(tmp_s + strlen(tmp_s), (h->length * 2)-strlen(tmp_s),
                                  "0x%02x", (h->data)[(row << 4) + i]);
                 }
-- 
2.31.1