From 75f8653bfe0da39acca9dbcb8b021ad033ac6ae9 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 30 May 2015 11:17:56 -0700 Subject: [PATCH] Don't misencode C-generated messages Also, be more consistent about calls to 'Fmessage' vs 'message'. * src/alloc.c (Fgc_status): Prefer AUTO_STRING to build_string for Fmessage call. * src/data.c (Fmake_variable_buffer_local) (Fmake_local_variable, Fmake_variable_frame_local): * src/doc.c (store_function_docstring): Use Fmessage, not message, since the argument can contain non-ASCII characters, and this can cause the resulting message to be incorrectly encoded for the current environment. * src/fns.c (maybe_resize_hash_table): * src/xselect.c (x_clipboard_manager_save_all): Use message, not Fmessage, since Fmessage's power isn't needed here. * src/process.c (Fmake_network_process): Reword message to avoid %s. * src/xdisp.c (vmessage): Document restrictions on message contents. (message_nolog) [false]: Remove unused code. --- src/alloc.c | 6 +++--- src/data.c | 27 ++++++++++++++++++--------- src/doc.c | 9 +++++++-- src/fns.c | 3 +-- src/process.c | 3 +-- src/xdisp.c | 24 +++++------------------- src/xselect.c | 3 +-- 7 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 030c6e06ba8..14baf291bd8 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -4542,9 +4542,9 @@ DEFUN ("gc-status", Fgc_status, Sgc_status, 0, 0, "", Lisp_Object zombie_list = Qnil; for (int i = 0; i < min (MAX_ZOMBIES, nzombies); i++) zombie_list = Fcons (zombies[i], zombie_list); - return CALLN (Fmessage, - build_string ("%d GCs, avg live/zombies = %.2f/%.2f" - " (%f%%), max %d/%d\nzombies: %S"), + AUTO_STRING (format, ("%d GCs, avg live/zombies = %.2f/%.2f (%f%%)," + " max %d/%d\nzombies: %S")); + return CALLN (Fmessage, format, make_number (ngcs), make_float (avg_live), make_float (avg_zombies), make_float (avg_zombies / avg_live / 100), diff --git a/src/data.c b/src/data.c index c96841aebbf..7bc080fdf84 100644 --- a/src/data.c +++ b/src/data.c @@ -1647,8 +1647,10 @@ The function `default-value' gets the default value and `set-default' sets it. Lisp_Object symbol; XSETSYMBOL (symbol, sym); /* In case `variable' is aliased. */ if (let_shadows_global_binding_p (symbol)) - message ("Making %s buffer-local while let-bound!", - SDATA (SYMBOL_NAME (variable))); + { + AUTO_STRING (format, "Making %s buffer-local while let-bound!"); + CALLN (Fmessage, format, SYMBOL_NAME (variable)); + } } } @@ -1730,9 +1732,11 @@ Instead, use `add-hook' and specify t for the LOCAL argument. */) Lisp_Object symbol; XSETSYMBOL (symbol, sym); /* In case `variable' is aliased. */ if (let_shadows_global_binding_p (symbol)) - message ("Making %s local to %s while let-bound!", - SDATA (SYMBOL_NAME (variable)), - SDATA (BVAR (current_buffer, name))); + { + AUTO_STRING (format, "Making %s local to %s while let-bound!"); + CALLN (Fmessage, format, SYMBOL_NAME (variable), + BVAR (current_buffer, name)); + } } } @@ -1742,8 +1746,11 @@ Instead, use `add-hook' and specify t for the LOCAL argument. */) if (NILP (tem)) { if (let_shadows_buffer_binding_p (sym)) - message ("Making %s buffer-local while locally let-bound!", - SDATA (SYMBOL_NAME (variable))); + { + AUTO_STRING (format, + "Making %s buffer-local while locally let-bound!"); + CALLN (Fmessage, format, SYMBOL_NAME (variable)); + } /* Swap out any local binding for some other buffer, and make sure the current value is permanently recorded, if it's the @@ -1908,8 +1915,10 @@ frame-local bindings). */) Lisp_Object symbol; XSETSYMBOL (symbol, sym); /* In case `variable' is aliased. */ if (let_shadows_global_binding_p (symbol)) - message ("Making %s frame-local while let-bound!", - SDATA (SYMBOL_NAME (variable))); + { + AUTO_STRING (format, "Making %s frame-local while let-bound!"); + CALLN (Fmessage, format, SYMBOL_NAME (variable)); + } } return variable; } diff --git a/src/doc.c b/src/doc.c index 32d65563fd9..f1ba64359a6 100644 --- a/src/doc.c +++ b/src/doc.c @@ -516,8 +516,13 @@ store_function_docstring (Lisp_Object obj, ptrdiff_t offset) if ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_DOC_STRING) ASET (fun, COMPILED_DOC_STRING, make_number (offset)); else - message ("No docstring slot for %s", - SYMBOLP (obj) ? SSDATA (SYMBOL_NAME (obj)) : ""); + { + AUTO_STRING (format, "No docstring slot for %s"); + CALLN (Fmessage, format, + (SYMBOLP (obj) + ? SYMBOL_NAME (obj) + : build_string (""))); + } } } diff --git a/src/fns.c b/src/fns.c index 51f61d23881..939760b7394 100644 --- a/src/fns.c +++ b/src/fns.c @@ -3954,8 +3954,7 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h) #ifdef ENABLE_CHECKING if (HASH_TABLE_P (Vpurify_flag) && XHASH_TABLE (Vpurify_flag) == h) - CALLN (Fmessage, build_string ("Growing hash table to: %d"), - make_number (new_size)); + message ("Growing hash table to: %"pI"d", new_size); #endif set_hash_key_and_value (h, larger_vector (h->key_and_value, diff --git a/src/process.c b/src/process.c index ce78d818e29..bb068943b4a 100644 --- a/src/process.c +++ b/src/process.c @@ -3292,8 +3292,7 @@ usage: (make-network-process &rest ARGS) */) { if (!NILP (host)) { - message (":family local ignores the :host \"%s\" property", - SDATA (host)); + message (":family local ignores the :host property"); contact = Fplist_put (contact, QChost, Qnil); host = Qnil; } diff --git a/src/xdisp.c b/src/xdisp.c index 87f110e667d..358d7b5e4a7 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -10223,7 +10223,11 @@ message_with_string (const char *m, Lisp_Object string, bool log) /* Dump an informative message to the minibuf. If M is 0, clear out - any existing message, and let the mini-buffer text show through. */ + any existing message, and let the mini-buffer text show through. + + The message must be safe ASCII only. If strings may contain escape + sequences or non-ASCII characters, convert them to Lisp strings and + use Fmessage. */ static void ATTRIBUTE_FORMAT_PRINTF (1, 0) vmessage (const char *m, va_list ap) @@ -10291,24 +10295,6 @@ message (const char *m, ...) } -#if false -/* The non-logging version of message. */ - -void -message_nolog (const char *m, ...) -{ - Lisp_Object old_log_max; - va_list ap; - va_start (ap, m); - old_log_max = Vmessage_log_max; - Vmessage_log_max = Qnil; - vmessage (m, ap); - Vmessage_log_max = old_log_max; - va_end (ap); -} -#endif - - /* Display the current message in the current mini-buffer. This is only called from error handlers in process.c, and is not time critical. */ diff --git a/src/xselect.c b/src/xselect.c index 1570c4fef9c..2a865e7cb8c 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -2208,8 +2208,7 @@ x_clipboard_manager_save_all (void) local_frame = XCAR (XCDR (XCDR (XCDR (local_selection)))); if (FRAME_LIVE_P (XFRAME (local_frame))) { - AUTO_STRING (saving, "Saving clipboard to X clipboard manager..."); - Fmessage (1, &saving); + message ("Saving clipboard to X clipboard manager..."); internal_condition_case_1 (x_clipboard_manager_save, local_frame, Qt, x_clipboard_manager_error_2); } -- 2.39.2