From 345bc61796b4f0712fa45d47ed14692c0de628ea Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 23 Nov 2015 20:08:01 +0200 Subject: [PATCH] Improve how non-ASCII strings are accepted from modules * src/emacs-module.c (module_make_function, module_make_string): Build a unibyte Lisp string and then decode it by UTF-8, instead of building a multibyte string without decoding. This is more tolerant to deviations from UTF-8. --- src/emacs-module.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/emacs-module.c b/src/emacs-module.c index 643633935ca..a24d85537bd 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -393,10 +393,8 @@ module_make_function (emacs_env *env, ptrdiff_t min_arity, ptrdiff_t max_arity, else { ptrdiff_t nbytes = strlen (documentation); - ptrdiff_t nchars, ignored_nbytes; - parse_str_as_multibyte ((unsigned char const *) documentation, nbytes, - &nchars, &ignored_nbytes); - doc = make_multibyte_string (documentation, nchars, nbytes); + doc = make_unibyte_string (documentation, nbytes); + doc = code_convert_string_norecord (doc, Qutf_8, false); } Lisp_Object ret = list4 (Qlambda, @@ -555,8 +553,7 @@ module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer, } *length = required_buf_size; - memcpy (buffer, SDATA (lisp_str_utf8), raw_size); - buffer[raw_size] = 0; + memcpy (buffer, SDATA (lisp_str_utf8), raw_size + 1); return true; } @@ -572,10 +569,9 @@ module_make_string (emacs_env *env, const char *str, ptrdiff_t length) module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil); return NULL; } - ptrdiff_t nchars, ignored_nbytes; - parse_str_as_multibyte ((unsigned char const *) str, length, - &nchars, &ignored_nbytes); - return lisp_to_value (env, make_multibyte_string (str, nchars, length)); + Lisp_Object lstr = make_unibyte_string (str, length); + return lisp_to_value (env, + code_convert_string_norecord (lstr, Qutf_8, false)); } static emacs_value -- 2.39.2