[libc-commits] [PATCH] D137286: [libc] Add implementation of ungetc.
Michael Jones via Phabricator via libc-commits
libc-commits at lists.llvm.org
Wed Nov 2 15:17:13 PDT 2022
michaelrj accepted this revision.
michaelrj added inline comments.
This revision is now accepted and ready to land.
================
Comment at: libc/src/__support/File/file.cpp:265-266
+ // |pos|.
+ --pos;
+ bufref[pos] = static_cast<unsigned char>(c);
+ }
----------------
sivachandra wrote:
> michaelrj wrote:
> > this could have issues in the case where `ungetc` is called twice in a row. If `pos` is 1 and ungetc is called, then `pos` is set to 0 and the char is written to `bufref[pos]`, but on the second call `pos` is already 0 so subtracting will cause an underflow and likely a segfault.
> I have added a conditional now.
this is okay for now (since it guarantees a buffer size of at least 1) but in future I'd like to look into a way to increase the size of the pushback buffer.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137286/new/
https://reviews.llvm.org/D137286
More information about the libc-commits
mailing list