From: Eli Zaretskii <eliz@gnu.org>
To: Jeff Norden <jnorden@tntech.edu>
Cc: 43499@debbugs.gnu.org
Subject: bug#43499: 27.1; It is possible for (forward-comment -1) to crash emacs
Date: Sat, 19 Sep 2020 12:08:51 +0300 [thread overview]
Message-ID: <83pn6i2kws.fsf@gnu.org> (raw)
In-Reply-To: <fdpn6i5zhu.fsf@norden.tntech.edu> (message from Jeff Norden on Fri, 18 Sep 2020 20:25:33 -0500)
> From: Jeff Norden <jnorden@tntech.edu>
> Date: Fri, 18 Sep 2020 20:25:33 -0500
>
> In an unusual circumstance, (forward-comment -1) can move the point before the
> accessible buffer text. This can even result in the point becoming negative.
> In the worst-case scenario, emacs becomes completely unresponsive, and it
> might even be necessary to reboot the computer.
Thanks. In my case, I get a segfault in DEC_BOTH (because it attempts
to dereference a pointer outside of buffer text).
> The loop should, I think, be changed to the following. The only change is how
> from and stop are compared.
>
> while (from > stop)
> {
> DEC_BOTH (from, from_byte);
> UPDATE_SYNTAX_TABLE_BACKWARD (from);
> c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
> if (SYNTAX (c) == Scomment_fence
> && !char_quoted (from, from_byte))
> {
> fence_found = 1;
> break;
> }
> rarely_quit (++quit_count);
> }
Thanks. I propose a slightly different change below. I think it's
somewhat better, because it does the comparison only once, and the
while loop can then run at full speed without testing on each
iteration. (It looks like a large change, but almost all of it is
just whitespace changes due to re-indentation of the loop.) Do you
agree?
diff --git a/src/syntax.c b/src/syntax.c
index a79ab86..e8b32f5 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -2545,20 +2545,23 @@ DEFUN ("forward-comment", Fforward_comment, Sforward_comment, 1, 1, 0,
bool fence_found = 0;
ptrdiff_t ini = from, ini_byte = from_byte;
- while (1)
+ if (from > stop)
{
- DEC_BOTH (from, from_byte);
- UPDATE_SYNTAX_TABLE_BACKWARD (from);
- c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
- if (SYNTAX (c) == Scomment_fence
- && !char_quoted (from, from_byte))
+ while (1)
{
- fence_found = 1;
- break;
+ DEC_BOTH (from, from_byte);
+ UPDATE_SYNTAX_TABLE_BACKWARD (from);
+ c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
+ if (SYNTAX (c) == Scomment_fence
+ && !char_quoted (from, from_byte))
+ {
+ fence_found = 1;
+ break;
+ }
+ else if (from == stop)
+ break;
+ rarely_quit (++quit_count);
}
- else if (from == stop)
- break;
- rarely_quit (++quit_count);
}
if (fence_found == 0)
{
next prev parent reply other threads:[~2020-09-19 9:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-19 1:25 bug#43499: 27.1; It is possible for (forward-comment -1) to crash emacs Jeff Norden
2020-09-19 9:08 ` Eli Zaretskii [this message]
2020-09-19 16:24 ` Jeff Norden
2020-09-19 16:56 ` Eli Zaretskii
2020-11-13 3:40 ` Stefan Kangas
2020-11-13 8:18 ` Eli Zaretskii
2020-09-19 9:10 ` Alan Mackenzie
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=83pn6i2kws.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=43499@debbugs.gnu.org \
--cc=jnorden@tntech.edu \
/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.