fix(coverity/509227/509228): tui driver_ti underflow #30341

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-19 08:33:40 +00:00 committed by GitHub
parent 0ba3888474
commit 0fe4362e21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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