aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Colascione2014-04-03 00:14:02 -0700
committerDaniel Colascione2014-04-03 00:14:02 -0700
commit705cf384bec23354ad22a5c48d3430a96ef70ca1 (patch)
tree1615876bc7abad32f5e41ea34c5cd1747466798a /src
parent3a9e7a49deea49088a773c321e52185e922748d6 (diff)
downloademacs-705cf384bec23354ad22a5c48d3430a96ef70ca1.tar.gz
emacs-705cf384bec23354ad22a5c48d3430a96ef70ca1.zip
Clean up array size calculations
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog61
-rw-r--r--src/chartab.c8
-rw-r--r--src/dired.c2
-rw-r--r--src/dosfns.c4
-rw-r--r--src/emacs.c5
-rw-r--r--src/fileio.c2
-rw-r--r--src/frame.c11
-rw-r--r--src/fringe.c2
-rw-r--r--src/image.c4
-rw-r--r--src/keyboard.c37
-rw-r--r--src/macfont.m15
-rw-r--r--src/msdos.c4
-rw-r--r--src/nsfns.m2
-rw-r--r--src/nsterm.m3
-rw-r--r--src/sysdep.c2
-rw-r--r--src/term.c2
-rw-r--r--src/unexcw.c3
-rw-r--r--src/w32.c6
-rw-r--r--src/w32fns.c3
-rw-r--r--src/xfaces.c2
-rw-r--r--src/xfns.c3
-rw-r--r--src/xterm.c2
22 files changed, 111 insertions, 72 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 72449dc52af..a628148bbda 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,66 @@
12014-04-03 Daniel Colascione <dancol@dancol.org> 12014-04-03 Daniel Colascione <dancol@dancol.org>
2 2
3 In all places below, change expressions of the form sizeof(arr) /
4 sizeof(arr[0]) to EARRAYSIZE(arr).
5
6 * xterm.c (x_term_init): See above.
7
8 * xfns.c (best_xim_style): See above.
9
10 * xfaces.c (Fdump_colors): See above.
11
12 * w32fns.c (w32_default_color_map): See above.
13
14 * w32.c:
15 (init_environment): See above.
16 (N_ENV_VARS): See above.
17
18 * unexcw.c (read_exe_header): See above.
19
20 * term.c (term_get_fkeys_1): See above.
21
22 * sysdep.c (init_baud_rate): See above.
23
24 * nsterm.m (ns_convert_key): See above.
25
26 * nsfns.m (get_geometry_from_preferences): See above.
27
28 * msdos.c (dos_set_window_size): See above.
29 (init_environment): See above.
30
31 * macfont.m (mac_font_get_glyph_for_cid): See above.
32 (macfont_store_descriptor_attributes): See above.
33 (macfont_create_attributes_with_spec): See above.
34 (mac_ctfont_get_glyph_for_cid): See above.
35
36 * keyboard.c (command_loop_1): See above.
37 (read_menu_command): See above.
38 (make_lispy_event): See above.
39 (NUM_MOD_NAMES): See above.
40 (read_key_sequence_vs): See above.
41 (Fcurrent_input_mode): See above.
42 (syms_of_keyboard): See above.
43
44 * image.c (xpm_str_to_color_key): See above.
45
46 * fringe.c (MAX_STANDARD_FRINGE_BITMAPS): See above.
47
48 * frame.c (x_set_frame_parameters): See above.
49
50 * fileio.c (Ffile_selinux_context): See above.
51
52 * emacs.c (sort_args): See above.
53
54 * dosfns.c ():
55 (msdos_stdcolor_name): See above.
56
57 * dired.c (file_attributes): See above.
58
59 * chartab.c:
60 (uniprop_decoder_count,uniprop_encode_count): See above.
61
622014-04-02 Daniel Colascione <dancol@dancol.org>
63
3 * data.c (Ffset): Abort if we're trying to set a function call to 64 * data.c (Ffset): Abort if we're trying to set a function call to
4 a dead lisp object. 65 a dead lisp object.
5 66
diff --git a/src/chartab.c b/src/chartab.c
index 2a8bbc6983a..56a6f548749 100644
--- a/src/chartab.c
+++ b/src/chartab.c
@@ -1221,9 +1221,7 @@ uniprop_decode_value_run_length (Lisp_Object table, Lisp_Object value)
1221static uniprop_decoder_t uniprop_decoder [] = 1221static uniprop_decoder_t uniprop_decoder [] =
1222 { uniprop_decode_value_run_length }; 1222 { uniprop_decode_value_run_length };
1223 1223
1224static int uniprop_decoder_count 1224static const int uniprop_decoder_count = EARRAYSIZE (uniprop_decoder);
1225 = (sizeof uniprop_decoder) / sizeof (uniprop_decoder[0]);
1226
1227 1225
1228/* Return the decoder of char-table TABLE or nil if none. */ 1226/* Return the decoder of char-table TABLE or nil if none. */
1229 1227
@@ -1301,9 +1299,7 @@ static uniprop_encoder_t uniprop_encoder[] =
1301 uniprop_encode_value_run_length, 1299 uniprop_encode_value_run_length,
1302 uniprop_encode_value_numeric }; 1300 uniprop_encode_value_numeric };
1303 1301
1304static int uniprop_encoder_count 1302static const int uniprop_encoder_count = EARRAYSIZE (uniprop_encoder);
1305 = (sizeof uniprop_encoder) / sizeof (uniprop_encoder[0]);
1306
1307 1303
1308/* Return the encoder of char-table TABLE or nil if none. */ 1304/* Return the encoder of char-table TABLE or nil if none. */
1309 1305
diff --git a/src/dired.c b/src/dired.c
index 69d0ae0429c..5d99314fde0 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -984,7 +984,7 @@ file_attributes (int fd, char const *name, Lisp_Object id_format)
984 values[10] = INTEGER_TO_CONS (s.st_ino); 984 values[10] = INTEGER_TO_CONS (s.st_ino);
985 values[11] = INTEGER_TO_CONS (s.st_dev); 985 values[11] = INTEGER_TO_CONS (s.st_dev);
986 986
987 return Flist (sizeof (values) / sizeof (values[0]), values); 987 return Flist (EARRAYSIZE (values), values);
988} 988}
989 989
990DEFUN ("file-attributes-lessp", Ffile_attributes_lessp, Sfile_attributes_lessp, 2, 2, 0, 990DEFUN ("file-attributes-lessp", Ffile_attributes_lessp, Sfile_attributes_lessp, 2, 2, 0,
diff --git a/src/dosfns.c b/src/dosfns.c
index 071d73ea16e..b98e3cd8f29 100644
--- a/src/dosfns.c
+++ b/src/dosfns.c
@@ -402,7 +402,7 @@ msdos_stdcolor_idx (const char *name)
402{ 402{
403 int i; 403 int i;
404 404
405 for (i = 0; i < sizeof (vga_colors) / sizeof (vga_colors[0]); i++) 405 for (i = 0; i < EARRAYSIZE (vga_colors); i++)
406 if (xstrcasecmp (name, vga_colors[i]) == 0) 406 if (xstrcasecmp (name, vga_colors[i]) == 0)
407 return i; 407 return i;
408 408
@@ -422,7 +422,7 @@ msdos_stdcolor_name (int idx)
422 return build_string (unspecified_fg); 422 return build_string (unspecified_fg);
423 else if (idx == FACE_TTY_DEFAULT_BG_COLOR) 423 else if (idx == FACE_TTY_DEFAULT_BG_COLOR)
424 return build_string (unspecified_bg); 424 return build_string (unspecified_bg);
425 else if (idx >= 0 && idx < sizeof (vga_colors) / sizeof (vga_colors[0])) 425 else if (idx >= 0 && idx < EARRAYSIZE (vga_colors))
426 return build_string (vga_colors[idx]); 426 return build_string (vga_colors[idx]);
427 else 427 else
428 return Qunspecified; /* meaning the default */ 428 return Qunspecified; /* meaning the default */
diff --git a/src/emacs.c b/src/emacs.c
index 56096016d41..a481a9c3d7f 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1817,7 +1817,7 @@ sort_args (int argc, char **argv)
1817 } 1817 }
1818 1818
1819 /* Look for a match with a known old-fashioned option. */ 1819 /* Look for a match with a known old-fashioned option. */
1820 for (i = 0; i < sizeof (standard_args) / sizeof (standard_args[0]); i++) 1820 for (i = 0; i < EARRAYSIZE (standard_args); i++)
1821 if (!strcmp (argv[from], standard_args[i].name)) 1821 if (!strcmp (argv[from], standard_args[i].name))
1822 { 1822 {
1823 options[from] = standard_args[i].nargs; 1823 options[from] = standard_args[i].nargs;
@@ -1839,8 +1839,7 @@ sort_args (int argc, char **argv)
1839 1839
1840 match = -1; 1840 match = -1;
1841 1841
1842 for (i = 0; 1842 for (i = 0; i < EARRAYSIZE (standard_args); i++)
1843 i < sizeof (standard_args) / sizeof (standard_args[0]); i++)
1844 if (standard_args[i].longname 1843 if (standard_args[i].longname
1845 && !strncmp (argv[from], standard_args[i].longname, 1844 && !strncmp (argv[from], standard_args[i].longname,
1846 thislen)) 1845 thislen))
diff --git a/src/fileio.c b/src/fileio.c
index 4d27b58d2b7..d317e169c26 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2909,7 +2909,7 @@ or if SELinux is disabled, or if Emacs lacks SELinux support. */)
2909 } 2909 }
2910#endif 2910#endif
2911 2911
2912 return Flist (sizeof (values) / sizeof (values[0]), values); 2912 return Flist (EARRAYSIZE (values), values);
2913} 2913}
2914 2914
2915DEFUN ("set-file-selinux-context", Fset_file_selinux_context, 2915DEFUN ("set-file-selinux-context", Fset_file_selinux_context,
diff --git a/src/frame.c b/src/frame.c
index c5a2f6ab245..3784e998753 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -2867,8 +2867,7 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist)
2867 2867
2868 param_index = Fget (prop, Qx_frame_parameter); 2868 param_index = Fget (prop, Qx_frame_parameter);
2869 if (NATNUMP (param_index) 2869 if (NATNUMP (param_index)
2870 && (XFASTINT (param_index) 2870 && XFASTINT (param_index) < EARRAYSIZE (frame_parms)
2871 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2872 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)]) 2871 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2873 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value); 2872 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2874 } 2873 }
@@ -2916,8 +2915,7 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist)
2916 2915
2917 param_index = Fget (prop, Qx_frame_parameter); 2916 param_index = Fget (prop, Qx_frame_parameter);
2918 if (NATNUMP (param_index) 2917 if (NATNUMP (param_index)
2919 && (XFASTINT (param_index) 2918 && XFASTINT (param_index) < EARRAYSIZE (frame_parms)
2920 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2921 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)]) 2919 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2922 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value); 2920 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2923 } 2921 }
@@ -3228,8 +3226,7 @@ x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
3228 { 3226 {
3229 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter); 3227 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3230 if (NATNUMP (parm_index) 3228 if (NATNUMP (parm_index)
3231 && (XFASTINT (parm_index) 3229 && XFASTINT (parm_index) < EARRAYSIZE (frame_parms)
3232 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3233 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)]) 3230 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3234 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)]) 3231 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3235 (f, bgcolor, Qnil); 3232 (f, bgcolor, Qnil);
@@ -4563,7 +4560,7 @@ syms_of_frame (void)
4563 { 4560 {
4564 int i; 4561 int i;
4565 4562
4566 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++) 4563 for (i = 0; i < EARRAYSIZE (frame_parms); i++)
4567 { 4564 {
4568 Lisp_Object v = intern_c_string (frame_parms[i].name); 4565 Lisp_Object v = intern_c_string (frame_parms[i].name);
4569 if (frame_parms[i].variable) 4566 if (frame_parms[i].variable)
diff --git a/src/fringe.c b/src/fringe.c
index 6325de4128e..1dd95341857 100644
--- a/src/fringe.c
+++ b/src/fringe.c
@@ -474,7 +474,7 @@ static struct fringe_bitmap standard_bitmaps[] =
474 474
475#define NO_FRINGE_BITMAP 0 475#define NO_FRINGE_BITMAP 0
476#define UNDEF_FRINGE_BITMAP 1 476#define UNDEF_FRINGE_BITMAP 1
477#define MAX_STANDARD_FRINGE_BITMAPS (sizeof (standard_bitmaps)/sizeof (standard_bitmaps[0])) 477#define MAX_STANDARD_FRINGE_BITMAPS EARRAYSIZE (standard_bitmaps)
478 478
479static struct fringe_bitmap **fringe_bitmaps; 479static struct fringe_bitmap **fringe_bitmaps;
480static Lisp_Object *fringe_faces; 480static Lisp_Object *fringe_faces;
diff --git a/src/image.c b/src/image.c
index 29a04e7da81..64bd41b52ab 100644
--- a/src/image.c
+++ b/src/image.c
@@ -3955,9 +3955,7 @@ xpm_str_to_color_key (const char *s)
3955{ 3955{
3956 int i; 3956 int i;
3957 3957
3958 for (i = 0; 3958 for (i = 0; i < EARRAYSIZE (xpm_color_key_strings); i++)
3959 i < sizeof xpm_color_key_strings / sizeof xpm_color_key_strings[0];
3960 i++)
3961 if (strcmp (xpm_color_key_strings[i], s) == 0) 3959 if (strcmp (xpm_color_key_strings[i], s) == 0)
3962 return i; 3960 return i;
3963 return -1; 3961 return -1;
diff --git a/src/keyboard.c b/src/keyboard.c
index 439a40f8762..ccdb469bbb3 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1446,7 +1446,7 @@ command_loop_1 (void)
1446 Vthis_command_keys_shift_translated = Qnil; 1446 Vthis_command_keys_shift_translated = Qnil;
1447 1447
1448 /* Read next key sequence; i gets its length. */ 1448 /* Read next key sequence; i gets its length. */
1449 i = read_key_sequence (keybuf, sizeof keybuf / sizeof keybuf[0], 1449 i = read_key_sequence (keybuf, EARRAYSIZE (keybuf),
1450 Qnil, 0, 1, 1, 0); 1450 Qnil, 0, 1, 1, 0);
1451 1451
1452 /* A filter may have run while we were reading the input. */ 1452 /* A filter may have run while we were reading the input. */
@@ -1694,7 +1694,7 @@ read_menu_command (void)
1694 menus. */ 1694 menus. */
1695 specbind (Qecho_keystrokes, make_number (0)); 1695 specbind (Qecho_keystrokes, make_number (0));
1696 1696
1697 i = read_key_sequence (keybuf, sizeof keybuf / sizeof keybuf[0], 1697 i = read_key_sequence (keybuf, EARRAYSIZE (keybuf),
1698 Qnil, 0, 1, 1, 1); 1698 Qnil, 0, 1, 1, 1);
1699 1699
1700 unbind_to (count, Qnil); 1700 unbind_to (count, Qnil);
@@ -5484,8 +5484,7 @@ make_lispy_event (struct input_event *event)
5484 event->modifiers, 5484 event->modifiers,
5485 Qfunction_key, Qnil, 5485 Qfunction_key, Qnil,
5486 lispy_accent_keys, &accent_key_syms, 5486 lispy_accent_keys, &accent_key_syms,
5487 (sizeof (lispy_accent_keys) 5487 EARRAYSIZE (lispy_accent_keys));
5488 / sizeof (lispy_accent_keys[0])));
5489 5488
5490#if 0 5489#if 0
5491#ifdef XK_kana_A 5490#ifdef XK_kana_A
@@ -5494,8 +5493,7 @@ make_lispy_event (struct input_event *event)
5494 event->modifiers & ~shift_modifier, 5493 event->modifiers & ~shift_modifier,
5495 Qfunction_key, Qnil, 5494 Qfunction_key, Qnil,
5496 lispy_kana_keys, &func_key_syms, 5495 lispy_kana_keys, &func_key_syms,
5497 (sizeof (lispy_kana_keys) 5496 EARRAYSIZE (lispy_kana_keys));
5498 / sizeof (lispy_kana_keys[0])));
5499#endif /* XK_kana_A */ 5497#endif /* XK_kana_A */
5500#endif /* 0 */ 5498#endif /* 0 */
5501 5499
@@ -5506,8 +5504,7 @@ make_lispy_event (struct input_event *event)
5506 event->modifiers, 5504 event->modifiers,
5507 Qfunction_key, Qnil, 5505 Qfunction_key, Qnil,
5508 iso_lispy_function_keys, &func_key_syms, 5506 iso_lispy_function_keys, &func_key_syms,
5509 (sizeof (iso_lispy_function_keys) 5507 EARRAYSIZE (iso_lispy_function_keys));
5510 / sizeof (iso_lispy_function_keys[0])));
5511#endif 5508#endif
5512 5509
5513 /* Handle system-specific or unknown keysyms. */ 5510 /* Handle system-specific or unknown keysyms. */
@@ -5533,20 +5530,17 @@ make_lispy_event (struct input_event *event)
5533 event->modifiers, 5530 event->modifiers,
5534 Qfunction_key, Qnil, 5531 Qfunction_key, Qnil,
5535 lispy_function_keys, &func_key_syms, 5532 lispy_function_keys, &func_key_syms,
5536 (sizeof (lispy_function_keys) 5533 EARRAYSIZE (lispy_function_keys));
5537 / sizeof (lispy_function_keys[0])));
5538 5534
5539#ifdef HAVE_NTGUI 5535#ifdef HAVE_NTGUI
5540 case MULTIMEDIA_KEY_EVENT: 5536 case MULTIMEDIA_KEY_EVENT:
5541 if (event->code < (sizeof (lispy_multimedia_keys) 5537 if (event->code < EARRAYSIZE (lispy_multimedia_keys)
5542 / sizeof (lispy_multimedia_keys[0]))
5543 && event->code > 0 && lispy_multimedia_keys[event->code]) 5538 && event->code > 0 && lispy_multimedia_keys[event->code])
5544 { 5539 {
5545 return modify_event_symbol (event->code, event->modifiers, 5540 return modify_event_symbol (event->code, event->modifiers,
5546 Qfunction_key, Qnil, 5541 Qfunction_key, Qnil,
5547 lispy_multimedia_keys, &func_key_syms, 5542 lispy_multimedia_keys, &func_key_syms,
5548 (sizeof (lispy_multimedia_keys) 5543 EARRAYSIZE (lispy_multimedia_keys));
5549 / sizeof (lispy_multimedia_keys[0])));
5550 } 5544 }
5551 return Qnil; 5545 return Qnil;
5552#endif 5546#endif
@@ -6268,7 +6262,7 @@ static const char *const modifier_names[] =
6268 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6262 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6269 0, 0, "alt", "super", "hyper", "shift", "control", "meta" 6263 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
6270}; 6264};
6271#define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0])) 6265#define NUM_MOD_NAMES EARRAYSIZE (modifier_names)
6272 6266
6273static Lisp_Object modifier_symbols; 6267static Lisp_Object modifier_symbols;
6274 6268
@@ -9758,7 +9752,7 @@ read_key_sequence_vs (Lisp_Object prompt, Lisp_Object continue_echo,
9758 9752
9759 memset (keybuf, 0, sizeof keybuf); 9753 memset (keybuf, 0, sizeof keybuf);
9760 GCPRO1 (keybuf[0]); 9754 GCPRO1 (keybuf[0]);
9761 gcpro1.nvars = (sizeof keybuf / sizeof (keybuf[0])); 9755 gcpro1.nvars = EARRAYSIZE (keybuf);
9762 9756
9763 if (NILP (continue_echo)) 9757 if (NILP (continue_echo))
9764 { 9758 {
@@ -9772,7 +9766,7 @@ read_key_sequence_vs (Lisp_Object prompt, Lisp_Object continue_echo,
9772 cancel_hourglass (); 9766 cancel_hourglass ();
9773#endif 9767#endif
9774 9768
9775 i = read_key_sequence (keybuf, (sizeof keybuf / sizeof (keybuf[0])), 9769 i = read_key_sequence (keybuf, EARRAYSIZE (keybuf),
9776 prompt, ! NILP (dont_downcase_last), 9770 prompt, ! NILP (dont_downcase_last),
9777 ! NILP (can_return_switch_frame), 0, 0); 9771 ! NILP (can_return_switch_frame), 0, 0);
9778 9772
@@ -10675,7 +10669,7 @@ The elements of this list correspond to the arguments of
10675 } 10669 }
10676 XSETFASTINT (val[3], quit_char); 10670 XSETFASTINT (val[3], quit_char);
10677 10671
10678 return Flist (sizeof (val) / sizeof (val[0]), val); 10672 return Flist (EARRAYSIZE (val), val);
10679} 10673}
10680 10674
10681DEFUN ("posn-at-x-y", Fposn_at_x_y, Sposn_at_x_y, 2, 4, 0, 10675DEFUN ("posn-at-x-y", Fposn_at_x_y, Sposn_at_x_y, 2, 4, 0,
@@ -11043,7 +11037,7 @@ syms_of_keyboard (void)
11043 11037
11044 { 11038 {
11045 int i; 11039 int i;
11046 int len = sizeof (head_table) / sizeof (head_table[0]); 11040 int len = EARRAYSIZE (head_table);
11047 11041
11048 for (i = 0; i < len; i++) 11042 for (i = 0; i < len; i++)
11049 { 11043 {
@@ -11059,14 +11053,13 @@ syms_of_keyboard (void)
11059 staticpro (&button_down_location); 11053 staticpro (&button_down_location);
11060 mouse_syms = Fmake_vector (make_number (5), Qnil); 11054 mouse_syms = Fmake_vector (make_number (5), Qnil);
11061 staticpro (&mouse_syms); 11055 staticpro (&mouse_syms);
11062 wheel_syms = Fmake_vector (make_number (sizeof (lispy_wheel_names) 11056 wheel_syms = Fmake_vector (make_number (EARRAYSIZE (lispy_wheel_names)),
11063 / sizeof (lispy_wheel_names[0])),
11064 Qnil); 11057 Qnil);
11065 staticpro (&wheel_syms); 11058 staticpro (&wheel_syms);
11066 11059
11067 { 11060 {
11068 int i; 11061 int i;
11069 int len = sizeof (modifier_names) / sizeof (modifier_names[0]); 11062 int len = EARRAYSIZE (modifier_names);
11070 11063
11071 modifier_symbols = Fmake_vector (make_number (len), Qnil); 11064 modifier_symbols = Fmake_vector (make_number (len), Qnil);
11072 for (i = 0; i < len; i++) 11065 for (i = 0; i < len; i++)
diff --git a/src/macfont.m b/src/macfont.m
index 075b512e686..447b08c723d 100644
--- a/src/macfont.m
+++ b/src/macfont.m
@@ -237,8 +237,7 @@ mac_font_get_glyph_for_cid (FontRef font, CharacterCollection collection,
237 unichar characters[] = {0xfffd}; 237 unichar characters[] = {0xfffd};
238 NSString *string = 238 NSString *string =
239 [NSString stringWithCharacters:characters 239 [NSString stringWithCharacters:characters
240 length:(sizeof (characters) 240 length:EARRAYSIZE (characters)];
241 / sizeof (characters[0]))];
242 NSGlyphInfo *glyphInfo = 241 NSGlyphInfo *glyphInfo =
243 [NSGlyphInfo glyphInfoWithCharacterIdentifier:cid 242 [NSGlyphInfo glyphInfoWithCharacterIdentifier:cid
244 collection:collection 243 collection:collection
@@ -826,7 +825,7 @@ macfont_store_descriptor_attributes (FontDescriptorRef desc,
826 {{0, 100}, {1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}}; 825 {{0, 100}, {1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}};
827 int i; 826 int i;
828 827
829 for (i = 0; i < sizeof (numeric_traits) / sizeof (numeric_traits[0]); i++) 828 for (i = 0; i < EARRAYSIZE (numeric_traits); i++)
830 { 829 {
831 num = CFDictionaryGetValue (dict, numeric_traits[i].trait); 830 num = CFDictionaryGetValue (dict, numeric_traits[i].trait);
832 if (num && CFNumberGetValue (num, kCFNumberCGFloatType, &floatval)) 831 if (num && CFNumberGetValue (num, kCFNumberCGFloatType, &floatval))
@@ -1908,7 +1907,7 @@ macfont_create_attributes_with_spec (Lisp_Object spec)
1908 if (! traits) 1907 if (! traits)
1909 goto err; 1908 goto err;
1910 1909
1911 for (i = 0; i < sizeof (numeric_traits) / sizeof (numeric_traits[0]); i++) 1910 for (i = 0; i < EARRAYSIZE (numeric_traits); i++)
1912 { 1911 {
1913 tmp = AREF (spec, numeric_traits[i].index); 1912 tmp = AREF (spec, numeric_traits[i].index);
1914 if (INTEGERP (tmp)) 1913 if (INTEGERP (tmp))
@@ -3584,7 +3583,7 @@ mac_ctfont_create_line_with_string_and_font (CFStringRef string,
3584 { 3583 {
3585 attributes = CFDictionaryCreate (NULL, (const void **) keys, 3584 attributes = CFDictionaryCreate (NULL, (const void **) keys,
3586 (const void **) values, 3585 (const void **) values,
3587 sizeof (keys) / sizeof (keys[0]), 3586 EARRAYSIZE (keys),
3588 &kCFTypeDictionaryKeyCallBacks, 3587 &kCFTypeDictionaryKeyCallBacks,
3589 &kCFTypeDictionaryValueCallBacks); 3588 &kCFTypeDictionaryValueCallBacks);
3590 CFRelease (values[1]); 3589 CFRelease (values[1]);
@@ -3795,8 +3794,8 @@ mac_ctfont_get_glyph_for_cid (CTFontRef font, CTCharacterCollection collection,
3795 CTLineRef ctline = NULL; 3794 CTLineRef ctline = NULL;
3796 3795
3797 string = CFStringCreateWithCharacters (NULL, characters, 3796 string = CFStringCreateWithCharacters (NULL, characters,
3798 sizeof (characters) 3797 EARRAYSIZE (characters));
3799 / sizeof (characters[0])); 3798
3800 if (string) 3799 if (string)
3801 { 3800 {
3802 CTGlyphInfoRef glyph_info = 3801 CTGlyphInfoRef glyph_info =
@@ -3811,7 +3810,7 @@ mac_ctfont_get_glyph_for_cid (CTFontRef font, CTCharacterCollection collection,
3811 3810
3812 attributes = CFDictionaryCreate (NULL, (const void **) keys, 3811 attributes = CFDictionaryCreate (NULL, (const void **) keys,
3813 (const void **) values, 3812 (const void **) values,
3814 sizeof (keys) / sizeof (keys[0]), 3813 EARRAYSIZE (keys),
3815 &kCFTypeDictionaryKeyCallBacks, 3814 &kCFTypeDictionaryKeyCallBacks,
3816 &kCFTypeDictionaryValueCallBacks); 3815 &kCFTypeDictionaryValueCallBacks);
3817 CFRelease (glyph_info); 3816 CFRelease (glyph_info);
diff --git a/src/msdos.c b/src/msdos.c
index 1af66b391ad..2b636977f61 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -564,7 +564,7 @@ dos_set_window_size (int *rows, int *cols)
564 }; 564 };
565 int i = 0; 565 int i = 0;
566 566
567 while (i < sizeof (std_dimension) / sizeof (std_dimension[0])) 567 while (i < EARRAYSIZE (std_dimension))
568 { 568 {
569 if (std_dimension[i].need_vga <= have_vga 569 if (std_dimension[i].need_vga <= have_vga
570 && std_dimension[i].rows >= *rows) 570 && std_dimension[i].rows >= *rows)
@@ -3465,7 +3465,7 @@ init_environment (int argc, char **argv, int skip_args)
3465 static const char * const tempdirs[] = { 3465 static const char * const tempdirs[] = {
3466 "$TMPDIR", "$TEMP", "$TMP", "c:/" 3466 "$TMPDIR", "$TEMP", "$TMP", "c:/"
3467 }; 3467 };
3468 const int imax = sizeof (tempdirs) / sizeof (tempdirs[0]); 3468 const int imax = EARRAYSIZE (tempdirs);
3469 3469
3470 /* Make sure they have a usable $TMPDIR. Many Emacs functions use 3470 /* Make sure they have a usable $TMPDIR. Many Emacs functions use
3471 temporary files and assume "/tmp" if $TMPDIR is unset, which 3471 temporary files and assume "/tmp" if $TMPDIR is unset, which
diff --git a/src/nsfns.m b/src/nsfns.m
index 58746aed9fa..d1692915bc7 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -1024,7 +1024,7 @@ get_geometry_from_preferences (struct ns_display_info *dpyinfo,
1024 }; 1024 };
1025 1025
1026 int i; 1026 int i;
1027 for (i = 0; i < sizeof (r)/sizeof (r[0]); ++i) 1027 for (i = 0; i < EARRAYSIZE (r); ++i)
1028 { 1028 {
1029 if (NILP (Fassq (r[i].tem, parms))) 1029 if (NILP (Fassq (r[i].tem, parms)))
1030 { 1030 {
diff --git a/src/nsterm.m b/src/nsterm.m
index c7cb4faa3b7..fb4d4028140 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2012,8 +2012,7 @@ ns_convert_key (unsigned code)
2012 Internal call used by NSView-keyDown. 2012 Internal call used by NSView-keyDown.
2013 -------------------------------------------------------------------------- */ 2013 -------------------------------------------------------------------------- */
2014{ 2014{
2015 const unsigned last_keysym = (sizeof (convert_ns_to_X_keysym) 2015 const unsigned last_keysym = EARRAYSIZE (convert_ns_to_X_keysym);
2016 / sizeof (convert_ns_to_X_keysym[0]));
2017 unsigned keysym; 2016 unsigned keysym;
2018 /* An array would be faster, but less easy to read. */ 2017 /* An array would be faster, but less easy to read. */
2019 for (keysym = 0; keysym < last_keysym; keysym += 2) 2018 for (keysym = 0; keysym < last_keysym; keysym += 2)
diff --git a/src/sysdep.c b/src/sysdep.c
index b33900062ae..f1608c4ab21 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -255,7 +255,7 @@ init_baud_rate (int fd)
255#endif /* not DOS_NT */ 255#endif /* not DOS_NT */
256 } 256 }
257 257
258 baud_rate = (emacs_ospeed < sizeof baud_convert / sizeof baud_convert[0] 258 baud_rate = (emacs_ospeed < EARRAYSIZE (baud_convert)
259 ? baud_convert[emacs_ospeed] : 9600); 259 ? baud_convert[emacs_ospeed] : 9600);
260 if (baud_rate == 0) 260 if (baud_rate == 0)
261 baud_rate = 1200; 261 baud_rate = 1200;
diff --git a/src/term.c b/src/term.c
index df5fc17a0c0..600c16ba820 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1339,7 +1339,7 @@ term_get_fkeys_1 (void)
1339 if (!KEYMAPP (KVAR (kboard, Vinput_decode_map))) 1339 if (!KEYMAPP (KVAR (kboard, Vinput_decode_map)))
1340 kset_input_decode_map (kboard, Fmake_sparse_keymap (Qnil)); 1340 kset_input_decode_map (kboard, Fmake_sparse_keymap (Qnil));
1341 1341
1342 for (i = 0; i < (sizeof (keys) / sizeof (keys[0])); i++) 1342 for (i = 0; i < EARRAYSIZE (keys); i++)
1343 { 1343 {
1344 char *sequence = tgetstr (keys[i].cap, address); 1344 char *sequence = tgetstr (keys[i].cap, address);
1345 if (sequence) 1345 if (sequence)
diff --git a/src/unexcw.c b/src/unexcw.c
index 25d13ca0ca4..1809961a801 100644
--- a/src/unexcw.c
+++ b/src/unexcw.c
@@ -81,8 +81,7 @@ read_exe_header (int fd, exe_header_t * exe_header_buffer)
81#endif 81#endif
82 assert (exe_header_buffer->file_header.f_nscns > 0); 82 assert (exe_header_buffer->file_header.f_nscns > 0);
83 assert (exe_header_buffer->file_header.f_nscns <= 83 assert (exe_header_buffer->file_header.f_nscns <=
84 sizeof (exe_header_buffer->section_header) / 84 EARRAYSIZE (exe_header_buffer->section_header));
85 sizeof (exe_header_buffer->section_header[0]));
86 assert (exe_header_buffer->file_header.f_opthdr > 0); 85 assert (exe_header_buffer->file_header.f_opthdr > 0);
87 86
88 ret = 87 ret =
diff --git a/src/w32.c b/src/w32.c
index 95092daa83a..e0fd60b1d20 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -1707,7 +1707,7 @@ static unsigned num_of_processors;
1707/* We maintain 1-sec samples for the last 16 minutes in a circular buffer. */ 1707/* We maintain 1-sec samples for the last 16 minutes in a circular buffer. */
1708static struct load_sample samples[16*60]; 1708static struct load_sample samples[16*60];
1709static int first_idx = -1, last_idx = -1; 1709static int first_idx = -1, last_idx = -1;
1710static int max_idx = sizeof (samples) / sizeof (samples[0]); 1710static int max_idx = EARRAYSIZE (samples);
1711 1711
1712static int 1712static int
1713buf_next (int from) 1713buf_next (int from)
@@ -2511,7 +2511,7 @@ init_environment (char ** argv)
2511 2511
2512 int i; 2512 int i;
2513 2513
2514 const int imax = sizeof (tempdirs) / sizeof (tempdirs[0]); 2514 const int imax = EARRAYSIZE (tempdirs);
2515 2515
2516 /* Implementation note: This function explicitly works with ANSI 2516 /* Implementation note: This function explicitly works with ANSI
2517 file names, not with UTF-8 encoded file names. This is because 2517 file names, not with UTF-8 encoded file names. This is because
@@ -2584,7 +2584,7 @@ init_environment (char ** argv)
2584 {"LANG", NULL}, 2584 {"LANG", NULL},
2585 }; 2585 };
2586 2586
2587#define N_ENV_VARS sizeof (dflt_envvars)/sizeof (dflt_envvars[0]) 2587#define N_ENV_VARS EARRAYSIZE (dflt_envvars)
2588 2588
2589 /* We need to copy dflt_envvars[] and work on the copy because we 2589 /* We need to copy dflt_envvars[] and work on the copy because we
2590 don't want the dumped Emacs to inherit the values of 2590 don't want the dumped Emacs to inherit the values of
diff --git a/src/w32fns.c b/src/w32fns.c
index 080771f4cca..3c366022770 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -723,8 +723,7 @@ w32_default_color_map (void)
723 723
724 cmap = Qnil; 724 cmap = Qnil;
725 725
726 for (i = 0; i < sizeof (w32_color_map) / sizeof (w32_color_map[0]); 726 for (i = 0; i < EARRAYSIZE (w32_color_map); pc++, i++)
727 pc++, i++)
728 cmap = Fcons (Fcons (build_string (pc->name), 727 cmap = Fcons (Fcons (build_string (pc->name),
729 make_number (pc->colorref)), 728 make_number (pc->colorref)),
730 cmap); 729 cmap);
diff --git a/src/xfaces.c b/src/xfaces.c
index 4271e47c36f..bae315b2811 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -515,7 +515,7 @@ DEFUN ("dump-colors", Fdump_colors, Sdump_colors, 0, 0, 0,
515 515
516 fputc ('\n', stderr); 516 fputc ('\n', stderr);
517 517
518 for (i = n = 0; i < sizeof color_count / sizeof color_count[0]; ++i) 518 for (i = n = 0; i < EARRAYSIZE (color_count); ++i)
519 if (color_count[i]) 519 if (color_count[i])
520 { 520 {
521 fprintf (stderr, "%3d: %5d", i, color_count[i]); 521 fprintf (stderr, "%3d: %5d", i, color_count[i]);
diff --git a/src/xfns.c b/src/xfns.c
index 692504ef762..ef827b55252 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1944,8 +1944,7 @@ static XIMStyle
1944best_xim_style (XIMStyles *xim) 1944best_xim_style (XIMStyles *xim)
1945{ 1945{
1946 int i, j; 1946 int i, j;
1947 int nr_supported = 1947 int nr_supported = EARRAYSIZE (supported_xim_styles);
1948 sizeof (supported_xim_styles) / sizeof (supported_xim_styles[0]);
1949 1948
1950 for (i = 0; i < nr_supported; ++i) 1949 for (i = 0; i < nr_supported; ++i)
1951 for (j = 0; j < xim->count_styles; ++j) 1950 for (j = 0; j < xim->count_styles; ++j)
diff --git a/src/xterm.c b/src/xterm.c
index 8c4e78073dd..ee8fce047de 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -10103,7 +10103,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10103 }; 10103 };
10104 10104
10105 int i; 10105 int i;
10106 const int atom_count = sizeof (atom_refs) / sizeof (atom_refs[0]); 10106 const int atom_count = EARRAYSIZE (atom_refs);
10107 /* 1 for _XSETTINGS_SN */ 10107 /* 1 for _XSETTINGS_SN */
10108 const int total_atom_count = 1 + atom_count; 10108 const int total_atom_count = 1 + atom_count;
10109 Atom *atoms_return = xmalloc (total_atom_count * sizeof *atoms_return); 10109 Atom *atoms_return = xmalloc (total_atom_count * sizeof *atoms_return);