Skip to contentSkip to conversation

btrfs-progs: replace sizeof() with ARRAY_SIZE() macro

PATCH New Integral 1 participant 1 message Nov 9, 2024 Btrfs file system

lore
Share & tools
lore

Integral

author
#0 lore raw

PATCH 1/1 btrfs-progs: replace sizeof() with ARRAY_SIZE() macro

Use ARRAY_SIZE() macro to simplify for loop.

---
 common/format-output.c | 2 +-
 common/sort-utils.h    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
common/format-output.c +1 -1
index 3b333ed5..f150a4f2 100644
@@ -149,7 +149,7 @@ static bool fmt_set_unquoted(struct format_ctx *fctx, const struct rowspec *row,
 {
 	static const char *types[] = { "%llu", "bool" };
 
-	for (int i = 0; i < sizeof(types) / sizeof(types[0]); i++)
+	for (int i = 0; i < ARRAY_SIZE(types); i++)
 		if (strcmp(types[i], row->fmt) == 0)
 			return true;
 
common/sort-utils.h +1 -1
index 09be7b7d..a8af9658 100644
@@ -56,7 +56,7 @@ void test() {
 	const char *sortby[] = { "size", "id" };
 
 	compare_init(&comp, sortit);
-	for (i = 0; i < sizeof(sortby) / sizeof(sortby[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(sortby); i++) {
 		ret = compare_add_sort_key(&comp, sortby[i]);
 		if (ret < 0) {
 			printf("ERROR adding sort key %s\n", sortby[i]);
Signature · 1 line
2.47.0