emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r114585: Fix minor problems found by static checking


From: Paul Eggert
Subject: [Emacs-diffs] trunk r114585: Fix minor problems found by static checking.
Date: Tue, 08 Oct 2013 20:04:44 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114585
revision-id: address@hidden
parent: address@hidden
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Tue 2013-10-08 13:04:40 -0700
message:
  Fix minor problems found by static checking.
  
  * dispnew.c (save_current_matrix): Omit unnecessary casts.
  * dispnew.c (update_frame_with_menu): Mark debug local as used.
  * keyboard.c, keyboard.h (Qmouse_movement): Now static.
  * keyboard.c (read_menu_command): Remove unused local.
  * lisp.h (read_menu_command): New decl.
  * menu.c, menu.h (menu_item_width): Arg is now unsigned char *, for
  benefit of STRING_CHAR_AND_LENGTH.  All uses changed.
  Return ptrdiff_t, not int.
  * term.c (tty_menu_struct): 'allocated' member is now ptrdiff_t,
  not int, for benefit of xpalloc.
  (tty_menu_create, tty_menu_make_room): Simplify by using xzalloc
  and xpalloc.
  (have_menus_p): Remove; unused.
  (tty_menu_add_pane, tty_menu_add_selection): Change signedness of
  local char * pointer to pacify STRING_CHAR_AND_LENGTH.
  (tty_menu_add_selection, tty_menu_locate, tty_meny_destroy):
  Now static.
  (save_and_enable_current_matrix): Omit unnecessary casts.
  (read_menu_input): Omit local extern decl (now in lisp.h).
  Don't access uninitialized storage if mouse_get_xy fails.
  (tty_menu_activate): Mark local as initialized, for lint.
  (tty_menu_activate, tty_meny_show): Remove unused locals.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/dispnew.c                  dispnew.c-20091113204419-o5vbwnq5f7feedwu-258
  src/keyboard.c                 keyboard.c-20091113204419-o5vbwnq5f7feedwu-449
  src/keyboard.h                 keyboard.h-20091113204419-o5vbwnq5f7feedwu-450
  src/lisp.h                     lisp.h-20091113204419-o5vbwnq5f7feedwu-253
  src/menu.c                     menu.c-20091113204419-o5vbwnq5f7feedwu-8676
  src/menu.h                     menu.h-20091113204419-o5vbwnq5f7feedwu-8702
  src/term.c                     term.c-20091113204419-o5vbwnq5f7feedwu-220
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-10-08 17:49:20 +0000
+++ b/src/ChangeLog     2013-10-08 20:04:40 +0000
@@ -1,3 +1,29 @@
+2013-10-08  Paul Eggert  <address@hidden>
+
+       Fix minor problems found by static checking.
+       * dispnew.c (save_current_matrix): Omit unnecessary casts.
+       * dispnew.c (update_frame_with_menu): Mark debug local as used.
+       * keyboard.c, keyboard.h (Qmouse_movement): Now static.
+       * keyboard.c (read_menu_command): Remove unused local.
+       * lisp.h (read_menu_command): New decl.
+       * menu.c, menu.h (menu_item_width): Arg is now unsigned char *, for
+       benefit of STRING_CHAR_AND_LENGTH.  All uses changed.
+       Return ptrdiff_t, not int.
+       * term.c (tty_menu_struct): 'allocated' member is now ptrdiff_t,
+       not int, for benefit of xpalloc.
+       (tty_menu_create, tty_menu_make_room): Simplify by using xzalloc
+       and xpalloc.
+       (have_menus_p): Remove; unused.
+       (tty_menu_add_pane, tty_menu_add_selection): Change signedness of
+       local char * pointer to pacify STRING_CHAR_AND_LENGTH.
+       (tty_menu_add_selection, tty_menu_locate, tty_meny_destroy):
+       Now static.
+       (save_and_enable_current_matrix): Omit unnecessary casts.
+       (read_menu_input): Omit local extern decl (now in lisp.h).
+       Don't access uninitialized storage if mouse_get_xy fails.
+       (tty_menu_activate): Mark local as initialized, for lint.
+       (tty_menu_activate, tty_meny_show): Remove unused locals.
+
 2013-10-08  Eli Zaretskii  <address@hidden>
 
        Support menus on text-mode terminals.

=== modified file 'src/dispnew.c'
--- a/src/dispnew.c     2013-10-08 17:49:20 +0000
+++ b/src/dispnew.c     2013-10-08 20:04:40 +0000
@@ -1853,7 +1853,7 @@
       if (from->used[LEFT_MARGIN_AREA])
        {
          nbytes = from->used[LEFT_MARGIN_AREA] * sizeof (struct glyph);
-         to->glyphs[LEFT_MARGIN_AREA] = (struct glyph *) xmalloc (nbytes);
+         to->glyphs[LEFT_MARGIN_AREA] = xmalloc (nbytes);
          memcpy (to->glyphs[LEFT_MARGIN_AREA],
                  from->glyphs[LEFT_MARGIN_AREA], nbytes);
          to->used[LEFT_MARGIN_AREA] = from->used[LEFT_MARGIN_AREA];
@@ -1861,7 +1861,7 @@
       if (from->used[RIGHT_MARGIN_AREA])
        {
          nbytes = from->used[RIGHT_MARGIN_AREA] * sizeof (struct glyph);
-         to->glyphs[RIGHT_MARGIN_AREA] = (struct glyph *) xmalloc (nbytes);
+         to->glyphs[RIGHT_MARGIN_AREA] = xmalloc (nbytes);
          memcpy (to->glyphs[RIGHT_MARGIN_AREA],
                  from->glyphs[RIGHT_MARGIN_AREA], nbytes);
          to->used[RIGHT_MARGIN_AREA] = from->used[RIGHT_MARGIN_AREA];
@@ -3123,6 +3123,8 @@
   check_window_matrix_pointers (root_window);
 #endif
   add_frame_display_history (f, paused_p);
+#else
+  IF_LINT ((void) paused_p);
 #endif
 
   /* Reset flags indicating that a window should be updated.  */

=== modified file 'src/keyboard.c'
--- a/src/keyboard.c    2013-10-08 17:49:20 +0000
+++ b/src/keyboard.c    2013-10-08 20:04:40 +0000
@@ -289,7 +289,7 @@
    at inopportune times.  */
 
 /* Symbols to head events.  */
-Lisp_Object Qmouse_movement;
+static Lisp_Object Qmouse_movement;
 static Lisp_Object Qscroll_bar_movement;
 Lisp_Object Qswitch_frame;
 static Lisp_Object Qfocus_in, Qfocus_out;
@@ -1696,7 +1696,6 @@
 Lisp_Object
 read_menu_command (void)
 {
-  Lisp_Object cmd;
   Lisp_Object keybuf[30];
   ptrdiff_t count = SPECPDL_INDEX ();
   int i;

=== modified file 'src/keyboard.h'
--- a/src/keyboard.h    2013-09-26 07:37:16 +0000
+++ b/src/keyboard.h    2013-10-08 20:04:40 +0000
@@ -450,7 +450,7 @@
 extern Lisp_Object Qevent_kind;
 
 /* The values of Qevent_kind properties.  */
-extern Lisp_Object Qmouse_click, Qmouse_movement;
+extern Lisp_Object Qmouse_click;
 
 extern Lisp_Object Qhelp_echo;
 

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2013-10-08 04:25:33 +0000
+++ b/src/lisp.h        2013-10-08 20:04:40 +0000
@@ -3905,6 +3905,7 @@
 extern void safe_run_hooks (Lisp_Object);
 extern void cmd_error_internal (Lisp_Object, const char *);
 extern Lisp_Object command_loop_1 (void);
+extern Lisp_Object read_menu_command (void);
 extern Lisp_Object recursive_edit_1 (void);
 extern void record_auto_save (void);
 extern void force_auto_save_soon (void);

=== modified file 'src/menu.c'
--- a/src/menu.c        2013-10-08 14:28:37 +0000
+++ b/src/menu.c        2013-10-08 20:04:40 +0000
@@ -1036,11 +1036,11 @@
 }
 #endif  /* HAVE_NS */
 
-int
-menu_item_width (const char *str)
+ptrdiff_t
+menu_item_width (const unsigned char *str)
 {
-  int len;
-  const char *p;
+  ptrdiff_t len;
+  const unsigned char *p;
 
   for (len = 0, p = str; *p; )
     {
@@ -1104,7 +1104,7 @@
          if (XINT (pos) <= col
              /* We use <= so the blank between 2 items on a TTY is
                 considered part of the previous item.  */
-             && col <= XINT (pos) + menu_item_width (SSDATA (str)))
+             && col <= XINT (pos) + menu_item_width (SDATA (str)))
            {
              item = AREF (items, i);
              return item;

=== modified file 'src/menu.h'
--- a/src/menu.h        2013-10-08 14:28:37 +0000
+++ b/src/menu.h        2013-10-08 20:04:40 +0000
@@ -53,5 +53,5 @@
                               Lisp_Object, const char **, Time);
 extern Lisp_Object tty_menu_show (struct frame *, int, int, int, int,
                                  Lisp_Object, int, const char **);
-extern int menu_item_width (const char *);
+extern ptrdiff_t menu_item_width (const unsigned char *);
 #endif /* MENU_H */

=== modified file 'src/term.c'
--- a/src/term.c        2013-10-08 19:06:40 +0000
+++ b/src/term.c        2013-10-08 20:04:40 +0000
@@ -2814,7 +2814,7 @@
   char **text;
   struct tty_menu_struct **submenu;
   int *panenumber; /* Also used as enabled flag.  */
-  int allocated;
+  ptrdiff_t allocated;
   int panecount;
   int width;
   const char **help_text;
@@ -2825,38 +2825,27 @@
 static tty_menu *
 tty_menu_create (void)
 {
-  tty_menu *menu;
-
-  menu = (tty_menu *) xmalloc (sizeof (tty_menu));
-  menu->allocated = menu->count = menu->panecount = menu->width = 0;
-  return menu;
+  return xzalloc (sizeof *tty_menu_create ());
 }
 
 /* Allocate some (more) memory for MENU ensuring that there is room for one
-   for item.  */
+   more item.  */
 
 static void
 tty_menu_make_room (tty_menu *menu)
 {
-  if (menu->allocated == 0)
-    {
-      int count = menu->allocated = 10;
-      menu->text = (char **) xmalloc (count * sizeof (char *));
-      menu->submenu = (tty_menu **) xmalloc (count * sizeof (tty_menu *));
-      menu->panenumber = (int *) xmalloc (count * sizeof (int));
-      menu->help_text = (const char **) xmalloc (count * sizeof (char *));
-    }
-  else if (menu->allocated == menu->count)
-    {
-      int count = menu->allocated = menu->allocated + 10;
-      menu->text
-       = (char **) xrealloc (menu->text, count * sizeof (char *));
-      menu->submenu
-       = (tty_menu **) xrealloc (menu->submenu, count * sizeof (tty_menu *));
-      menu->panenumber
-       = (int *) xrealloc (menu->panenumber, count * sizeof (int));
-      menu->help_text
-       = (const char **) xrealloc (menu->help_text, count * sizeof (char *));
+  if (menu->allocated == menu->count)
+    {
+      ptrdiff_t allocated = menu->allocated;
+      menu->text = xpalloc (menu->text, &allocated, 1, -1, sizeof *menu->text);
+      menu->text = xrealloc (menu->text, allocated * sizeof *menu->text);
+      menu->submenu = xrealloc (menu->submenu,
+                               allocated * sizeof *menu->submenu);
+      menu->panenumber = xrealloc (menu->panenumber,
+                                  allocated * sizeof *menu->panenumber);
+      menu->help_text = xrealloc (menu->help_text,
+                                 allocated * sizeof *menu->help_text);
+      menu->allocated = allocated;
     }
 }
 
@@ -2965,18 +2954,13 @@
 
 /* --------------------------- X Menu emulation ---------------------- */
 
-/* Report availability of menus.  */
-
-int
-have_menus_p (void) {  return 1; }
-
 /* Create a new pane and place it on the outer-most level.  */
 
 static int
 tty_menu_add_pane (tty_menu *menu, const char *txt)
 {
   int len;
-  const char *p;
+  const unsigned char *p;
 
   tty_menu_make_room (menu);
   menu->submenu[menu->count] = tty_menu_create ();
@@ -2986,7 +2970,7 @@
   menu->count++;
 
   /* Update the menu width, if necessary.  */
-  for (len = 0, p = txt; *p; )
+  for (len = 0, p = (unsigned char *) txt; *p; )
     {
       int ch_len;
       int ch = STRING_CHAR_AND_LENGTH (p, ch_len);
@@ -3003,12 +2987,12 @@
 
 /* Create a new item in a menu pane.  */
 
-int
+static int
 tty_menu_add_selection (tty_menu *menu, int pane,
                        char *txt, int enable, char const *help_text)
 {
   int len;
-  char *p;
+  unsigned char *p;
 
   if (pane)
     if (!(menu = tty_menu_search_pane (menu, pane)))
@@ -3021,7 +3005,7 @@
   menu->count++;
 
   /* Update the menu width, if necessary.  */
-  for (len = 0, p = txt; *p; )
+  for (len = 0, p = (unsigned char *) txt; *p; )
     {
       int ch_len;
       int ch = STRING_CHAR_AND_LENGTH (p, ch_len);
@@ -3038,7 +3022,7 @@
 
 /* Decide where the menu would be placed if requested at (X,Y).  */
 
-void
+static void
 tty_menu_locate (tty_menu *menu, int x, int y,
                 int *ulx, int *uly, int *width, int *height)
 {
@@ -3085,7 +3069,7 @@
       if (from->used[LEFT_MARGIN_AREA])
        {
          nbytes = from->used[LEFT_MARGIN_AREA] * sizeof (struct glyph);
-         to->glyphs[LEFT_MARGIN_AREA] = (struct glyph *) xmalloc (nbytes);
+         to->glyphs[LEFT_MARGIN_AREA] = xmalloc (nbytes);
          memcpy (to->glyphs[LEFT_MARGIN_AREA],
                  from->glyphs[LEFT_MARGIN_AREA], nbytes);
          to->used[LEFT_MARGIN_AREA] = from->used[LEFT_MARGIN_AREA];
@@ -3093,7 +3077,7 @@
       if (from->used[RIGHT_MARGIN_AREA])
        {
          nbytes = from->used[RIGHT_MARGIN_AREA] * sizeof (struct glyph);
-         to->glyphs[RIGHT_MARGIN_AREA] = (struct glyph *) xmalloc (nbytes);
+         to->glyphs[RIGHT_MARGIN_AREA] = xmalloc (nbytes);
          memcpy (to->glyphs[RIGHT_MARGIN_AREA],
                  from->glyphs[RIGHT_MARGIN_AREA], nbytes);
          to->used[RIGHT_MARGIN_AREA] = from->used[RIGHT_MARGIN_AREA];
@@ -3194,7 +3178,6 @@
     }
   else
     {
-      extern Lisp_Object read_menu_command (void);
       Lisp_Object cmd;
       int usable_input = 1;
       int st = 0;
@@ -3215,13 +3198,7 @@
       if (EQ (cmd, Qt) || EQ (cmd, Qtty_menu_exit))
        return -1;
       if (EQ (cmd, Qtty_menu_mouse_movement))
-       {
-         int mx, my;
-
-         mouse_get_xy (&mx, &my);
-         *x = mx;
-         *y = my;
-       }
+       mouse_get_xy (x, y);
       else if (EQ (cmd, Qtty_menu_next_menu))
        {
          usable_input = 0;
@@ -3261,13 +3238,14 @@
                   int kbd_navigation)
 {
   struct tty_menu_state *state;
-  int statecount, x, y, i, b, leave, result, onepane;
+  int statecount, x, y, i, leave, onepane;
+  int result IF_LINT (= 0);
   int title_faces[4];          /* face to display the menu title */
   int faces[4], buffers_num_deleted = 0;
   struct frame *sf = SELECTED_FRAME ();
   struct tty_display_info *tty = FRAME_TTY (sf);
   bool first_time;
-  Lisp_Object saved_echo_area_message, selectface;
+  Lisp_Object selectface;
 
   /* Don't allow non-positive x0 and y0, lest the menu will wrap
      around the display.  */
@@ -3465,7 +3443,7 @@
 
 /* Dispose of a menu.  */
 
-void
+static void
 tty_menu_destroy (tty_menu *menu)
 {
   int i;
@@ -3576,7 +3554,7 @@
          if (ix <= *x
              /* We use <= so the blank between 2 items on a TTY is
                 considered part of the previous item.  */
-             && *x <= ix + menu_item_width (SSDATA (str)))
+             && *x <= ix + menu_item_width (SDATA (str)))
            {
              /* Found current item.  Now compute the X coordinate of
                 the previous or next item.  */
@@ -3614,8 +3592,6 @@
   int dispwidth, dispheight;
   int i, j, lines, maxlines;
   int maxwidth;
-  int dummy_int;
-  unsigned int dummy_uint;
   ptrdiff_t specpdl_count = SPECPDL_INDEX ();
 
   if (! FRAME_TERMCAP_P (f))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]