s3-libsmb: Fix possible comparsion problems.
authorAndreas Schneider <asn@samba.org>
Mon, 10 Dec 2012 14:11:23 +0000 (15:11 +0100)
committerGünther Deschner <gd@samba.org>
Wed, 12 Dec 2012 14:00:02 +0000 (15:00 +0100)
This makes the code also easier to understand.

Found by Coverity.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Günther Deschner <gd@samba.org>
source3/libsmb/libsmb_printjob.c

index db46ceee9cb3e6217830b1842e3b1cf26c4ad67a..173fa327d3ebf7f07b6ca8d2e3e7e09ae85320ef 100644 (file)
@@ -93,6 +93,8 @@ SMBC_print_file_ctx(SMBCCTX *c_file,
 {
         SMBCFILE *fid1;
         SMBCFILE *fid2;
+        smbc_open_fn f_open1;
+        smbc_open_print_job_fn f_open_pj2;
         int bytes;
         int saverr;
         int tot_bytes = 0;
@@ -113,18 +115,30 @@ SMBC_print_file_ctx(SMBCCTX *c_file,
         }
 
         /* Try to open the file for reading ... */
+       f_open1 = smbc_getFunctionOpen(c_file);
+       if (f_open1 == NULL) {
+               errno = EINVAL;
+               TALLOC_FREE(frame);
+               return -1;
+       }
 
-        if ((long)(fid1 = smbc_getFunctionOpen(c_file)(c_file, fname,
-                                                       O_RDONLY, 0666)) < 0) {
-                DEBUG(3, ("Error, fname=%s, errno=%i\n", fname, errno));
+       fid1 = f_open1(c_file, fname, O_RDONLY, 0666);
+       if (fid1 < 0) {
+               DEBUG(3, ("Error, fname=%s, errno=%i\n", fname, errno));
                TALLOC_FREE(frame);
-                return -1;  /* smbc_open sets errno */
-        }
+               return -1;  /* smbc_open sets errno */
+       }
 
         /* Now, try to open the printer file for writing */
+       f_open_pj2 = smbc_getFunctionOpenPrintJob(c_print);
+       if (f_open_pj2 == NULL) {
+               errno = EINVAL;
+               TALLOC_FREE(frame);
+               return -1;
+       }
 
-        if ((long)(fid2 = smbc_getFunctionOpenPrintJob(c_print)(c_print,
-                                                                printq)) < 0) {
+       fid2 = f_open_pj2(c_print, printq);
+       if (fid2 < 0) {
                 saverr = errno;  /* Save errno */
                 smbc_getFunctionClose(c_file)(c_file, fid1);
                 errno = saverr;