[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r117838: Fix bug uncovered by changing alloca to aut
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] trunk r117838: Fix bug uncovered by changing alloca to auto buffer. |
Date: |
Sun, 07 Sep 2014 22:28:05 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 117838
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/18410
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Sun 2014-09-07 15:27:59 -0700
message:
Fix bug uncovered by changing alloca to auto buffer.
* coding.c (growable_destination): New function.
(produce_chars): Use it for sanity checks. Do not fiddle with
dst_end if the source and destination are both nil, as it's
the caller's responsibility to avoid overlap.
* keyboard.c (read_decoded_event_from_main_queue):
The destination must be MAX_MULTIBYTE_LENGTH times the max source
length, not 4 times, to prevent decode_coding_c_string from trying
to reallocate a destination. This removes the need for the FIXME.
modified:
src/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1438
src/coding.c coding.c-20091113204419-o5vbwnq5f7feedwu-1077
src/keyboard.c keyboard.c-20091113204419-o5vbwnq5f7feedwu-449
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2014-09-07 20:31:18 +0000
+++ b/src/ChangeLog 2014-09-07 22:27:59 +0000
@@ -1,5 +1,15 @@
2014-09-07 Paul Eggert <address@hidden>
+ Fix bug uncovered by changing alloca to auto buffer (Bug#18410).
+ * coding.c (growable_destination): New function.
+ (produce_chars): Use it for sanity checks. Do not fiddle with
+ dst_end if the source and destination are both nil, as it's
+ the caller's responsibility to avoid overlap.
+ * keyboard.c (read_decoded_event_from_main_queue):
+ The destination must be MAX_MULTIBYTE_LENGTH times the max source
+ length, not 4 times, to prevent decode_coding_c_string from trying
+ to reallocate a destination. This removes the need for the FIXME.
+
* callproc.c (exec_failed) [DOS_NT]: Define a dummy.
All callers simplified. Add a comment about exec_failed, vfork,
and alloca.
=== modified file 'src/coding.c'
--- a/src/coding.c 2014-09-07 07:04:01 +0000
+++ b/src/coding.c 2014-09-07 22:27:59 +0000
@@ -690,6 +690,14 @@
XSETCDR (x, tmp);
}
+/* True if CODING's destination can be grown. */
+
+static bool
+growable_destination (struct coding_system *coding)
+{
+ return STRINGP (coding->dst_object) || BUFFERP (coding->dst_object);
+}
+
/* Safely get one byte from the source text pointed by SRC which ends
at SRC_END, and set C to that byte. If there are not enough bytes
@@ -7019,8 +7027,10 @@
int *buf = coding->charbuf;
int *buf_end = buf + coding->charbuf_used;
- if (EQ (coding->src_object, coding->dst_object))
+ if (EQ (coding->src_object, coding->dst_object)
+ && ! NILP (coding->dst_object))
{
+ eassert (growable_destination (coding));
coding_set_source (coding);
dst_end = ((unsigned char *) coding->source) + coding->consumed;
}
@@ -7059,6 +7069,7 @@
if ((dst_end - dst) / MAX_MULTIBYTE_LENGTH < to_nchars)
{
+ eassert (growable_destination (coding));
if (((min (PTRDIFF_MAX, SIZE_MAX) - (buf_end - buf))
/ MAX_MULTIBYTE_LENGTH)
< to_nchars)
@@ -7103,7 +7114,10 @@
const unsigned char *src_end = src + coding->consumed;
if (EQ (coding->dst_object, coding->src_object))
- dst_end = (unsigned char *) src;
+ {
+ eassert (growable_destination (coding));
+ dst_end = (unsigned char *) src;
+ }
if (coding->src_multibyte != coding->dst_multibyte)
{
if (coding->src_multibyte)
@@ -7119,6 +7133,7 @@
ONE_MORE_BYTE (c);
if (dst == dst_end)
{
+ eassert (growable_destination (coding));
if (EQ (coding->src_object, coding->dst_object))
dst_end = (unsigned char *) src;
if (dst == dst_end)
@@ -7149,6 +7164,7 @@
if (dst >= dst_end - 1)
{
+ eassert (growable_destination (coding));
if (EQ (coding->src_object, coding->dst_object))
dst_end = (unsigned char *) src;
if (dst >= dst_end - 1)
=== modified file 'src/keyboard.c'
--- a/src/keyboard.c 2014-09-07 13:27:33 +0000
+++ b/src/keyboard.c 2014-09-07 22:27:59 +0000
@@ -2355,22 +2355,15 @@
struct coding_system *coding
= TERMINAL_KEYBOARD_CODING (terminal);
unsigned char src[MAX_ENCODED_BYTES];
- unsigned char dest[4 * sizeof src];
+ unsigned char dest[MAX_ENCODED_BYTES * MAX_MULTIBYTE_LENGTH];
int i;
for (i = 0; i < n; i++)
src[i] = XINT (events[i]);
if (meta_key != 2)
for (i = 0; i < n; i++)
src[i] &= ~0x80;
-
- /* FIXME: For some reason decode_coding_c_string requires a
- fresh output buffer each time, and reusing the old buffer can
- make Emacs dump core. Avoid triggering the problem for now
- by allocating a new buffer each time through the loop. */
- bool please_fixme = true;
- coding->destination = please_fixme ? alloca (n * 4) : dest;
-
- coding->dst_bytes = n * 4;
+ coding->destination = dest;
+ coding->dst_bytes = sizeof dest;
decode_coding_c_string (coding, src, n, Qnil);
eassert (coding->produced_char <= n);
if (coding->produced_char == 0)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r117838: Fix bug uncovered by changing alloca to auto buffer.,
Paul Eggert <=