[PATCH 2/3] ungetc: Guarantee single char pushback
Siddhesh Poyarekar
siddhesh@sourceware.org
Fri Nov 29 11:44:24 GMT 2024
On 2024-11-29 02:02, Florian Weimer wrote:
> * Maciej W. Rozycki:
>
>> The structure is fully packed and there's no padding in the legacy part
>> I'm afraid, and I guess it's the case for the majority of 32-bit targets,
>> which don't imply alignment beyond 4 bytes for pointers. Have I missed
>> anything?
>
> No, you are right. So the extension area has to be used. I think we
> should fail ungetc if the malloc call fails and the extension area is
> unavailable, instead of resorting to heroic bit-stuffing.
So basically the original struct layout I had proposed plus this in
genops.c should do it?
diff --git a/libio/genops.c b/libio/genops.c
index d7e35e67d5..5b8bb52ec3 100644
--- a/libio/genops.c
+++ b/libio/genops.c
@@ -1002,7 +1002,14 @@ _IO_default_pbackfail (FILE *fp, int c)
int backup_size = 128;
char *bbuf = (char *) malloc (backup_size);
if (bbuf == NULL)
- return EOF;
+ {
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+ if (__glibc_unlikely (_IO_vtable_offset (fp) != 0))
+ return EOF;
+#endif
+ bbuf = fp->_short_backupbuf;
+ backup_size = 1;
+ }
fp->_IO_save_base = bbuf;
fp->_IO_save_end = fp->_IO_save_base + backup_size;
fp->_IO_backup_base = fp->_IO_save_end;
More information about the Libc-alpha
mailing list