]> code.delx.au - gnu-emacs/commitdiff
Port to pedantic memcpy
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 31 Jul 2015 16:46:45 +0000 (09:46 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 31 Jul 2015 16:47:19 +0000 (09:47 -0700)
* src/keyboard.c (menu_bar_items, tool_bar_items):
* src/xrdb.c (magic_db):
Port to pedantic memcpy implementations that reject memcpy (0, 0, 0).

src/keyboard.c
src/xrdb.c

index 6bd123c67109358d669f70a814a0a2894ef31e1d..91cca8e477e9b1cc3477a5686ee7b256fd9078ff 100644 (file)
@@ -7481,18 +7481,19 @@ menu_bar_items (Lisp_Object old)
           properties may not work reliable, as they are only
           recognized when the menu-bar (or mode-line) is updated,
           which does not normally happen after every command.  */
-       Lisp_Object tem;
-       ptrdiff_t nminor;
-       nminor = current_minor_maps (NULL, &tmaps);
+       ptrdiff_t nminor = current_minor_maps (NULL, &tmaps);
        SAFE_NALLOCA (maps, 1, nminor + 4);
        nmaps = 0;
-       tem = KVAR (current_kboard, Voverriding_terminal_local_map);
+       Lisp_Object tem = KVAR (current_kboard, Voverriding_terminal_local_map);
        if (!NILP (tem) && !NILP (Voverriding_local_map_menu_flag))
          maps[nmaps++] = tem;
        if (tem = get_local_map (PT, current_buffer, Qkeymap), !NILP (tem))
          maps[nmaps++] = tem;
-       memcpy (maps + nmaps, tmaps, nminor * sizeof (maps[0]));
-       nmaps += nminor;
+       if (nminor != 0)
+         {
+           memcpy (maps + nmaps, tmaps, nminor * sizeof (maps[0]));
+           nmaps += nminor;
+         }
        maps[nmaps++] = get_local_map (PT, current_buffer, Qlocal_map);
       }
     maps[nmaps++] = current_global_map;
@@ -8030,18 +8031,19 @@ tool_bar_items (Lisp_Object reuse, int *nitems)
         properties may not work reliable, as they are only
         recognized when the tool-bar (or mode-line) is updated,
         which does not normally happen after every command.  */
-      Lisp_Object tem;
-      ptrdiff_t nminor;
-      nminor = current_minor_maps (NULL, &tmaps);
+      ptrdiff_t nminor = current_minor_maps (NULL, &tmaps);
       SAFE_NALLOCA (maps, 1, nminor + 4);
       nmaps = 0;
-      tem = KVAR (current_kboard, Voverriding_terminal_local_map);
+      Lisp_Object tem = KVAR (current_kboard, Voverriding_terminal_local_map);
       if (!NILP (tem) && !NILP (Voverriding_local_map_menu_flag))
        maps[nmaps++] = tem;
       if (tem = get_local_map (PT, current_buffer, Qkeymap), !NILP (tem))
        maps[nmaps++] = tem;
-      memcpy (maps + nmaps, tmaps, nminor * sizeof (maps[0]));
-      nmaps += nminor;
+      if (nminor != 0)
+       {
+         memcpy (maps + nmaps, tmaps, nminor * sizeof (maps[0]));
+         nmaps += nminor;
+       }
       maps[nmaps++] = get_local_map (PT, current_buffer, Qlocal_map);
     }
 
index 9e85e5a6277e472f47413beb8b9a950e37aadf6f..2235b4535daf7665d66673689af346f08e70a7e2 100644 (file)
@@ -119,8 +119,8 @@ magic_db (const char *string, ptrdiff_t string_len, const char *class,
   while (p < string + string_len)
     {
       /* The chunk we're about to stick on the end of result.  */
-      const char *next = NULL;
-      ptrdiff_t next_len;
+      const char *next = p;
+      ptrdiff_t next_len = 1;
 
       if (*p == '%')
        {
@@ -137,10 +137,13 @@ magic_db (const char *string, ptrdiff_t string_len, const char *class,
                break;
 
              case 'C':
-               next = (x_customization_string
-                       ? x_customization_string
-                       : "");
-               next_len = strlen (next);
+               if (x_customization_string)
+                 {
+                   next = x_customization_string;
+                   next_len = strlen (next);
+                 }
+               else
+                 next_len = 0;
                break;
 
              case 'N':
@@ -176,8 +179,6 @@ magic_db (const char *string, ptrdiff_t string_len, const char *class,
                return NULL;
              }
        }
-      else
-       next = p, next_len = 1;
 
       /* Do we have room for this component followed by a '\0'?  */
       if (path_size - path_len <= next_len)