diff --git a/ChangeLog b/ChangeLog index 854c008e1..326f62129 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-01-20 Vladimir Serbinenko + + Replace explicit sizeof divisions by ARRAY_SIZE. + 2015-01-19 Kris Moore * grub-core/disk/geli.c: Support GELI v6 and v7. diff --git a/grub-core/commands/i386/pc/sendkey.c b/grub-core/commands/i386/pc/sendkey.c index d985cb33f..26d9acd3d 100644 --- a/grub-core/commands/i386/pc/sendkey.c +++ b/grub-core/commands/i386/pc/sendkey.c @@ -292,7 +292,7 @@ find_key_code (char *key) { unsigned i; - for (i = 0; i < sizeof (keysym_table) / sizeof (keysym_table[0]); i++) + for (i = 0; i < ARRAY_SIZE(keysym_table); i++) { if (keysym_table[i].unshifted_name && grub_strcmp (key, keysym_table[i].unshifted_name) == 0) @@ -311,7 +311,7 @@ find_ascii_code (char *key) { unsigned i; - for (i = 0; i < sizeof (keysym_table) / sizeof (keysym_table[0]); i++) + for (i = 0; i < ARRAY_SIZE(keysym_table); i++) { if (keysym_table[i].unshifted_name && grub_strcmp (key, keysym_table[i].unshifted_name) == 0) @@ -352,15 +352,13 @@ grub_cmd_sendkey (grub_extcmd_context_t ctxt, int argc, char **args) { unsigned i; - for (i = 0; i < sizeof (simple_flag_offsets) - / sizeof (simple_flag_offsets[0]); i++) + for (i = 0; i < ARRAY_SIZE(simple_flag_offsets); i++) grub_sendkey_set_simple_flag (simple_flag_offsets[i], grub_sendkey_parse_op(state[i])); } /* Set noled. */ - noled = (state[sizeof (simple_flag_offsets) - / sizeof (simple_flag_offsets[0])].set); + noled = (state[ARRAY_SIZE(simple_flag_offsets)].set); return GRUB_ERR_NONE; } diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 44b0fcbb1..a4ebf78a9 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -99,7 +99,7 @@ find_free_slot (void) { unsigned int i; - for (i = 0; i < sizeof (map) / sizeof (map[0]); i++) + for (i = 0; i < ARRAY_SIZE (map); i++) if (! map[i].drive) return i; @@ -115,7 +115,7 @@ grub_util_biosdisk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data, if (pull != GRUB_DISK_PULL_NONE) return 0; - for (i = 0; i < sizeof (map) / sizeof (map[0]); i++) + for (i = 0; i < ARRAY_SIZE (map); i++) if (map[i].drive && hook (map[i].drive, hook_data)) return 1; @@ -581,7 +581,7 @@ grub_util_biosdisk_fini (void) { unsigned i; - for (i = 0; i < sizeof (map) / sizeof (map[0]); i++) + for (i = 0; i < ARRAY_SIZE(map); i++) { if (map[i].drive) free (map[i].drive); diff --git a/grub-core/lib/syslinux_parse.c b/grub-core/lib/syslinux_parse.c index 08e451cea..241cefe69 100644 --- a/grub-core/lib/syslinux_parse.c +++ b/grub-core/lib/syslinux_parse.c @@ -717,7 +717,7 @@ syslinux_parse_real (struct syslinux_menu *menu) for (ptr3 = ptr2; grub_isspace (*ptr3) && *ptr3; ptr3++); for (ptr4 = ptr3; !grub_isspace (*ptr4) && *ptr4; ptr4++); for (ptr5 = ptr4; grub_isspace (*ptr5) && *ptr5; ptr5++); - for (i = 0; i < sizeof (commands) / sizeof (commands[0]); i++) + for (i = 0; i < ARRAY_SIZE(commands); i++) if (grub_strlen (commands[i].name1) == (grub_size_t) (ptr2 - ptr1) && grub_strncasecmp (commands[i].name1, ptr1, ptr2 - ptr1) == 0 && (commands[i].name2 == NULL @@ -726,7 +726,7 @@ syslinux_parse_real (struct syslinux_menu *menu) && grub_strncasecmp (commands[i].name2, ptr3, ptr4 - ptr3) == 0))) break; - if (i == sizeof (commands) / sizeof (commands[0])) + if (i == ARRAY_SIZE(commands)) { if (sizeof ("text") - 1 == ptr2 - ptr1 && grub_strncasecmp ("text", ptr1, ptr2 - ptr1) == 0 diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c index e83e1e972..94daa021e 100644 --- a/grub-core/loader/i386/xnu.c +++ b/grub-core/loader/i386/xnu.c @@ -741,10 +741,10 @@ grub_cpu_xnu_fill_devicetree (grub_uint64_t *fsbfreq_out) *((grub_uint64_t *) curval->data) = (grub_addr_t) ptr; /* Create alias. */ - for (j = 0; j < sizeof (table_aliases) / sizeof (table_aliases[0]); j++) + for (j = 0; j < ARRAY_SIZE(table_aliases); j++) if (grub_memcmp (&table_aliases[j].guid, &guid, sizeof (guid)) == 0) break; - if (j != sizeof (table_aliases) / sizeof (table_aliases[0])) + if (j != ARRAY_SIZE(table_aliases)) { curval = grub_xnu_create_value (&(curkey->first_child), "alias"); if (!curval) diff --git a/grub-core/normal/color.c b/grub-core/normal/color.c index c2654239f..d22cf903d 100644 --- a/grub-core/normal/color.c +++ b/grub-core/normal/color.c @@ -47,7 +47,7 @@ static int parse_color_name (grub_uint8_t *ret, char *name) { grub_uint8_t i; - for (i = 0; i < sizeof (color_list) / sizeof (*color_list); i++) + for (i = 0; i < ARRAY_SIZE(color_list); i++) if (! grub_strcmp (name, color_list[i])) { *ret = i;