A bug in the file read logic has also been fixed along the way. Parts
of the ungetc tests will fail without that bug fixed.
Details
- Reviewers
michaelrj - Commits
- rG1ceafe5e0f69: [libc] Add implementation of ungetc.
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libc/src/__support/File/file.cpp | ||
---|---|---|
265–266 | 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. |
Address comments.
libc/src/__support/File/file.cpp | ||
---|---|---|
265–266 | I have added a conditional now. |
libc/src/__support/File/file.cpp | ||
---|---|---|
265–266 | 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. |
libc/src/__support/File/file.cpp | ||
---|---|---|
265–266 | The standards require a minimum unget buffer of 1 character. A program relying on anything else would be a relying on internals so I do not think trying to build larger push back buffer is required or worth the complication. |
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.