Skip to content

Commit

Permalink
Merge pull request #466 from analogdevicesinc/rgetz-fix-coverity-iio-…
Browse files Browse the repository at this point in the history
…readdev

Coverity: Fix potential divide by zero in iio_readdev
  • Loading branch information
rgetz authored Apr 28, 2020
2 parents 9e36fd3 + ab6581f commit 5d7d176
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/iio_readdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ int main(int argc, char **argv)
const char *arg_ip = NULL;
int c, option_index = 0;
struct iio_device *dev;
size_t sample_size;
ssize_t sample_size;
int timeout = -1;
bool scan_for_context = false;
ssize_t ret;
Expand Down Expand Up @@ -352,6 +352,18 @@ int main(int argc, char **argv)
}

sample_size = iio_device_get_sample_size(dev);
/* Zero isn't normally an error code, but in this case it is an error */
if (sample_size == 0) {
fprintf(stderr, "Unable to get sample size, returned 0\n");
iio_context_destroy(ctx);
return EXIT_FAILURE;
} else if (sample_size < 0) {
char buf[256];
iio_strerror(errno, buf, sizeof(buf));
fprintf(stderr, "Unable to get sample size : %s\n", buf);
iio_context_destroy(ctx);
return EXIT_FAILURE;
}

buffer = iio_device_create_buffer(dev, buffer_size, false);
if (!buffer) {
Expand Down

0 comments on commit 5d7d176

Please sign in to comment.