The fread() result is now always terminated with \0. Don't think that's ever hit but it gives us a good reason to use the return value so we don't get more complaints.
Interestingly, a (void) cast doesn't silence gcc but it does silence coverity. Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net> --- src/wcmISDV4.c | 10 +++++++--- tools/isdv4-serial-inputattach.c | 5 +++-- tools/tools-shared.c | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/wcmISDV4.c b/src/wcmISDV4.c index 0d3cc81..da64598 100644 --- a/src/wcmISDV4.c +++ b/src/wcmISDV4.c @@ -590,7 +590,7 @@ static int isdv4StopTablet(InputInfoPtr pInfo) char buffer[10]; while (read(pInfo->fd, buffer, sizeof(buffer)) > 0) DBG(10, common, "discarding garbage data.\n"); - fcntl(pInfo->fd, F_SETFL, fd_flags); + (void)fcntl(pInfo->fd, F_SETFL, fd_flags); } return Success; @@ -983,8 +983,10 @@ static Bool get_sysfs_id(InputInfoPtr pInfo, char *buf, int buf_size) char *sysfs_path = NULL; FILE *file = NULL; Bool ret = FALSE; + int bytes_read; - fstat(pInfo->fd, &st); + if (fstat(pInfo->fd, &st) == -1) + goto out; udev = udev_new(); device = udev_device_new_from_devnum(udev, 'c', st.st_rdev); @@ -1000,8 +1002,10 @@ static Bool get_sysfs_id(InputInfoPtr pInfo, char *buf, int buf_size) file = fopen(sysfs_path, "r"); if (!file) goto out; - if (!fread(buf, 1, buf_size, file)) + bytes_read = fread(buf, 1, buf_size - 1, file); + if (bytes_read == 0) goto out; + buf[bytes_read] = '\0'; ret = TRUE; out: udev_device_unref(device); diff --git a/tools/isdv4-serial-inputattach.c b/tools/isdv4-serial-inputattach.c index be8706e..9d698b0 100644 --- a/tools/isdv4-serial-inputattach.c +++ b/tools/isdv4-serial-inputattach.c @@ -89,7 +89,8 @@ static int get_baud_rate(int fd) struct udev_device *device, *parent; const char *attr_id = NULL; - fstat(fd, &st); + if (fstat(fd, &st) == -1) + return -1; udev = udev_new(); device = udev_device_new_from_devnum(udev, 'c', st.st_rdev); @@ -206,7 +207,7 @@ int main(int argc, char **argv) signal(SIGINT, sighandler); signal(SIGHUP, sighandler); - read(fd, NULL, 0); + rc = (int)read(fd, NULL, 0); /* warning fix only, ignore error */ set_line_discipline(fd, 0); diff --git a/tools/tools-shared.c b/tools/tools-shared.c index 4796c3c..3485ac2 100644 --- a/tools/tools-shared.c +++ b/tools/tools-shared.c @@ -149,7 +149,7 @@ int stop_tablet(int fd) { while (read(fd, buffer, sizeof(buffer)) > 0) TRACE("garbage flushed\n"); - fcntl(fd, F_SETFL, fd_flags); + (void)fcntl(fd, F_SETFL, fd_flags); } return rc; -- 2.1.0 ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Linuxwacom-devel mailing list Linuxwacom-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel