* 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.
(cherry picked from commit
e092aabf714717dd135e5767a49b78c428e49878)
--- /dev/null
+// Use the ARRAYELTS macro where possible.
+@@
+type T;
+T[] E;
+@@
+- (sizeof (E) / sizeof (E[...]))
++ ARRAYELTS (E)
+
+@@
+type T;
+T[] E;
+@@
+- (sizeof (E) / sizeof (T))
++ ARRAYELTS (E)
+
+@@
+type T;
+T[] E;
+@@
+- (sizeof (E) / sizeof (*E))
++ ARRAYELTS (E)
ptrdiff_t i = 0;
FOR_EACH_TAIL (p)
{
- if (i == sizeof (arg) / sizeof (Lisp_Object))
+ if (i == ARRAYELTS (arg))
break;
arg[i++] = XCAR (p);
}
keyboard_map_all = always;
dos_keyboard_layout = 1;
- for (i = 0; i < (sizeof (keyboard_layout_list)/sizeof (struct keyboard_layout_list)); i++)
+ for (i = 0; i < ARRAYELTS (keyboard_layout_list); i++)
if (code == keyboard_layout_list[i].country_code)
{
keyboard = keyboard_layout_list[i].keyboard_map;
one. */
if (code == -1)
{
- if (sc >= (sizeof (ibmpc_translate_map) / sizeof (short)))
+ if (sc >= ARRAYELTS (ibmpc_translate_map))
continue;
if ((code = ibmpc_translate_map[sc]) == Ignore)
continue;
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;
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;
windows_msg.time = GetMessageTime ();
TranslateMessage (&windows_msg);
}
- count = get_wm_chars (hwnd, buf, sizeof (buf)/sizeof (*buf), 1,
+ count = get_wm_chars (hwnd, buf, ARRAYELTS (buf), 1,
/* The message may have been synthesized by
who knows what; be conservative. */
modifier_set (VK_LCONTROL)
file_details_w->lStructSize = sizeof (*file_details_w);
/* Set up the inout parameter for the selected file name. */
file_details_w->lpstrFile = filename_buf_w;
- file_details_w->nMaxFile =
- sizeof (filename_buf_w) / sizeof (*filename_buf_w);
+ file_details_w->nMaxFile = ARRAYELTS (filename_buf_w);
file_details_w->hwndOwner = FRAME_W32_WINDOW (f);
/* Undocumented Bug in Common File Dialog:
If a filter is not specified, shell links are not resolved. */
else
file_details_a->lStructSize = sizeof (*file_details_a);
file_details_a->lpstrFile = filename_buf_a;
- file_details_a->nMaxFile =
- sizeof (filename_buf_a) / sizeof (*filename_buf_a);
+ file_details_a->nMaxFile = ARRAYELTS (filename_buf_a);
file_details_a->hwndOwner = FRAME_W32_WINDOW (f);
file_details_a->lpstrFilter = filter_a;
file_details_a->lpstrInitialDir = dir_a;
record_event (char *locus, int type)
{
- if (event_record_index == sizeof (event_record) / sizeof (struct record))
+ if (event_record_index == ARRAYELTS (event_record))
event_record_index = 0;
event_record[event_record_index].locus = locus;
hlinfo->mouse_face_hidden = true;
}
- if (temp_index == sizeof temp_buffer / sizeof (short))
+ if (temp_index == ARRAYELTS (temp_buffer))
temp_index = 0;
temp_buffer[temp_index++] = msg.msg.wParam;
inev.kind = NON_ASCII_KEYSTROKE_EVENT;
hlinfo->mouse_face_hidden = true;
}
- if (temp_index == sizeof temp_buffer / sizeof (short))
+ if (temp_index == ARRAYELTS (temp_buffer))
temp_index = 0;
temp_buffer[temp_index++] = msg.msg.wParam;
hlinfo->mouse_face_hidden = true;
}
- if (temp_index == sizeof temp_buffer / sizeof (short))
+ if (temp_index == ARRAYELTS (temp_buffer))
temp_index = 0;
temp_buffer[temp_index++] = msg.msg.wParam;
inev.kind = MULTIMEDIA_KEY_EVENT;