This is an automated email from Gerrit.

"Antonio Borneo <borneo.anto...@gmail.com>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8395

-- gerrit

commit 0a775cab49ed72f0699c4b5839f3f61f140fbd05
Author: Antonio Borneo <borneo.anto...@gmail.com>
Date:   Sun Jul 14 12:31:53 2024 +0200

    binarybuffer: str_to_buf(): rename buf_len as buf_bitsize
    
    The name 'buf_len' is misleading, as it usually refers to the byte
    length of a buffer. Here we use it for the length in bits.
    
    Rename it as 'buf_bitsize'.
    While there, fix checkpatch error by changing the index type to
    'unsigned int'.
    
    Change-Id: I78855ed79a346d996d9c0100d94d14c64a36b228
    Signed-off-by: Antonio Borneo <borneo.anto...@gmail.com>

diff --git a/src/helper/binarybuffer.c b/src/helper/binarybuffer.c
index da6e10bab7..dd1449276a 100644
--- a/src/helper/binarybuffer.c
+++ b/src/helper/binarybuffer.c
@@ -249,7 +249,7 @@ static const char *str_strip_number_prefix(const char *str, 
unsigned int radix)
        }
 }
 
-int str_to_buf(const char *str, void *_buf, unsigned int buf_len)
+int str_to_buf(const char *str, void *_buf, unsigned int buf_bitsize)
 {
        assert(str);
 
@@ -314,18 +314,18 @@ int str_to_buf(const char *str, void *_buf, unsigned int 
buf_len)
                assert(tmp == 0);
        }
 
-       /* The result must not contain more bits than buf_len. */
+       /* The result must not contain more bits than buf_bitsize. */
        /* Check the whole bytes: */
-       for (unsigned int j = DIV_ROUND_UP(buf_len, 8); j < b256_len; j++) {
+       for (unsigned int j = DIV_ROUND_UP(buf_bitsize, 8); j < b256_len; j++) {
                if (b256_buf[j] != 0x0) {
                        free(b256_buf);
                        return ERROR_NUMBER_EXCEEDS_BUFFER;
                }
        }
        /* Check the partial byte: */
-       if (buf_len % 8) {
-               const uint8_t mask = 0xFFu << (buf_len % 8);
-               if ((b256_buf[(buf_len / 8)] & mask) != 0x0) {
+       if (buf_bitsize % 8) {
+               const uint8_t mask = 0xFFu << (buf_bitsize % 8);
+               if ((b256_buf[(buf_bitsize / 8)] & mask) != 0x0) {
                        free(b256_buf);
                        return ERROR_NUMBER_EXCEEDS_BUFFER;
                }
@@ -333,7 +333,7 @@ int str_to_buf(const char *str, void *_buf, unsigned int 
buf_len)
 
        /* Copy the digits to the output buffer */
        uint8_t *buf = _buf;
-       for (unsigned j = 0; j < DIV_ROUND_UP(buf_len, 8); j++) {
+       for (unsigned int j = 0; j < DIV_ROUND_UP(buf_bitsize, 8); j++) {
                if (j < b256_len)
                        buf[j] = b256_buf[j];
                else
diff --git a/src/helper/binarybuffer.h b/src/helper/binarybuffer.h
index 6cff86bd92..103a48c5c5 100644
--- a/src/helper/binarybuffer.h
+++ b/src/helper/binarybuffer.h
@@ -198,10 +198,10 @@ void *buf_set_buf(const void *src, unsigned src_start,
  * number is detected between decimal, hexadecimal and octal.
  * @param str Input number, zero-terminated string
  * @param _buf Output buffer, allocated by the caller
- * @param buf_len Output buffer size in bits
+ * @param buf_bitsize Output buffer size in bits
  * @returns Error on invalid or overflowing number
  */
-int str_to_buf(const char *str, void *_buf, unsigned int buf_len);
+int str_to_buf(const char *str, void *_buf, unsigned int buf_bitsize);
 
 char *buf_to_hex_str(const void *buf, unsigned size);
 

-- 

Reply via email to