Conversation
There was a problem hiding this comment.
Pull request overview
This PR replaces fixed-size fgets(3) stdin reads with a getline(3)-based wrapper (getstdin) to avoid truncated input and simplify interactive prompting across itsa.
Changes:
- Added
getstdin(char **lineptr)wrapper aroundgetline(3)for stdin reading. - Updated multiple interactive prompts to use
getstdin()instead of stack buffers +fgets(). - Adjusted related local variables to use
__cleanup_freeheap strings instead of fixed-size arrays.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
getline(3) is generally safer than fgets(3), for example you won't get truncated input and will always get the \n character. Rather than using getline(3) directly we create a wrapper function for it, ssize_t getstdin(char **lineptr); We don't care about the allocated string size and are always reading from stdin. The first thing we do is free(*lineptr) and set it to NULL, this makes subsequent calls to getstdin() in the same function safe and not leak memory. If getline(3) returns an error, we free lineptr and set it to NULL so it can be safely passed to free by the __cleanup_free function and return -1. That way we can just check lineptr for NULL to check for an error. lineptr should always be set to NULL before the first call to getstdin() in a fucntion. Signed-off-by: Andrew Clayton <ac@sigsegv.uk>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.