clang-tidy: Fix bugprone-macro-parentheses diagnostics
Example output:
```
/usr/bin/clang-tidy -checks=-*, bugprone-macro-parentheses -export-fixes /tmp/tmpemqa5szx/tmph_piz_ci.yaml -p=build /mnt/host/andrew/src/openbmc/libpldm/src/base.c
/mnt/host/andrew/src/openbmc/libpldm/build/../include/libpldm/base.h:137:21: error: macro argument should be enclosed in parentheses [bugprone-macro-parentheses,-warnings-as-errors]
^
()
```
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Id12338430a328436d57d6560db1d3a1c53001b83
diff --git a/include/libpldm/base.h b/include/libpldm/base.h
index 6c2e094..26e0825 100644
--- a/include/libpldm/base.h
+++ b/include/libpldm/base.h
@@ -134,10 +134,10 @@
} __attribute__((packed));
// Macros for byte-swapping variables in-place
-#define HTOLE32(X) (X = htole32(X))
-#define HTOLE16(X) (X = htole16(X))
-#define LE32TOH(X) (X = le32toh(X))
-#define LE16TOH(X) (X = le16toh(X))
+#define HTOLE32(X) ((X) = htole32(X))
+#define HTOLE16(X) ((X) = htole16(X))
+#define LE32TOH(X) ((X) = le32toh(X))
+#define LE16TOH(X) ((X) = le16toh(X))
/** @struct pldm_msg
*
diff --git a/src/bios_table.c b/src/bios_table.c
index ef69dc2..c187ab1 100644
--- a/src/bios_table.c
+++ b/src/bios_table.c
@@ -11,19 +11,19 @@
#define POINTER_CHECK(pointer) \
do { \
- if (pointer == NULL) \
+ if ((pointer) == NULL) \
return PLDM_ERROR_INVALID_DATA; \
} while (0)
#define ATTR_TYPE_EXPECT(type, expected) \
do { \
- if (type != expected && type != (expected | 0x80)) \
+ if ((type) != (expected) && (type) != ((expected) | 0x80)) \
return PLDM_ERROR_INVALID_DATA; \
} while (0)
#define BUFFER_SIZE_EXPECT(current_size, expected_size) \
do { \
- if (current_size < expected_size) \
+ if ((current_size) < (expected_size)) \
return PLDM_ERROR_INVALID_LENGTH; \
} while (0)
@@ -203,7 +203,7 @@
#define ATTR_TYPE_EXPECT(type, expected) \
do { \
- if (type != expected && type != (expected | 0x80)) \
+ if ((type) != (expected) && (type) != ((expected) | 0x80)) \
return PLDM_ERROR_INVALID_DATA; \
} while (0)
@@ -560,7 +560,7 @@
size_t (*entry_length_handler)(const void *);
};
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
static const struct table_entry_length *find_table_entry_length_by_type(
uint8_t attr_type, const struct table_entry_length *handlers, size_t count)
diff --git a/src/utils.c b/src/utils.c
index b78ffe5..ea25f54 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -104,7 +104,7 @@
#define AS_CHAR(digit) ((digit) + '0')
#define INSERT_CHAR(c, b, n) \
{ \
- if (n > 1) { \
+ if ((n) > 1) { \
*(b)++ = (c); \
(n)--; \
} \