]> git.eshelyaron.com Git - emacs.git/commitdiff
Clean up array size calculations
authorDaniel Colascione <dancol@dancol.org>
Thu, 3 Apr 2014 07:14:02 +0000 (00:14 -0700)
committerDaniel Colascione <dancol@dancol.org>
Thu, 3 Apr 2014 07:14:02 +0000 (00:14 -0700)
22 files changed:
src/ChangeLog
src/chartab.c
src/dired.c
src/dosfns.c
src/emacs.c
src/fileio.c
src/frame.c
src/fringe.c
src/image.c
src/keyboard.c
src/macfont.m
src/msdos.c
src/nsfns.m
src/nsterm.m
src/sysdep.c
src/term.c
src/unexcw.c
src/w32.c
src/w32fns.c
src/xfaces.c
src/xfns.c
src/xterm.c

index 72449dc52afc0488a35f0fee2ee825429626587e..a628148bbda5bb1550900ee4fc1c100a67fbc997 100644 (file)
@@ -1,5 +1,66 @@
 2014-04-03  Daniel Colascione  <dancol@dancol.org>
 
+       In all places below, change expressions of the form sizeof(arr) /
+       sizeof(arr[0]) to EARRAYSIZE(arr).
+
+       * xterm.c (x_term_init): See above.
+
+       * xfns.c (best_xim_style): See above.
+
+       * xfaces.c (Fdump_colors): See above.
+
+       * w32fns.c (w32_default_color_map): See above.
+
+       * w32.c:
+       (init_environment): See above.
+       (N_ENV_VARS): See above.
+
+       * unexcw.c (read_exe_header): See above.
+
+       * term.c (term_get_fkeys_1): See above.
+
+       * sysdep.c (init_baud_rate): See above.
+
+       * nsterm.m (ns_convert_key): See above.
+
+       * nsfns.m (get_geometry_from_preferences): See above.
+
+       * msdos.c (dos_set_window_size): See above.
+       (init_environment): See above.
+
+       * macfont.m (mac_font_get_glyph_for_cid): See above.
+       (macfont_store_descriptor_attributes): See above.
+       (macfont_create_attributes_with_spec): See above.
+       (mac_ctfont_get_glyph_for_cid): See above.
+
+       * keyboard.c (command_loop_1): See above.
+       (read_menu_command): See above.
+       (make_lispy_event): See above.
+       (NUM_MOD_NAMES): See above.
+       (read_key_sequence_vs): See above.
+       (Fcurrent_input_mode): See above.
+       (syms_of_keyboard): See above.
+
+       * image.c (xpm_str_to_color_key): See above.
+
+       * fringe.c (MAX_STANDARD_FRINGE_BITMAPS): See above.
+
+       * frame.c (x_set_frame_parameters): See above.
+
+       * fileio.c (Ffile_selinux_context): See above.
+
+       * emacs.c (sort_args): See above.
+
+       * dosfns.c ():
+       (msdos_stdcolor_name): See above.
+
+       * dired.c (file_attributes): See above.
+
+       * chartab.c:
+       (uniprop_decoder_count,uniprop_encode_count): See above.
+
+2014-04-02  Daniel Colascione  <dancol@dancol.org>
+
        * data.c (Ffset): Abort if we're trying to set a function call to
        a dead lisp object.
 
index 2a8bbc6983a328aa696ae6b5c2fbe20e367b6011..56a6f548749715f7c391dcb730ca55199b454b8b 100644 (file)
@@ -1221,9 +1221,7 @@ uniprop_decode_value_run_length (Lisp_Object table, Lisp_Object value)
 static uniprop_decoder_t uniprop_decoder [] =
   { uniprop_decode_value_run_length };
 
-static int uniprop_decoder_count
-  = (sizeof uniprop_decoder) / sizeof (uniprop_decoder[0]);
-
+static const int uniprop_decoder_count = EARRAYSIZE (uniprop_decoder);
 
 /* Return the decoder of char-table TABLE or nil if none.  */
 
@@ -1301,9 +1299,7 @@ static uniprop_encoder_t uniprop_encoder[] =
     uniprop_encode_value_run_length,
     uniprop_encode_value_numeric };
 
-static int uniprop_encoder_count
-  = (sizeof uniprop_encoder) / sizeof (uniprop_encoder[0]);
-
+static const int uniprop_encoder_count = EARRAYSIZE (uniprop_encoder);
 
 /* Return the encoder of char-table TABLE or nil if none.  */
 
index 69d0ae0429cf25d42b22aaf14a57a4c83e069413..5d99314fde088f3427b1fcf2c7ce82186eee7ef5 100644 (file)
@@ -984,7 +984,7 @@ file_attributes (int fd, char const *name, Lisp_Object id_format)
   values[10] = INTEGER_TO_CONS (s.st_ino);
   values[11] = INTEGER_TO_CONS (s.st_dev);
 
-  return Flist (sizeof (values) / sizeof (values[0]), values);
+  return Flist (EARRAYSIZE (values), values);
 }
 
 DEFUN ("file-attributes-lessp", Ffile_attributes_lessp, Sfile_attributes_lessp, 2, 2, 0,
index 071d73ea16ec249d08322f2f56e781f7b3256faf..b98e3cd8f293ce7b3a28b724e17b57bf0b1937e2 100644 (file)
@@ -402,7 +402,7 @@ msdos_stdcolor_idx (const char *name)
 {
   int i;
 
-  for (i = 0; i < sizeof (vga_colors) / sizeof (vga_colors[0]); i++)
+  for (i = 0; i < EARRAYSIZE (vga_colors); i++)
     if (xstrcasecmp (name, vga_colors[i]) == 0)
       return i;
 
@@ -422,7 +422,7 @@ msdos_stdcolor_name (int idx)
     return build_string (unspecified_fg);
   else if (idx == FACE_TTY_DEFAULT_BG_COLOR)
     return build_string (unspecified_bg);
-  else if (idx >= 0 && idx < sizeof (vga_colors) / sizeof (vga_colors[0]))
+  else if (idx >= 0 && idx < EARRAYSIZE (vga_colors))
     return build_string (vga_colors[idx]);
   else
     return Qunspecified;       /* meaning the default */
index 56096016d416fe7737a6b06c35ddd8cb90c91e38..a481a9c3d7f38644d35ea0346745b6c3452c2913 100644 (file)
@@ -1817,7 +1817,7 @@ sort_args (int argc, char **argv)
            }
 
          /* Look for a match with a known old-fashioned option.  */
-         for (i = 0; i < sizeof (standard_args) / sizeof (standard_args[0]); i++)
+         for (i = 0; i < EARRAYSIZE (standard_args); i++)
            if (!strcmp (argv[from], standard_args[i].name))
              {
                options[from] = standard_args[i].nargs;
@@ -1839,8 +1839,7 @@ sort_args (int argc, char **argv)
 
              match = -1;
 
-             for (i = 0;
-                  i < sizeof (standard_args) / sizeof (standard_args[0]); i++)
+             for (i = 0; i < EARRAYSIZE (standard_args); i++)
                if (standard_args[i].longname
                    && !strncmp (argv[from], standard_args[i].longname,
                                 thislen))
index 4d27b58d2b7cd4671627ddb46e8aa07fd6856565..d317e169c26717122ee235b1f3f86c762733f190 100644 (file)
@@ -2909,7 +2909,7 @@ or if SELinux is disabled, or if Emacs lacks SELinux support.  */)
     }
 #endif
 
-  return Flist (sizeof (values) / sizeof (values[0]), values);
+  return Flist (EARRAYSIZE (values), values);
 }
 \f
 DEFUN ("set-file-selinux-context", Fset_file_selinux_context,
index c5a2f6ab245dbcf66495c2b3d09295d4a160174c..3784e998753777cf87b4edca1164763c01fb3475 100644 (file)
@@ -2867,8 +2867,7 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist)
 
              param_index = Fget (prop, Qx_frame_parameter);
              if (NATNUMP (param_index)
-                 && (XFASTINT (param_index)
-                     < sizeof (frame_parms)/sizeof (frame_parms[0]))
+                 && XFASTINT (param_index) < EARRAYSIZE (frame_parms)
                   && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
                 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
            }
@@ -2916,8 +2915,7 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist)
 
          param_index = Fget (prop, Qx_frame_parameter);
          if (NATNUMP (param_index)
-             && (XFASTINT (param_index)
-                 < sizeof (frame_parms)/sizeof (frame_parms[0]))
+             && XFASTINT (param_index) < EARRAYSIZE (frame_parms)
              && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
            (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
        }
@@ -3228,8 +3226,7 @@ x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
     {
       Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
       if (NATNUMP (parm_index)
-         && (XFASTINT (parm_index)
-             < sizeof (frame_parms)/sizeof (frame_parms[0]))
+         && XFASTINT (parm_index) < EARRAYSIZE (frame_parms)
          && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
          (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
            (f, bgcolor, Qnil);
@@ -4563,7 +4560,7 @@ syms_of_frame (void)
   {
     int i;
 
-    for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
+    for (i = 0; i < EARRAYSIZE (frame_parms); i++)
       {
        Lisp_Object v = intern_c_string (frame_parms[i].name);
        if (frame_parms[i].variable)
index 6325de4128ecedea90dd8c21b946c23661e00635..1dd95341857bba309a29b5ca3308656b9bfd5cb8 100644 (file)
@@ -474,7 +474,7 @@ static struct fringe_bitmap standard_bitmaps[] =
 
 #define NO_FRINGE_BITMAP 0
 #define UNDEF_FRINGE_BITMAP 1
-#define MAX_STANDARD_FRINGE_BITMAPS (sizeof (standard_bitmaps)/sizeof (standard_bitmaps[0]))
+#define MAX_STANDARD_FRINGE_BITMAPS EARRAYSIZE (standard_bitmaps)
 
 static struct fringe_bitmap **fringe_bitmaps;
 static Lisp_Object *fringe_faces;
index 29a04e7da81c1e8c2864f6a61cb92a5b9534ee05..64bd41b52ab3afd1c33cc53fba51bcb035442fd7 100644 (file)
@@ -3955,9 +3955,7 @@ xpm_str_to_color_key (const char *s)
 {
   int i;
 
-  for (i = 0;
-       i < sizeof xpm_color_key_strings / sizeof xpm_color_key_strings[0];
-       i++)
+  for (i = 0; i < EARRAYSIZE (xpm_color_key_strings); i++)
     if (strcmp (xpm_color_key_strings[i], s) == 0)
       return i;
   return -1;
index 439a40f8762196aa1f7321dab61c739359668221..ccdb469bbb31f8ec00451a52a39c923e936f86b6 100644 (file)
@@ -1446,7 +1446,7 @@ command_loop_1 (void)
       Vthis_command_keys_shift_translated = Qnil;
 
       /* Read next key sequence; i gets its length.  */
-      i = read_key_sequence (keybuf, sizeof keybuf / sizeof keybuf[0],
+      i = read_key_sequence (keybuf, EARRAYSIZE (keybuf),
                             Qnil, 0, 1, 1, 0);
 
       /* A filter may have run while we were reading the input.  */
@@ -1694,7 +1694,7 @@ read_menu_command (void)
      menus.  */
   specbind (Qecho_keystrokes, make_number (0));
 
-  i = read_key_sequence (keybuf, sizeof keybuf / sizeof keybuf[0],
+  i = read_key_sequence (keybuf, EARRAYSIZE (keybuf),
                         Qnil, 0, 1, 1, 1);
 
   unbind_to (count, Qnil);
@@ -5484,8 +5484,7 @@ make_lispy_event (struct input_event *event)
                                      event->modifiers,
                                      Qfunction_key, Qnil,
                                      lispy_accent_keys, &accent_key_syms,
-                                     (sizeof (lispy_accent_keys)
-                                      / sizeof (lispy_accent_keys[0])));
+                                      EARRAYSIZE (lispy_accent_keys));
 
 #if 0
 #ifdef XK_kana_A
@@ -5494,8 +5493,7 @@ make_lispy_event (struct input_event *event)
                                    event->modifiers & ~shift_modifier,
                                    Qfunction_key, Qnil,
                                    lispy_kana_keys, &func_key_syms,
-                                   (sizeof (lispy_kana_keys)
-                                    / sizeof (lispy_kana_keys[0])));
+                                    EARRAYSIZE (lispy_kana_keys));
 #endif /* XK_kana_A */
 #endif /* 0 */
 
@@ -5506,8 +5504,7 @@ make_lispy_event (struct input_event *event)
                                    event->modifiers,
                                    Qfunction_key, Qnil,
                                    iso_lispy_function_keys, &func_key_syms,
-                                   (sizeof (iso_lispy_function_keys)
-                                    / sizeof (iso_lispy_function_keys[0])));
+                                    EARRAYSIZE (iso_lispy_function_keys));
 #endif
 
       /* Handle system-specific or unknown keysyms.  */
@@ -5533,20 +5530,17 @@ make_lispy_event (struct input_event *event)
                                  event->modifiers,
                                  Qfunction_key, Qnil,
                                  lispy_function_keys, &func_key_syms,
-                                 (sizeof (lispy_function_keys)
-                                  / sizeof (lispy_function_keys[0])));
+                                  EARRAYSIZE (lispy_function_keys));
 
 #ifdef HAVE_NTGUI
     case MULTIMEDIA_KEY_EVENT:
-      if (event->code < (sizeof (lispy_multimedia_keys)
-                         / sizeof (lispy_multimedia_keys[0]))
+      if (event->code < EARRAYSIZE (lispy_multimedia_keys)
           && event->code > 0 && lispy_multimedia_keys[event->code])
         {
           return modify_event_symbol (event->code, event->modifiers,
                                       Qfunction_key, Qnil,
                                       lispy_multimedia_keys, &func_key_syms,
-                                      (sizeof (lispy_multimedia_keys)
-                                       / sizeof (lispy_multimedia_keys[0])));
+                                      EARRAYSIZE (lispy_multimedia_keys));
         }
       return Qnil;
 #endif
@@ -6268,7 +6262,7 @@ static const char *const modifier_names[] =
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, "alt", "super", "hyper", "shift", "control", "meta"
 };
-#define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
+#define NUM_MOD_NAMES EARRAYSIZE (modifier_names)
 
 static Lisp_Object modifier_symbols;
 
@@ -9758,7 +9752,7 @@ read_key_sequence_vs (Lisp_Object prompt, Lisp_Object continue_echo,
 
   memset (keybuf, 0, sizeof keybuf);
   GCPRO1 (keybuf[0]);
-  gcpro1.nvars = (sizeof keybuf / sizeof (keybuf[0]));
+  gcpro1.nvars = EARRAYSIZE (keybuf);
 
   if (NILP (continue_echo))
     {
@@ -9772,7 +9766,7 @@ read_key_sequence_vs (Lisp_Object prompt, Lisp_Object continue_echo,
     cancel_hourglass ();
 #endif
 
-  i = read_key_sequence (keybuf, (sizeof keybuf / sizeof (keybuf[0])),
+  i = read_key_sequence (keybuf, EARRAYSIZE (keybuf),
                         prompt, ! NILP (dont_downcase_last),
                         ! NILP (can_return_switch_frame), 0, 0);
 
@@ -10675,7 +10669,7 @@ The elements of this list correspond to the arguments of
     }
   XSETFASTINT (val[3], quit_char);
 
-  return Flist (sizeof (val) / sizeof (val[0]), val);
+  return Flist (EARRAYSIZE (val), val);
 }
 
 DEFUN ("posn-at-x-y", Fposn_at_x_y, Sposn_at_x_y, 2, 4, 0,
@@ -11043,7 +11037,7 @@ syms_of_keyboard (void)
 
   {
     int i;
-    int len = sizeof (head_table) / sizeof (head_table[0]);
+    int len = EARRAYSIZE (head_table);
 
     for (i = 0; i < len; i++)
       {
@@ -11059,14 +11053,13 @@ syms_of_keyboard (void)
   staticpro (&button_down_location);
   mouse_syms = Fmake_vector (make_number (5), Qnil);
   staticpro (&mouse_syms);
-  wheel_syms = Fmake_vector (make_number (sizeof (lispy_wheel_names)
-                                         / sizeof (lispy_wheel_names[0])),
+  wheel_syms = Fmake_vector (make_number (EARRAYSIZE (lispy_wheel_names)),
                             Qnil);
   staticpro (&wheel_syms);
 
   {
     int i;
-    int len = sizeof (modifier_names) / sizeof (modifier_names[0]);
+    int len = EARRAYSIZE (modifier_names);
 
     modifier_symbols = Fmake_vector (make_number (len), Qnil);
     for (i = 0; i < len; i++)
index 075b512e68624cb96621c8311e945e8c6f974a11..447b08c723d5e23b6dc0b13492ecba2cba99c3b5 100644 (file)
@@ -237,8 +237,7 @@ mac_font_get_glyph_for_cid (FontRef font, CharacterCollection collection,
     unichar characters[] = {0xfffd};
     NSString *string =
       [NSString stringWithCharacters:characters
-                             length:(sizeof (characters)
-                                     / sizeof (characters[0]))];
+                             length:EARRAYSIZE (characters)];
     NSGlyphInfo *glyphInfo =
       [NSGlyphInfo glyphInfoWithCharacterIdentifier:cid
                                         collection:collection
@@ -826,7 +825,7 @@ macfont_store_descriptor_attributes (FontDescriptorRef desc,
            {{0, 100}, {1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}};
       int i;
 
-      for (i = 0; i < sizeof (numeric_traits) / sizeof (numeric_traits[0]); i++)
+      for (i = 0; i < EARRAYSIZE (numeric_traits); i++)
        {
          num = CFDictionaryGetValue (dict, numeric_traits[i].trait);
          if (num && CFNumberGetValue (num, kCFNumberCGFloatType, &floatval))
@@ -1908,7 +1907,7 @@ macfont_create_attributes_with_spec (Lisp_Object spec)
   if (! traits)
     goto err;
 
-  for (i = 0; i < sizeof (numeric_traits) / sizeof (numeric_traits[0]); i++)
+  for (i = 0; i < EARRAYSIZE (numeric_traits); i++)
     {
       tmp = AREF (spec, numeric_traits[i].index);
       if (INTEGERP (tmp))
@@ -3584,7 +3583,7 @@ mac_ctfont_create_line_with_string_and_font (CFStringRef string,
     {
       attributes = CFDictionaryCreate (NULL, (const void **) keys,
                                       (const void **) values,
-                                      sizeof (keys) / sizeof (keys[0]),
+                                       EARRAYSIZE (keys),
                                       &kCFTypeDictionaryKeyCallBacks,
                                       &kCFTypeDictionaryValueCallBacks);
       CFRelease (values[1]);
@@ -3795,8 +3794,8 @@ mac_ctfont_get_glyph_for_cid (CTFontRef font, CTCharacterCollection collection,
   CTLineRef ctline = NULL;
 
   string = CFStringCreateWithCharacters (NULL, characters,
-                                        sizeof (characters)
-                                        / sizeof (characters[0]));
+                                         EARRAYSIZE (characters));
+
   if (string)
     {
       CTGlyphInfoRef glyph_info =
@@ -3811,7 +3810,7 @@ mac_ctfont_get_glyph_for_cid (CTFontRef font, CTCharacterCollection collection,
 
          attributes = CFDictionaryCreate (NULL, (const void **) keys,
                                           (const void **) values,
-                                          sizeof (keys) / sizeof (keys[0]),
+                                           EARRAYSIZE (keys),
                                           &kCFTypeDictionaryKeyCallBacks,
                                           &kCFTypeDictionaryValueCallBacks);
          CFRelease (glyph_info);
index 1af66b391ad846dd80acc6671a831f294ffbeef2..2b636977f61805b1c90498180eedf4385b3ed55b 100644 (file)
@@ -564,7 +564,7 @@ dos_set_window_size (int *rows, int *cols)
       };
       int i = 0;
 
-      while (i < sizeof (std_dimension) / sizeof (std_dimension[0]))
+      while (i < EARRAYSIZE (std_dimension))
        {
         if (std_dimension[i].need_vga <= have_vga
             && std_dimension[i].rows >= *rows)
@@ -3465,7 +3465,7 @@ init_environment (int argc, char **argv, int skip_args)
   static const char * const tempdirs[] = {
     "$TMPDIR", "$TEMP", "$TMP", "c:/"
   };
-  const int imax = sizeof (tempdirs) / sizeof (tempdirs[0]);
+  const int imax = EARRAYSIZE (tempdirs);
 
   /* Make sure they have a usable $TMPDIR.  Many Emacs functions use
      temporary files and assume "/tmp" if $TMPDIR is unset, which
index 58746aed9faeedf3d99d1941e69097d0e2b245a5..d1692915bc7642212bf5ef08cc45421e1a396fa5 100644 (file)
@@ -1024,7 +1024,7 @@ get_geometry_from_preferences (struct ns_display_info *dpyinfo,
   };
 
   int i;
-  for (i = 0; i < sizeof (r)/sizeof (r[0]); ++i)
+  for (i = 0; i < EARRAYSIZE (r); ++i)
     {
       if (NILP (Fassq (r[i].tem, parms)))
         {
index c7cb4faa3b787854d8931b8dfdca9bde545467ad..fb4d402814093d35318e71a3b91fc23e0b87666d 100644 (file)
@@ -2012,8 +2012,7 @@ ns_convert_key (unsigned code)
     Internal call used by NSView-keyDown.
    -------------------------------------------------------------------------- */
 {
-  const unsigned last_keysym = (sizeof (convert_ns_to_X_keysym)
-                                / sizeof (convert_ns_to_X_keysym[0]));
+  const unsigned last_keysym = EARRAYSIZE (convert_ns_to_X_keysym);
   unsigned keysym;
   /* An array would be faster, but less easy to read. */
   for (keysym = 0; keysym < last_keysym; keysym += 2)
index b33900062aea73ad808f8b978883f71292e7f858..f1608c4ab21528f9fd5b5a6d661d848d1f942f35 100644 (file)
@@ -255,7 +255,7 @@ init_baud_rate (int fd)
 #endif /* not DOS_NT */
     }
 
-  baud_rate = (emacs_ospeed < sizeof baud_convert / sizeof baud_convert[0]
+  baud_rate = (emacs_ospeed < EARRAYSIZE (baud_convert)
               ? baud_convert[emacs_ospeed] : 9600);
   if (baud_rate == 0)
     baud_rate = 1200;
index df5fc17a0c092e8642aabb926650c209fb88d8f6..600c16ba8205df083133e5655fe0cc2e09c918a8 100644 (file)
@@ -1339,7 +1339,7 @@ term_get_fkeys_1 (void)
   if (!KEYMAPP (KVAR (kboard, Vinput_decode_map)))
     kset_input_decode_map (kboard, Fmake_sparse_keymap (Qnil));
 
-  for (i = 0; i < (sizeof (keys) / sizeof (keys[0])); i++)
+  for (i = 0; i < EARRAYSIZE (keys); i++)
     {
       char *sequence = tgetstr (keys[i].cap, address);
       if (sequence)
index 25d13ca0ca466b32a241f5b2f379e77e84eae795..1809961a80102d76a70d5356976e73f55306594a 100644 (file)
@@ -81,8 +81,7 @@ read_exe_header (int fd, exe_header_t * exe_header_buffer)
 #endif
   assert (exe_header_buffer->file_header.f_nscns > 0);
   assert (exe_header_buffer->file_header.f_nscns <=
-         sizeof (exe_header_buffer->section_header) /
-         sizeof (exe_header_buffer->section_header[0]));
+          EARRAYSIZE (exe_header_buffer->section_header));
   assert (exe_header_buffer->file_header.f_opthdr > 0);
 
   ret =
index 95092daa83a7e6916f4db53e6f09043f502b19b6..e0fd60b1d20067be0f461a7b38ecb7d9c526d593 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -1707,7 +1707,7 @@ static unsigned num_of_processors;
 /* We maintain 1-sec samples for the last 16 minutes in a circular buffer.  */
 static struct load_sample samples[16*60];
 static int first_idx = -1, last_idx = -1;
-static int max_idx = sizeof (samples) / sizeof (samples[0]);
+static int max_idx = EARRAYSIZE (samples);
 
 static int
 buf_next (int from)
@@ -2511,7 +2511,7 @@ init_environment (char ** argv)
 
   int i;
 
-  const int imax = sizeof (tempdirs) / sizeof (tempdirs[0]);
+  const int imax = EARRAYSIZE (tempdirs);
 
   /* Implementation note: This function explicitly works with ANSI
      file names, not with UTF-8 encoded file names.  This is because
@@ -2584,7 +2584,7 @@ init_environment (char ** argv)
       {"LANG", NULL},
     };
 
-#define N_ENV_VARS sizeof (dflt_envvars)/sizeof (dflt_envvars[0])
+#define N_ENV_VARS EARRAYSIZE (dflt_envvars)
 
     /* We need to copy dflt_envvars[] and work on the copy because we
        don't want the dumped Emacs to inherit the values of
index 080771f4cca22fd730ab6f137d3c6c1b0d50d253..3c366022770a7e630bab0e1c8382326e3a274d26 100644 (file)
@@ -723,8 +723,7 @@ w32_default_color_map (void)
 
   cmap = Qnil;
 
-  for (i = 0; i < sizeof (w32_color_map) / sizeof (w32_color_map[0]);
-       pc++, i++)
+  for (i = 0; i < EARRAYSIZE (w32_color_map); pc++, i++)
     cmap = Fcons (Fcons (build_string (pc->name),
                         make_number (pc->colorref)),
                  cmap);
index 4271e47c36f8eb72cfed1295f4734ab7f8cf5583..bae315b28112e9570ffc2811202bb0d51068ad5f 100644 (file)
@@ -515,7 +515,7 @@ DEFUN ("dump-colors", Fdump_colors, Sdump_colors, 0, 0, 0,
 
   fputc ('\n', stderr);
 
-  for (i = n = 0; i < sizeof color_count / sizeof color_count[0]; ++i)
+  for (i = n = 0; i < EARRAYSIZE (color_count); ++i)
     if (color_count[i])
       {
        fprintf (stderr, "%3d: %5d", i, color_count[i]);
index 692504ef762891080ec1b53eea94ec66a98bb84d..ef827b552521838f10bc673b58b75d28901fb069 100644 (file)
@@ -1944,8 +1944,7 @@ static XIMStyle
 best_xim_style (XIMStyles *xim)
 {
   int i, j;
-  int nr_supported =
-    sizeof (supported_xim_styles) / sizeof (supported_xim_styles[0]);
+  int nr_supported = EARRAYSIZE (supported_xim_styles);
 
   for (i = 0; i < nr_supported; ++i)
     for (j = 0; j < xim->count_styles; ++j)
index 8c4e78073dddbd8add818f0119bdbd8a2db7f7d0..ee8fce047de18dfd7c35761f05a201d0df375f72 100644 (file)
@@ -10103,7 +10103,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
     };
 
     int i;
-    const int atom_count = sizeof (atom_refs) / sizeof (atom_refs[0]);
+    const int atom_count = EARRAYSIZE (atom_refs);
     /* 1 for _XSETTINGS_SN  */
     const int total_atom_count = 1 + atom_count;
     Atom *atoms_return = xmalloc (total_atom_count * sizeof *atoms_return);