Commit ec69bda0 authored by Flavio Ceolin's avatar Flavio Ceolin Committed by Anas Nashif
Browse files

lib: hex: Code guideline fixes



Fixes violations code guideline related with essential types rules:

- Avoid mixing characters with integers
- Ensure computations are done in the destination precision

Signed-off-by: default avatarFlavio Ceolin <flavio.ceolin@intel.com>
Signed-off-by: default avatarAbramo Bagnara <abramo.bagnara@bugseng.com>
parent 04379cbe
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -12,11 +12,11 @@
int char2hex(char c, uint8_t *x)
{
	if (c >= '0' && c <= '9') {
		*x = c - '0';
		*x = (uint8_t)(int)(c - '0');
	} else if (c >= 'a' && c <= 'f') {
		*x = c - 'a' + 10;
		*x = (uint8_t)(int)(c - 'a' + 10);
	} else if (c >= 'A' && c <= 'F') {
		*x = c - 'A' + 10;
		*x = (uint8_t)(int)(c - 'A' + 10);
	} else {
		return -EINVAL;
	}
@@ -47,7 +47,7 @@ size_t bin2hex(const uint8_t *buf, size_t buflen, char *hex, size_t hexlen)
		if (hex2char(buf[i] >> 4, &hex[2 * i]) < 0) {
			return 0;
		}
		if (hex2char(buf[i] & 0xf, &hex[2 * i + 1]) < 0) {
		if (hex2char(buf[i] & 0x0FU, &hex[2 * i + 1]) < 0) {
			return 0;
		}
	}