Skip to content

Commit

Permalink
coverity: fix Unchecked return value from library
Browse files Browse the repository at this point in the history
fcntl can return errors (as -1, and set errno); so handle that
appropraitely.

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz committed Apr 8, 2020
1 parent e12120a commit 7d39af6
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions iiod/iiod.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,24 @@ static int main_interactive(struct iio_context *ctx, bool verbose, bool use_aio)

if (!use_aio) {
flags = fcntl(STDIN_FILENO, F_GETFL);
fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
if (flags >= 0)
flags = fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
if (flags < 0) {
char err_str[1024];
iio_strerror(errno, err_str, sizeof(err_str));
IIO_ERROR("Could not get/set O_NONBLOCK on STDIN_FILENO"
" %s (%d)\n", err_str, -errno);
}

flags = fcntl(STDOUT_FILENO, F_GETFL);
fcntl(STDOUT_FILENO, F_SETFL, flags | O_NONBLOCK);
if (flags >= 0)
flags = fcntl(STDOUT_FILENO, F_SETFL, flags | O_NONBLOCK);
if (flags < 0) {
char err_str[1024];
iio_strerror(errno, err_str, sizeof(err_str));
IIO_ERROR("Could not get/set O_NONBLOCK on STDOUT_FILENO"
" %s (%d)\n", err_str, -errno);
}
}

interpreter(ctx, STDIN_FILENO, STDOUT_FILENO, verbose,
Expand Down

0 comments on commit 7d39af6

Please sign in to comment.