Coverity fix CID:92 NEGATIVE_RETURNS
authorNelson Ferreira <nelson.ferreira@ieee.org>
Tue, 11 Oct 2011 01:14:35 +0000 (21:14 -0400)
committerNelson Ferreira <nelson.ferreira@ieee.org>
Tue, 11 Oct 2011 01:14:35 +0000 (21:14 -0400)
* lib-src/movemail.c (main): Make sure read was successful before
trying to write..

Signed-off-by: Nelson Ferreira <nelson.ferreira@ieee.org>
lib-src/movemail.c

index d328c45..5d1e95b 100644 (file)
@@ -418,16 +418,17 @@ int main(int argc, char *argv[])
 
                {
                        char buf[1024];
-
+                       int retries = 3;
                        while (1) {
                                nread = read(indesc, buf, sizeof buf);
-                               if (nread != write(outdesc, buf, nread)) {
+                               if (nread < 0 ||  
+                                   nread != write(outdesc, buf, nread)) {
                                        int saved_errno = errno;
                                        unlink(outname);
                                        errno = saved_errno;
                                        pfatal_with_name(outname);
                                }
-                               if (nread < (int)sizeof buf)
+                               if (nread < (int)sizeof(buf))
                                        break;
                        }
                }