fix(coverity/509227): tui stop_driver_ti() avoid underflow

Problem:
write() can return -1 but is cast to unsigned type causing coverity
to detect possible overflowed integer

Solution:
Perform check to ensure all negative values are captured rather than
just -1 before casting to unsigned type
This commit is contained in:
Devon Gardner 2024-09-11 00:38:17 -04:00
parent 5dad85b977
commit 9054993842

View File

@ -449,10 +449,11 @@ int stop_driver_ti(TermKey *tk, void *info)
// Can't call putp or tputs because they suck and don't give us fd control
len = strlen(stop_string);
while (len) {
size_t written = (size_t)write(tk->fd, stop_string, (unsigned)len);
if (written == (size_t)-1) {
ssize_t result = write(tk->fd, stop_string, (unsigned)len);
if (result < 0) {
return 0;
}
size_t written = (size_t)result;
stop_string += written;
len -= written;
}