From c7602b4e9e074eb8d0fd701d094f1c244713a70f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 6 Feb 2018 15:25:45 -0800 Subject: [PATCH] Fix crashes when run with --no-build-details MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * src/xrdb.c (get_environ_db): * src/xterm.c (same_x_server, x_term_init): Don’t assume Fsystem_name returns a string. --- src/xrdb.c | 19 +++++++++++-------- src/xterm.c | 16 +++++++++++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/xrdb.c b/src/xrdb.c index b55c0f9011..836c147947 100644 --- a/src/xrdb.c +++ b/src/xrdb.c @@ -376,15 +376,18 @@ get_environ_db (void) if (!p) { - /* Use ~/.Xdefaults-HOSTNAME. */ - char *home = gethomedir (); - ptrdiff_t homelen = strlen (home); Lisp_Object system_name = Fsystem_name (); - ptrdiff_t filenamesize = (homelen + sizeof xdefaults - + 1 + SBYTES (system_name)); - p = filename = xrealloc (home, filenamesize); - lispstpcpy (stpcpy (stpcpy (filename + homelen, xdefaults), "-"), - system_name); + if (STRINGP (system_name)) + { + /* Use ~/.Xdefaults-HOSTNAME. */ + char *home = gethomedir (); + ptrdiff_t homelen = strlen (home); + ptrdiff_t filenamesize = (homelen + sizeof xdefaults + + 1 + SBYTES (system_name)); + p = filename = xrealloc (home, filenamesize); + lispstpcpy (stpcpy (stpcpy (filename + homelen, xdefaults), "-"), + system_name); + } } db = XrmGetFileDatabase (p); diff --git a/src/xterm.c b/src/xterm.c index 364a8a8db0..b10664dda9 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -12150,6 +12150,8 @@ same_x_server (const char *name1, const char *name2) { bool seen_colon = false; Lisp_Object sysname = Fsystem_name (); + if (! STRINGP (sysname)) + sysname = empty_unibyte_string; const char *system_name = SSDATA (sysname); ptrdiff_t system_name_length = SBYTES (sysname); ptrdiff_t length_until_period = 0; @@ -12572,15 +12574,19 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) #endif Lisp_Object system_name = Fsystem_name (); - ptrdiff_t nbytes; - if (INT_ADD_WRAPV (SBYTES (Vinvocation_name), SBYTES (system_name) + 2, - &nbytes)) + + ptrdiff_t nbytes = SBYTES (Vinvocation_name) + 1; + if (STRINGP (system_name) + && INT_ADD_WRAPV (nbytes, SBYTES (system_name) + 1, &nbytes)) memory_full (SIZE_MAX); dpyinfo->x_id = ++x_display_id; dpyinfo->x_id_name = xmalloc (nbytes); char *nametail = lispstpcpy (dpyinfo->x_id_name, Vinvocation_name); - *nametail++ = '@'; - lispstpcpy (nametail, system_name); + if (STRINGP (system_name)) + { + *nametail++ = '@'; + lispstpcpy (nametail, system_name); + } /* Figure out which modifier bits mean what. */ x_find_modifier_meanings (dpyinfo); -- 2.14.3