From 8a7a99e0280103e223b8e1a717107bdf9b8eabc7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 31 Jul 2015 09:46:45 -0700 Subject: [PATCH] Port to pedantic memcpy * 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 | 26 ++++++++++++++------------ src/xrdb.c | 17 +++++++++-------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index 6bd123c6710..91cca8e477e 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -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); } diff --git a/src/xrdb.c b/src/xrdb.c index 9e85e5a6277..2235b4535da 100644 --- a/src/xrdb.c +++ b/src/xrdb.c @@ -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) -- 2.11.4.GIT