Prefer 'ARRAYELTS (x)' to 'sizeof x / sizeof *x'

* src/comp.c (emit_limple_insn):
* src/msdos.c (dos_set_keyboard, dos_rawgetc):
* src/sysdep.c (convert_speed, list_system_processes):
* src/w32fns.c (deliver_wm_chars, Fx_file_dialog):
* src/w32term.c (record_event, w32_read_socket):
Prefer 'ARRAYELTS (x)' to 'sizeof x / sizeof *x'.

* admin/coccinelle/arrayelts.cocci: New file.
This commit is contained in:
Stefan Kangas 2025-01-15 20:09:32 +01:00
parent 16c89c5ae5
commit e092aabf71
6 changed files with 33 additions and 14 deletions

View file

@ -3160,7 +3160,7 @@ static const struct speed_struct speeds[] =
static speed_t
convert_speed (speed_t speed)
{
for (size_t i = 0; i < sizeof speeds / sizeof speeds[0]; i++)
for (size_t i = 0; i < ARRAYELTS (speeds); i++)
{
if (speed == speeds[i].internal)
return speed;
@ -3380,7 +3380,7 @@ list_system_processes (void)
int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PROC};
#endif
size_t len;
size_t mibsize = sizeof mib / sizeof mib[0];
size_t mibsize = ARRAYELTS (mib);
struct kinfo_proc *procs;
size_t i;