Skip to content

Commit

Permalink
Squash a different signedness comparison warning
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrojnar committed May 24, 2024
1 parent 15104c9 commit ae1e4d7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/listkeys_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ int getbin(const char c)
int hex2bin(unsigned char *dst, const char *str, size_t *op_len)
{
const char HEXDIGITS[] = "01234567890ABCDEFabcdef";
size_t len, byte_len;

if (!str || !dst) {
*op_len = 0;
return -1;
}

ssize_t len = 0, byte_len = 0;
len = strspn(str, HEXDIGITS);
/* 0x010 needs 2 bytes , 0x0110 needs 2 bytes, 0x010203 needs 3 bytes, 0x10203 needs 3 bytes, and so on */
byte_len = (len + 1) / 2;
Expand All @@ -124,7 +124,7 @@ int hex2bin(unsigned char *dst, const char *str, size_t *op_len)
/* start parsing from end of hexstring to beginning of hex string */
/* len is including '\0' so use pre-decrement */
int lsb = getbin(str[--len]); // this never goes out of bounds, we will have at least one byte to process!
int msb = --len >= 0 ? getbin(str[len]) : 0; // avoid underflow on str (when len is not even we assume 0)
int msb = len-- > 0 ? getbin(str[len]) : 0; // avoid underflow on str (when len is not even we assume 0)

/* combine msb and lsb to make uint8_t; */
dst[byte_len] = msb << 4 | lsb;
Expand Down

0 comments on commit ae1e4d7

Please sign in to comment.