all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: p.stephani2@gmail.com, johnw@gnu.org, schwab@linux-m68k.org,
	24206@debbugs.gnu.org
Subject: bug#24206: 25.1; Curly quotes generate invalid strings, leading to a segfault
Date: Tue, 16 Aug 2016 14:07:05 -0700	[thread overview]
Message-ID: <4822bfeb-c507-a9ff-93bc-1d27ba93b9d7@cs.ucla.edu> (raw)
In-Reply-To: <83d1l8g3zs.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2051 bytes --]

Eli Zaretskii wrote:
> I've reviewed the changes you pushed to master for fixing this bug,
> and I must say that most of them look like purely stylistic changes,
> to make the code more to your personal liking.  The actual bugs were
> very few and minor, and didn't necessitate such thorough changes.

The changes were motivated by bug fixes, not style. Although the bugs were 
mostly minor (e.g., generating bogus NUL bytes due to miscounting) it's fine to 
fix minor bugs. I did change nearby style (indenting as per GNU style, switching 
some locals to C99-style decl-after-statement, etc.) but none of the changes 
were pervasive or were intended for the emacs-25 branch, and it's fine to make 
such changes in master.

One of the bugs was O(N**2) performance when reallocating a temporary buffer. 
While I was at it, I changed the code to allocate a small temp buffer on the 
stack to avoid a malloc/free in the usual case, which should be a small win. 
This accounts for many changes that a quick glance might give the mistaken 
impression of being stylistic.

> without any comments as to why we handle the input string as
> multibyte for the rest of the function, I think this will confuse
> someone down the road.

OK, I added some comments along those lines (see attached patch).

> I think the refactoring already introduced a
> regression.

This comment appears to be about changes made in May for Bug#23425, not about 
code changes I made recently. The May changes were not a regression; they were 
intended and are documented in etc/NEWS. Alan Mackenzie felt strongly that some 
changes were needed in this area. See commit 
433d366dc7b053048abf710d790ff62421dd1570.

> maybe we should just go to the original code, after fixing the
> immediate bugs, as I proposed in a patch yesterday?

No, the code in master should be uniformly better than what's in emacs-25.

It would be nice to have good tests for substitute-command-keys, of course. (We 
can all add this to our lists of things to do. :-)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Omit-substitute-command-keys-code-no-longer-needed.patch --]
[-- Type: text/x-diff; name="0001-Omit-substitute-command-keys-code-no-longer-needed.patch", Size: 1420 bytes --]

From bc5a55262382da9cc4b1999df7ce195b7f825d4b Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Tue, 16 Aug 2016 13:16:49 -0700
Subject: [PATCH] Omit substitute-command-keys code no longer needed

* src/doc.c (Fsubstitute_command_keys):
Remove duplicate initializations.
---
 src/doc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/doc.c b/src/doc.c
index 37a731b..4b91831 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -743,10 +743,12 @@ Otherwise, return a new string.  */)
   if (NILP (string))
     return Qnil;
 
+  /* If STRING contains non-ASCII unibyte data, process its
+     properly-encoded multibyte equivalent instead.  This simplifies
+     the implementation and is OK since substitute-command-keys is
+     intended for use only on text strings.  Keep STRING around, since
+     it will be returned if no changes occur.  */
   Lisp_Object str = Fstring_make_multibyte (string);
-  tem = Qnil;
-  keymap = Qnil;
-  name = Qnil;
 
   enum text_quoting_style quoting_style = text_quoting_style ();
 
@@ -905,6 +907,8 @@ Otherwise, return a new string.  */)
 	 }
 
 	subst_string:
+	  /* Convert non-ASCII unibyte data to properly-encoded multibyte,
+	     for the same reason STRING was converted to STR.  */
 	  tem = Fstring_make_multibyte (tem);
 	  start = SDATA (tem);
 	  length = SCHARS (tem);
-- 
2.7.4


  reply	other threads:[~2016-08-16 21:07 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-11 18:55 bug#24206: 25.1; Curly quotes generate invalid strings, leading to a segfault Phil
2016-08-11 20:05 ` Eli Zaretskii
2016-08-11 23:51   ` Philipp Stephani
2016-08-13  8:32     ` Eli Zaretskii
2016-08-13 12:25       ` Nicolas Petton
2016-08-14  6:33         ` John Wiegley
2016-08-14  4:54 ` Paul Eggert
2016-08-14 14:27   ` Eli Zaretskii
2016-08-14 14:51     ` Paul Eggert
2016-08-14 17:18       ` Eli Zaretskii
2016-08-15  2:04         ` Paul Eggert
2016-08-15 16:09           ` Eli Zaretskii
2016-08-15 16:46             ` Andreas Schwab
2016-08-15 18:43               ` Paul Eggert
2016-08-15 19:04                 ` Eli Zaretskii
2016-08-15 18:51               ` Eli Zaretskii
2016-08-15 19:05                 ` John Wiegley
2016-08-15 20:41                 ` Paul Eggert
2016-08-16 14:38                   ` Eli Zaretskii
2016-08-16 15:25                     ` John Wiegley
2016-08-16 16:09                       ` Nicolas Petton
2016-08-18 16:30                       ` Nicolas Petton
2016-08-18 16:41                         ` John Wiegley
2016-08-18 17:35                           ` Eli Zaretskii
2016-08-16 17:37                     ` Paul Eggert
2016-08-16 17:45                       ` John Wiegley
2016-08-16 17:55                         ` Paul Eggert
2016-08-16 17:57                           ` John Wiegley
2016-08-16 18:44                           ` Dmitry Gutov
2016-08-16 18:31                       ` Eli Zaretskii
2016-08-16 14:52                   ` Eli Zaretskii
2016-08-16 21:07                     ` Paul Eggert [this message]
2016-08-17 15:12                       ` Eli Zaretskii
2016-08-17 17:41                         ` Paul Eggert
2016-08-17 18:06                           ` Eli Zaretskii
2016-08-17 20:52                             ` Paul Eggert
2016-08-18 14:30                               ` Eli Zaretskii
2016-08-18 18:33                                 ` Paul Eggert
2016-08-18 18:58                                   ` Eli Zaretskii
2016-08-17 17:50                       ` Dmitry Gutov
2016-08-14 15:21   ` Dmitry Gutov
2016-08-15  1:53     ` Paul Eggert
2016-08-15  1:57       ` Dmitry Gutov
2016-08-15  2:05         ` Paul Eggert
2016-08-14 17:21   ` Eli Zaretskii
2016-08-14 20:16     ` Paul Eggert
2016-08-15  1:12       ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4822bfeb-c507-a9ff-93bc-1d27ba93b9d7@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=24206@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=johnw@gnu.org \
    --cc=p.stephani2@gmail.com \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.