(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
getCursorPosition and getColumns the result of calling write is checked against the buffer passed, and fails if not equal;
- In function
linenoiseClearScreen the result is checked by <= 0, but is ignored anyway;
- In functions
refreshSingleLine and refreshMultiLine and getColumns (again) the result is checked by == -1, but is ignored anyway;
- In functions
linenoiseEditInsert and linenoiseEditStart the 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.
(Thanks for this code.)
In several places, linenoise.c uses the function
writeto output data, but it is handled in different ways in different places.getCursorPositionandgetColumnsthe result of callingwriteis checked against the buffer passed, and fails if not equal;linenoiseClearScreenthe result is checked by<= 0, but is ignored anyway;refreshSingleLineandrefreshMultiLineandgetColumns(again) the result is checked by== -1, but is ignored anyway;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 forwritereturn states: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
writethat put out one byte to the UART and returned 1 - which then failed for linenoise. Obviously, I can and have improve my version ofwrite, 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 fromwriteis inconsistent within the code, and does not allow forwriteto successfully return less than the buffer size.Cheers.