From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 36431@debbugs.gnu.org
Subject: bug#36431: Crash in marker.c:337
Date: Tue, 02 Jul 2019 17:00:21 -0400 [thread overview]
Message-ID: <jwvpnmsjh5i.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <83pnmschvy.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 02 Jul 2019 23:15:45 +0300")
>> Decode the data at CODING->src_object into CODING->dst_object.
>> CODING->src_object is a buffer, a string, or nil.
>> CODING->dst_object is a buffer.
>>
>> If CODING->src_object is a buffer, it must be the current buffer.
>> In this case, if CODING->src_pos is positive, it is a position of
>> the source text in the buffer, otherwise, the source text is in the
>> gap area of the buffer, and CODING->src_pos specifies the offset of
>> the text from GPT (which must be the same as PT). If this is the
>> same buffer as CODING->dst_object, CODING->src_pos must be
>> negative.
>> [...]
>> The decoded data is inserted at the current point of the buffer
>> CODING->dst_object.
>>
>> but this doesn't say if the bytes are to be found originally at the
>> beginning of the gap or its end, nor whether they finish at the beginning or
>> the end, nor what happens in the middle and why it's been designed this way.
>
> It says that (a) CODING->src_pos is the negative of the offset from
> GPT of where the bytes are in the gap
Yes, I think this is actually wrong.
E.e. decode_coding_gap does:
coding->src_chars = chars;
[...]
coding->src_pos = -chars;
so nowhere does it account for unspecified number of bytes between the
beginning of the gap and the beginning of the source text.
Here, `src_pos` is the offset from the end of the gap.
> (they don't have to be "at the
> end", AFAIU, just not "at the beginning");
Oh, indeed, src_pos doesn't need to start as the negation of src_chars.
> As for why this was designed like that -- where else did you see
> comments in Emacs that answer this kind of questions?
There are such design comments at various places.
Usually added after the fact, sometimes added as part of
a commit-reversal to make sure someone else doesn't fall into the same
trap ;-)
>> Is the patch below correct?
> I think it describes conditions that don't need to exist.
How 'bout this new version.
Stefan
diff --git a/src/coding.c b/src/coding.c
index 59589caee6..fd7e7aca0f 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -7323,10 +7323,15 @@ produce_annotation (struct coding_system *coding, ptrdiff_t pos)
If CODING->src_object is a buffer, it must be the current buffer.
In this case, if CODING->src_pos is positive, it is a position of
the source text in the buffer, otherwise, the source text is in the
- gap area of the buffer, and CODING->src_pos specifies the offset of
- the text from GPT (which must be the same as PT). If this is the
- same buffer as CODING->dst_object, CODING->src_pos must be
- negative.
+ gap area of the buffer, and CODING->src_pos specifies the
+ offset of the text from the end of the gap (which must be at PT).
+ If this is the same buffer as CODING->dst_object, CODING->src_pos must
+ be negative.
+
+ When the text is taken from the gap, it can't be at the beginning of
+ the gap so that we can produce the decoded text at the beginning of
+ the gap: this way, as the output grows, the input shrinks, so we only
+ need to allocate enough space for `max(IN, OUT)` instead of `IN + OUT`.
If CODING->src_object is a string, CODING->src_pos is an index to
that string.
next prev parent reply other threads:[~2019-07-02 21:00 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-29 11:17 bug#36431: Crash in marker.c:337 Werner LEMBERG
2019-06-29 12:13 ` Eli Zaretskii
2019-06-29 12:20 ` Eli Zaretskii
2019-06-29 22:56 ` Stefan Monnier
2019-06-30 7:26 ` Werner LEMBERG
2019-06-30 13:14 ` Stefan Monnier
2019-07-02 16:29 ` Stefan Monnier
2019-06-30 14:52 ` Eli Zaretskii
2019-06-30 14:39 ` Eli Zaretskii
2019-06-30 14:59 ` Stefan Monnier
2019-06-30 15:16 ` Eli Zaretskii
2019-06-30 15:53 ` Stefan Monnier
2019-07-02 17:04 ` Stefan Monnier
2019-07-02 17:22 ` Stefan Monnier
2019-07-02 17:37 ` Stefan Monnier
2019-07-02 17:42 ` Eli Zaretskii
2019-07-02 17:55 ` Stefan Monnier
2019-07-02 17:39 ` Eli Zaretskii
2019-07-02 17:51 ` Stefan Monnier
2019-07-02 18:27 ` Eli Zaretskii
2019-07-02 19:44 ` Stefan Monnier
2019-07-02 20:15 ` Eli Zaretskii
2019-07-02 21:00 ` Stefan Monnier [this message]
2019-07-03 4:49 ` Eli Zaretskii
2019-07-03 16:19 ` Stefan Monnier
2019-07-03 16:33 ` Eli Zaretskii
2019-07-03 4:21 ` Stefan Monnier
2019-07-03 4:55 ` Eli Zaretskii
2019-07-03 6:20 ` Werner LEMBERG
2019-07-03 6:29 ` Eli Zaretskii
2019-07-03 6:46 ` Werner LEMBERG
2019-07-03 7:14 ` Eli Zaretskii
2019-07-03 16:08 ` Stefan Monnier
2019-07-09 21:04 ` Stefan Monnier
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=jwvpnmsjh5i.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=36431@debbugs.gnu.org \
--cc=eliz@gnu.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.