(decode_coding): Fix handling of invalid bytes.
[bpt/emacs.git] / src / coding.c
index 93051d2..1a9b13f 100644 (file)
@@ -6208,7 +6208,9 @@ decode_coding (coding)
            {
              int c = *src++;
 
-             coding->charbuf[coding->charbuf_used++] = (c & 0x80 ? - c : c);
+             if (c & 0x80)
+               c = BYTE8_TO_CHAR (c);
+             coding->charbuf[coding->charbuf_used++] = c;
            }
          produce_chars (coding, Qnil, 1);
        }
@@ -6887,6 +6889,7 @@ encode_coding_object (coding, src_object, from, from_byte, to, to_byte,
   Lisp_Object attrs;
   Lisp_Object buffer;
   int saved_pt = -1, saved_pt_byte;
+  int kill_src_buffer = 0;
 
   buffer = Fcurrent_buffer ();
 
@@ -6924,6 +6927,8 @@ encode_coding_object (coding, src_object, from, from_byte, to, to_byte,
        args[2] = make_number (Z);
        safe_call (3, args);
       }
+      if (XBUFFER (coding->src_object) != current_buffer)
+       kill_src_buffer = 1;
       coding->src_object = Fcurrent_buffer ();
       if (BEG != GPT)
        move_gap_both (BEG, BEG_BYTE);
@@ -7026,6 +7031,8 @@ encode_coding_object (coding, src_object, from, from_byte, to, to_byte,
                          saved_pt_byte + (coding->produced - bytes));
     }
 
+  if (kill_src_buffer)
+    Fkill_buffer (coding->src_object);
   unbind_to (count, Qnil);
 }