From: Eli Zaretskii Date: Sat, 6 Jan 2018 16:23:52 +0000 (+0200) Subject: Fix valgrind report in call-interactively X-Git-Tag: emacs-26.0.91~34 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3a22097cf68761aa106a5455409b7eec689efd88;p=emacs.git Fix valgrind report in call-interactively * src/callint.c (Fcall_interactively): Don't try to access more bytes than are available in the interactive spec. (Bug#30004) --- diff --git a/src/callint.c b/src/callint.c index ef228517f17..e4491e9085a 100644 --- a/src/callint.c +++ b/src/callint.c @@ -774,10 +774,23 @@ invoke it. If KEYS is omitted or nil, the return value of if anyone tries to define one here. */ case '+': default: - error ("Invalid control letter `%c' (#o%03o, #x%04x) in interactive calling string", - STRING_CHAR ((unsigned char *) tem), - (unsigned) STRING_CHAR ((unsigned char *) tem), - (unsigned) STRING_CHAR ((unsigned char *) tem)); + { + /* How many bytes are left unprocessed in the specs string? + (Note that this excludes the trailing null byte.) */ + ptrdiff_t bytes_left = SBYTES (specs) - (tem - string); + unsigned letter; + + /* If we have enough bytes left to treat the sequence as a + character, show that character's codepoint; otherwise + show only its first byte. */ + if (bytes_left >= BYTES_BY_CHAR_HEAD (*((unsigned char *) tem))) + letter = STRING_CHAR ((unsigned char *) tem); + else + letter = *((unsigned char *) tem); + + error ("Invalid control letter `%c' (#o%03o, #x%04x) in interactive calling string", + (int) letter, letter, letter); + } } if (varies[i] == 0)