-
Notifications
You must be signed in to change notification settings - Fork 717
Description
(Thanks for this code.)
In several places, linenoise.c uses the function write to output data, but it is handled in different ways in different places.
- In functions
getCursorPositionandgetColumnsthe result of callingwriteis checked against the buffer passed, and fails if not equal; - In function
linenoiseClearScreenthe result is checked by<= 0, but is ignored anyway; - In functions
refreshSingleLineandrefreshMultiLineandgetColumns(again) the result is checked by== -1, but is ignored anyway; - In functions
linenoiseEditInsertandlinenoiseEditStartthe result is checked by== -1, and fails if true, but ignores values returned less than the buffer size.
For the semantics of write, I refer to the POSIX specification (https://pubs.opengroup.org/onlinepubs/9799919799/). The specification for write return states:
Upon successful completion, these functions shall return the number of bytes actually written to the file associated with fildes. This number shall never be greater than nbyte. Otherwise, -1 shall be returned and errno set to indicate the error.
Elsewhere is makes it clear that the number of bytes actually written may legitimately be less than the size of the buffer passed.
I'm trying to use linenoise on an embedded device, and did a cheap-and-nasty version of write that put out one byte to the UART and returned 1 - which then failed for linenoise. Obviously, I can and have improve my version of write, but when sending output to a UART, I may want to limit the output to the size of my hardware FIFO (32 characters). In any case, I suggest that the handling of the result from write is inconsistent within the code, and does not allow for write to successfully return less than the buffer size.
Cheers.