clang-tidy: Fix readability-braces-around-statements diagnostics
For example:
```
/usr/bin/clang-tidy -checks=-*, readability-braces-around-statements -export-fixes /tmp/tmpp5g5_gym/tmpoyj8t6gj.yaml -p=build /mnt/host/andrew/src/openbmc/libpldm/src/utils.c
/mnt/host/andrew/src/openbmc/libpldm/build/../src/utils.c:88:16: error: statement should be inside braces [readability-braces-around-statements,-warnings-as-errors]
while (size--)
^
{
```
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Id06d4049d5c9db1378b5a66ef1bac5372715a0fd
diff --git a/src/bios_table.c b/src/bios_table.c
index c187ab1..e8a419c 100644
--- a/src/bios_table.c
+++ b/src/bios_table.c
@@ -31,8 +31,9 @@
static void set_errmsg(const char **errmsg, const char *msg)
{
- if (errmsg != NULL)
+ if (errmsg != NULL) {
*errmsg = msg;
+ }
}
static uint16_t get_bios_string_handle(void)
@@ -64,8 +65,9 @@
const char *str,
uint16_t str_length)
{
- if (str_length == 0)
+ if (str_length == 0) {
return PLDM_ERROR_INVALID_DATA;
+ }
POINTER_CHECK(entry);
POINTER_CHECK(str);
size_t length = pldm_bios_table_string_entry_encode_length(str_length);
@@ -179,8 +181,9 @@
uint16_t *pv_hdls =
(uint16_t *)(attr_entry->metadata + 1 /* sizeof(pv num) */);
size_t i;
- for (i = 0; i < info->pv_num; i++)
+ for (i = 0; i < info->pv_num; i++) {
pv_hdls[i] = htole16(info->pv_handle[i]);
+ }
attr_entry->metadata[1 + info->pv_num * sizeof(uint16_t)] =
info->def_num;
memcpy(attr_entry->metadata + 1 /* sizeof(pv num) */ +
@@ -264,8 +267,9 @@
POINTER_CHECK(pv_hdls);
ATTR_TYPE_EXPECT(entry->attr_type, PLDM_BIOS_ENUMERATION);
uint8_t num = pldm_bios_table_attr_entry_enum_decode_pv_num(entry);
- if (num != pv_num)
+ if (num != pv_num) {
return PLDM_ERROR_INVALID_DATA;
+ }
pldm_bios_table_attr_entry_enum_decode_pv_hdls(entry, pv_hdls, pv_num);
return PLDM_SUCCESS;
}
@@ -329,9 +333,10 @@
attr_fields->min_length = htole16(info->min_length);
attr_fields->max_length = htole16(info->max_length);
attr_fields->def_length = htole16(info->def_length);
- if (info->def_length != 0 && info->def_string != NULL)
+ if (info->def_length != 0 && info->def_string != NULL) {
memcpy(attr_fields->def_string, info->def_string,
info->def_length);
+ }
}
#define PLDM_STRING_TYPE_MAX 5
@@ -380,8 +385,9 @@
pldm_bios_table_attr_entry_string_encode_length(info->def_length);
BUFFER_SIZE_EXPECT(entry_length, length);
if (pldm_bios_table_attr_entry_string_info_check(info, NULL) !=
- PLDM_SUCCESS)
+ PLDM_SUCCESS) {
return PLDM_ERROR_INVALID_DATA;
+ }
pldm_bios_table_attr_entry_string_encode(entry, entry_length, info);
return PLDM_SUCCESS;
}
@@ -531,8 +537,9 @@
size_t length = pldm_bios_table_attr_entry_integer_encode_length();
BUFFER_SIZE_EXPECT(entry_length, length);
if (pldm_bios_table_attr_entry_integer_info_check(info, NULL) !=
- PLDM_SUCCESS)
+ PLDM_SUCCESS) {
return PLDM_ERROR_INVALID_DATA;
+ }
pldm_bios_table_attr_entry_integer_encode(entry, entry_length, info);
return PLDM_SUCCESS;
}
@@ -567,8 +574,9 @@
{
size_t i;
for (i = 0; i < count; i++) {
- if (attr_type == handlers[i].attr_type)
+ if (attr_type == handlers[i].attr_type) {
return &handlers[i];
+ }
}
return NULL;
}
@@ -631,8 +639,9 @@
table_entry->attr_handle = htole16(attr_handle);
table_entry->attr_type = attr_type;
table_entry->value[0] = count;
- if (count != 0)
+ if (count != 0) {
memcpy(&table_entry->value[1], handles, count);
+ }
}
uint8_t pldm_bios_table_attr_value_entry_enum_decode_number(
@@ -658,8 +667,9 @@
uint8_t count, uint8_t *handles)
{
POINTER_CHECK(entry);
- if (count != 0 && handles == NULL)
+ if (count != 0 && handles == NULL) {
return PLDM_ERROR_INVALID_DATA;
+ }
ATTR_TYPE_EXPECT(attr_type, PLDM_BIOS_ENUMERATION);
size_t length =
pldm_bios_table_attr_value_entry_encode_enum_length(count);
@@ -694,9 +704,10 @@
struct pldm_bios_attr_val_table_entry *table_entry = entry;
table_entry->attr_handle = htole16(attr_handle);
table_entry->attr_type = attr_type;
- if (str_length != 0)
+ if (str_length != 0) {
memcpy(table_entry->value + sizeof(str_length), str,
str_length);
+ }
str_length = htole16(str_length);
memcpy(table_entry->value, &str_length, sizeof(str_length));
}
@@ -724,8 +735,9 @@
uint16_t str_length, const char *str)
{
POINTER_CHECK(entry);
- if (str_length != 0 && str == NULL)
+ if (str_length != 0 && str == NULL) {
return PLDM_ERROR_INVALID_DATA;
+ }
ATTR_TYPE_EXPECT(attr_type, PLDM_BIOS_STRING);
size_t length =
pldm_bios_table_attr_value_entry_encode_string_length(str_length);
@@ -843,8 +855,9 @@
static uint8_t *pad_append(uint8_t *table_end, size_t pad_size)
{
- while (pad_size--)
+ while (pad_size--) {
*table_end++ = 0;
+ }
return table_end;
}
@@ -923,15 +936,17 @@
#define pad_and_check_max 7
bool pldm_bios_table_iter_is_end(const struct pldm_bios_table_iter *iter)
{
- if (iter->table_len - iter->current_pos <= pad_and_check_max)
+ if (iter->table_len - iter->current_pos <= pad_and_check_max) {
return true;
+ }
return false;
}
void pldm_bios_table_iter_next(struct pldm_bios_table_iter *iter)
{
- if (pldm_bios_table_iter_is_end(iter))
+ if (pldm_bios_table_iter_is_end(iter)) {
return;
+ }
const void *entry = iter->table_data + iter->current_pos;
iter->current_pos += iter->entry_length_handler(entry);
}
@@ -950,8 +965,9 @@
const void *entry;
while (!pldm_bios_table_iter_is_end(iter)) {
entry = pldm_bios_table_iter_value(iter);
- if (equal(entry, key))
+ if (equal(entry, key)) {
return entry;
+ }
pldm_bios_table_iter_next(iter);
}
return NULL;
@@ -974,8 +990,10 @@
{
const struct pldm_bios_string_table_entry *string_entry = entry;
uint16_t handle = *(uint16_t *)key;
- if (pldm_bios_table_string_entry_decode_handle(string_entry) == handle)
+ if (pldm_bios_table_string_entry_decode_handle(string_entry) ==
+ handle) {
return true;
+ }
return false;
}
@@ -998,10 +1016,12 @@
const struct pldm_bios_string_table_entry *string_entry = entry;
const struct string_equal_arg *arg = key;
if (arg->str_length !=
- pldm_bios_table_string_entry_decode_string_length(string_entry))
+ pldm_bios_table_string_entry_decode_string_length(string_entry)) {
return false;
- if (memcmp(string_entry->name, arg->str, arg->str_length) != 0)
+ }
+ if (memcmp(string_entry->name, arg->str, arg->str_length) != 0) {
return false;
+ }
return true;
}
@@ -1112,13 +1132,15 @@
bool pldm_bios_table_checksum(const uint8_t *table, size_t size)
{
- if (table == NULL)
+ if (table == NULL) {
return false;
+ }
// 12: BIOSStringHandle(uint16) + BIOSStringLength(uint16) +
// Variable(4) + checksum(uint32)
- if (size < 12)
+ if (size < 12) {
return false;
+ }
uint32_t src_crc = le32toh(*(uint32_t *)(table + size - 4));
uint32_t dst_crc = crc32(table, size - 4);
diff --git a/src/utils.c b/src/utils.c
index ea25f54..482fd95 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -85,8 +85,9 @@
{
const uint8_t *p = data;
uint32_t crc = ~0U;
- while (size--)
+ while (size--) {
crc = crc32_tab[(crc ^ *p++) & 0xff] ^ (crc >> 8);
+ }
return crc ^ ~0U;
}
@@ -94,8 +95,9 @@
{
const uint8_t *p = data;
uint8_t crc = 0x00;
- while (size--)
+ while (size--) {
crc = crc8_table[crc ^ *p++];
+ }
return crc;
}
@@ -115,14 +117,17 @@
ssize_t remaining;
char *cursor;
- if (!version || !buffer)
+ if (!version || !buffer) {
return -1;
+ }
- if (!buffer_size)
+ if (!buffer_size) {
return -1;
+ }
- if (buffer_size > SSIZE_MAX)
+ if (buffer_size > SSIZE_MAX) {
return -1;
+ }
cursor = buffer;
remaining = (ssize_t)buffer_size;