This is an automated email from Gerrit.

"Jessica Clarke <jrt...@jrtc27.com>" just uploaded a new patch set to Gerrit, 
which you can find at https://review.openocd.org/c/openocd/+/8490

-- gerrit

commit 75bca35108ed9ca5bc9aabe33b13bc84e6646c65
Author: Jessica Clarke <jrt...@jrtc27.com>
Date:   Fri Sep 13 18:10:48 2024 +0100

    binarybuffer: Invert buf_cmp* return value and rename to buf_eq*
    
    The current semantics are a bit confusing, as the return value looks
    like memcmp (0/false being equal) but the bool return type means one
    likely expects true to mean equal. Make this clearer by switching them
    out for buf_eq* functions that do that instead.
    
    Change-Id: Iee0c5af794316aab5327cb9c168051fabd3bc1cb
    Signed-off-by: Jessica Clarke <jrt...@jrtc27.com>

diff --git a/src/helper/binarybuffer.c b/src/helper/binarybuffer.c
index c25383dc61..a7ca5af9df 100644
--- a/src/helper/binarybuffer.c
+++ b/src/helper/binarybuffer.c
@@ -57,49 +57,49 @@ void *buf_cpy(const void *from, void *_to, unsigned size)
        return _to;
 }
 
-static bool buf_cmp_masked(uint8_t a, uint8_t b, uint8_t m)
+static bool buf_eq_masked(uint8_t a, uint8_t b, uint8_t m)
 {
-       return (a & m) != (b & m);
+       return (a & m) == (b & m);
 }
-static bool buf_cmp_trailing(uint8_t a, uint8_t b, uint8_t m, unsigned 
trailing)
+static bool buf_eq_trailing(uint8_t a, uint8_t b, uint8_t m, unsigned trailing)
 {
        uint8_t mask = (1 << trailing) - 1;
-       return buf_cmp_masked(a, b, mask & m);
+       return buf_eq_masked(a, b, mask & m);
 }
 
-bool buf_cmp(const void *_buf1, const void *_buf2, unsigned size)
+bool buf_eq(const void *_buf1, const void *_buf2, unsigned size)
 {
        if (!_buf1 || !_buf2)
-               return _buf1 != _buf2;
+               return _buf1 == _buf2;
 
        unsigned last = size / 8;
        if (memcmp(_buf1, _buf2, last) != 0)
-               return true;
+               return false;
 
        unsigned trailing = size % 8;
        if (!trailing)
-               return false;
+               return true;
 
        const uint8_t *buf1 = _buf1, *buf2 = _buf2;
-       return buf_cmp_trailing(buf1[last], buf2[last], 0xff, trailing);
+       return buf_eq_trailing(buf1[last], buf2[last], 0xff, trailing);
 }
 
-bool buf_cmp_mask(const void *_buf1, const void *_buf2,
+bool buf_eq_mask(const void *_buf1, const void *_buf2,
        const void *_mask, unsigned size)
 {
        if (!_buf1 || !_buf2)
-               return _buf1 != _buf2 || _buf1 != _mask;
+               return _buf1 == _buf2 && _buf1 == _mask;
 
        const uint8_t *buf1 = _buf1, *buf2 = _buf2, *mask = _mask;
        unsigned last = size / 8;
        for (unsigned i = 0; i < last; i++) {
-               if (buf_cmp_masked(buf1[i], buf2[i], mask[i]))
-                       return true;
+               if (!buf_eq_masked(buf1[i], buf2[i], mask[i]))
+                       return false;
        }
        unsigned trailing = size % 8;
        if (!trailing)
-               return false;
-       return buf_cmp_trailing(buf1[last], buf2[last], mask[last], trailing);
+               return true;
+       return buf_eq_trailing(buf1[last], buf2[last], mask[last], trailing);
 }
 
 void *buf_set_ones(void *_buf, unsigned size)
diff --git a/src/helper/binarybuffer.h b/src/helper/binarybuffer.h
index 103a48c5c5..dfb3632bc6 100644
--- a/src/helper/binarybuffer.h
+++ b/src/helper/binarybuffer.h
@@ -168,8 +168,8 @@ static inline uint64_t buf_get_u64(const uint8_t *_buffer,
  */
 uint32_t flip_u32(uint32_t value, unsigned width);
 
-bool buf_cmp(const void *buf1, const void *buf2, unsigned size);
-bool buf_cmp_mask(const void *buf1, const void *buf2,
+bool buf_eq(const void *buf1, const void *buf2, unsigned size);
+bool buf_eq_mask(const void *buf1, const void *buf2,
                const void *mask, unsigned size);
 
 /**
diff --git a/src/jtag/core.c b/src/jtag/core.c
index 9eae5e74ba..a6f38a19dd 100644
--- a/src/jtag/core.c
+++ b/src/jtag/core.c
@@ -881,9 +881,9 @@ static int jtag_check_value_inner(uint8_t *captured, 
uint8_t *in_check_value,
        int compare_failed;
 
        if (in_check_mask)
-               compare_failed = buf_cmp_mask(captured, in_check_value, 
in_check_mask, num_bits);
+               compare_failed = !buf_eq_mask(captured, in_check_value, 
in_check_mask, num_bits);
        else
-               compare_failed = buf_cmp(captured, in_check_value, num_bits);
+               compare_failed = !buf_eq(captured, in_check_value, num_bits);
 
        if (compare_failed) {
                char *captured_str, *in_check_value_str;
diff --git a/src/svf/svf.c b/src/svf/svf.c
index dd3d5175c3..470889948c 100644
--- a/src/svf/svf.c
+++ b/src/svf/svf.c
@@ -932,7 +932,7 @@ static int svf_check_tdo(void)
                index_var = svf_check_tdo_para[i].buffer_offset;
                len = svf_check_tdo_para[i].bit_len;
                if ((svf_check_tdo_para[i].enabled)
-                               && buf_cmp_mask(&svf_tdi_buffer[index_var], 
&svf_tdo_buffer[index_var],
+                               && !buf_eq_mask(&svf_tdi_buffer[index_var], 
&svf_tdo_buffer[index_var],
                                &svf_mask_buffer[index_var], len)) {
                        LOG_ERROR("tdo check error at line %d",
                                svf_check_tdo_para[i].line_num);

-- 

Reply via email to