On 01/18/2013 11:34 PM, Eli Zaretskii wrote: > I'm not sure I see how the gap size fails to be updated. There's a > call to make_gap just before read_non_regular is called. Or did you > mean GAP_SIZE? If the latter, then the comments there explain why > this is not done. Argh. We fool itself with gap_size (src/fileio.c, 24.2.92): 4098 /* Maybe make more room. */ 4099 if (gap_size < trytry) 4100 { 4101 make_gap (total - gap_size); 4102 gap_size = GAP_SIZE; /* !!! here */ 4103 } After that, local gap_size (e.g. amount of bytes which may be used to read next chunk from the file) is GAP_SIZE - inserted, not GAP_SIZE. > But until GAP_SIZE and ZV are updated, the inserted text is not > really part of the buffer, right? So what is the problem here? Here is the original code (src/fileio.c, 24.2.92): 4169 /* Make the text read part of the buffer. */ 4170 GAP_SIZE -= inserted; 4171 GPT += inserted; 4172 GPT_BYTE += inserted; 4173 ZV += inserted; 4174 ZV_BYTE += inserted; 4175 Z += inserted; 4176 Z_BYTE += inserted; 4177 /* !!! `inserted' bytes becomes "really inserted" */ 4178 if (GAP_SIZE > 0) 4179 /* Put an anchor to ensure multi-byte form ends at gap. */ 4180 *GPT_ADDR = 0; 4181 4182 emacs_close (fd); 4183 4184 /* Discard the unwind protect for closing the file. */ 4185 specpdl_ptr--; 4186 4187 if (how_much < 0) 4188 error ("IO error reading %s: %s", /* error leaves `inserted' bytes not decoded !!! */ 4189 SDATA (orig_filename), emacs_strerror (errno)); Attached is the fix for 24.2.92, and I believe that this is important for the next pretest. For trunk, I'll revert 111547 and do the similar fix. Dmitry