diff options
author | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2024-11-07 11:16:04 -0500 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2024-12-17 17:42:55 -0500 |
commit | ae5062201d7e9d18fe88bff4bc71088374c394fb (patch) | |
tree | 4f5917292a83f1e2f479802987f7e7dc966a5672 /benchtests/json-lib.c | |
parent | cfdd9e7aa45cdc575df237e2d2eee3219a06829b (diff) | |
download | glibc-ae5062201d7e9d18fe88bff4bc71088374c394fb.zip glibc-ae5062201d7e9d18fe88bff4bc71088374c394fb.tar.gz glibc-ae5062201d7e9d18fe88bff4bc71088374c394fb.tar.bz2 |
ungetc: Guarantee single char pushback
The C standard requires that ungetc guarantees at least one pushback,
but the malloc call to allocate the pushback buffer could fail, thus
violating that requirement. Fix this by adding a single byte pushback
buffer in the FILE struct that the pushback can fall back to if malloc
fails.
The side-effect is that if the initial malloc fails and the 1-byte
fallback buffer is used, future resizing (if it succeeds) will be
2-bytes, 4-bytes and so on, which is suboptimal but it's after a malloc
failure, so maybe even desirable.
A future optimization here could be to have the pushback code use the
single byte buffer first and only fall back to malloc for subsequent
calls.
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Maciej W. Rozycki <macro@redhat.com>
Diffstat (limited to 'benchtests/json-lib.c')
0 files changed, 0 insertions, 0 deletions