Blame SOURCES/sane-backends-1.0.24-static-code-check.patch

b0a773
From 886208261b5b91b4a64efd8a203873ab85a07a2e Mon Sep 17 00:00:00 2001
b0a773
From: Nils Philippsen <nils@redhat.com>
b0a773
Date: Thu, 7 Nov 2013 12:48:23 +0100
b0a773
Subject: [PATCH] patch: static-code-check
b0a773
b0a773
Fix problems found during static code check (Coverity).
b0a773
b0a773
Squashed commit of the following:
b0a773
b0a773
commit e24cea3bceb5dad2042dcd95f582d6c8acf4c9ee
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Thu Nov 7 14:29:28 2013 +0100
b0a773
b0a773
    epson: don't leak memory if realloc() fails
b0a773
b0a773
    (cherry picked from commit d835d9d565118d52c2339c2e79890f57d0616077)
b0a773
b0a773
commit b0c14b86210c7615ea4d90723722a7430b175ae2
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Wed Nov 6 11:05:58 2013 +0100
b0a773
b0a773
    genesys: check return values
b0a773
b0a773
    (cherry picked from commit dc76e7cce464f04e46aab2bb0c269b4742161c59)
b0a773
b0a773
commit b6e13be1c187790adfa50e81506533fbe21dca6f
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Tue Nov 5 14:48:09 2013 +0100
b0a773
b0a773
    genesys: remove code which is never reached
b0a773
b0a773
    The surrounding conditions always evaluate as FALSE because the
b0a773
    variables are set to different values before.
b0a773
b0a773
    (cherry picked from commit 5d7f7ffefb22e7e64789e97af0356b7859d61814)
b0a773
b0a773
commit 6d77e6f1ebb9eb0f47117a5790486a3b83c142d2
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Wed Nov 6 11:44:16 2013 +0100
b0a773
b0a773
    rts8891: check return values
b0a773
b0a773
    (cherry picked from commit 602d6ecdfe5f3146867799fabf3ac87582c26461)
b0a773
b0a773
commit 0438b3f9aaa4ee8558185ad5e7a9c6a0bf1a3590
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Tue Nov 5 15:42:26 2013 +0100
b0a773
b0a773
    genesys: compute MAX_SCANNERS from array length
b0a773
b0a773
    ... of genesys_usb_device_list[]
b0a773
b0a773
    (cherry picked from commit a3fe2c1ea5b4f6b1e55435f6abc44f402ff32b4d)
b0a773
b0a773
commit ba746cc2a62cfb32ae6f8e22d6d36206959b7128
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Tue Nov 5 15:31:11 2013 +0100
b0a773
b0a773
    kodakio: don't overrun option name array
b0a773
b0a773
    (cherry picked from commit 2d89e37f365cb8e54ee44aa686a62320e2837b50)
b0a773
b0a773
commit 87580bc5d07f983afa1db1e0e7c36287b85b5ecd
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Tue Nov 5 15:19:48 2013 +0100
b0a773
b0a773
    pixma: document falling through to next switch case
b0a773
b0a773
    (cherry picked from commit 101f76c516cd42cafe9e142aefe751094a125e73)
b0a773
b0a773
commit 15f7322b94a1e895d6ab6e8fb0466ef920a946ad
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Tue Nov 5 15:15:17 2013 +0100
b0a773
b0a773
    genesys: avoid infinite loop
b0a773
b0a773
    The stray semicolon prevents executing the loop which could reset the
b0a773
    REG41_FEBUSY bit.
b0a773
b0a773
    (cherry picked from commit b53a58c4b534b9e6897c1b0a6301d2bf76dc3499)
b0a773
b0a773
commit bde7ee0c9e0bde21fc8b01af11270ca51110a89d
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Tue Nov 5 15:12:20 2013 +0100
b0a773
b0a773
    pixma: avoid buffer overflows
b0a773
b0a773
    (cherry picked from commit 575f40a0790bb5e20ffd7ccae1c9272e481bbe51)
b0a773
b0a773
commit ee3953fb5b11a26a42bee3d75ee6b93da0bb112f
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Tue Nov 5 14:52:22 2013 +0100
b0a773
b0a773
    pixma: u32tohex(): shift first, then cast to uint8_t
b0a773
b0a773
    (cherry picked from commit cf9129d62fe7e84479e8daf6018cd2495d53bcc9)
b0a773
b0a773
commit ef85481800383cf082ad6aa4a944765ee84027c0
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Tue Nov 5 14:47:27 2013 +0100
b0a773
b0a773
    remove code which is never reached
b0a773
b0a773
    (cherry picked from commit 66cb9b55c2e60503d537d7ed927f5a5aef3658d2)
b0a773
b0a773
commit 0864f4d6203ba8f1306af0d39a09dff2f9d4706a
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Tue Nov 5 14:17:12 2013 +0100
b0a773
b0a773
    genesys: fix some memory leaks
b0a773
b0a773
    (cherry picked from commit 252ccdd926bb28bd6064da7b652e646664226572)
b0a773
b0a773
commit a4d72c0e2ebb1f6352f21a300bbff67d439cd77f
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Tue Nov 5 13:56:28 2013 +0100
b0a773
b0a773
    epson: ensure that command() allocates enough memory
b0a773
b0a773
    (cherry picked from commit 8cd2d36f1e9a5b5633d4b8334acf5c8f68381415)
b0a773
b0a773
commit 67af3b80508c0a0adb0fe89ead7c4cb570d7400c
b0a773
Author: Nils Philippsen <nils@redhat.com>
b0a773
Date:   Tue Nov 5 11:39:56 2013 +0100
b0a773
b0a773
    genesys: avoid dereferencing null pointer
b0a773
b0a773
    (cherry picked from commit 56104b5329076d45caf2e04a2271f40a2699f71f)
b0a773
---
b0a773
 backend/epson.c           | 36 +++++++++++++++++++++----------
b0a773
 backend/genesys.c         |  9 +++++---
b0a773
 backend/genesys_devices.c |  3 +++
b0a773
 backend/genesys_gl124.c   | 21 ++++++++++++++++--
b0a773
 backend/genesys_gl843.c   | 20 +++++++++++++++--
b0a773
 backend/genesys_gl846.c   | 55 ++++++++++++++++++++++++++---------------------
b0a773
 backend/genesys_gl847.c   | 21 ++++++++++++++++--
b0a773
 backend/genesys_low.h     |  1 -
b0a773
 backend/kodakaio.c        |  6 +++---
b0a773
 backend/pixma_bjnp.c      | 18 ++++++++++------
b0a773
 backend/rts8891.c         | 16 ++++++--------
b0a773
 sanei/sanei_usb.c         |  2 --
b0a773
 tools/sane-find-scanner.c |  2 --
b0a773
 13 files changed, 141 insertions(+), 69 deletions(-)
b0a773
b0a773
diff --git a/backend/epson.c b/backend/epson.c
b0a773
index 2cae65a..3b063b9 100644
b0a773
--- a/backend/epson.c
b0a773
+++ b/backend/epson.c
b0a773
@@ -818,6 +818,12 @@ typedef struct
b0a773
 
b0a773
 } EpsonIdentRec, *EpsonIdent;
b0a773
 
b0a773
+typedef union
b0a773
+{
b0a773
+  EpsonHdrRec hdr;
b0a773
+  EpsonIdentRec ident;
b0a773
+} EpsonHdrUnionRec, *EpsonHdrUnion;
b0a773
+
b0a773
 
b0a773
 typedef struct
b0a773
 {
b0a773
@@ -843,7 +849,7 @@ typedef struct
b0a773
  *
b0a773
  */
b0a773
 
b0a773
-static EpsonHdr command (Epson_Scanner * s, u_char * cmd, size_t cmd_size,
b0a773
+static EpsonHdrUnion command (Epson_Scanner * s, u_char * cmd, size_t cmd_size,
b0a773
                          SANE_Status * status);
b0a773
 static SANE_Status get_identity_information (SANE_Handle handle);
b0a773
 static SANE_Status get_identity2_information (SANE_Handle handle);
b0a773
@@ -1844,21 +1850,24 @@ static Epson_Device *first_dev = NULL;  /* first EPSON scanner in list */
b0a773
 static Epson_Scanner *first_handle = NULL;
b0a773
 
b0a773
 
b0a773
-static EpsonHdr
b0a773
+static EpsonHdrUnion
b0a773
 command (Epson_Scanner * s, u_char * cmd, size_t cmd_size,
b0a773
          SANE_Status * status)
b0a773
 {
b0a773
+  EpsonHdrUnion hdrunion, hdrunion_bak;
b0a773
   EpsonHdr head;
b0a773
   u_char *buf;
b0a773
   int count;
b0a773
 
b0a773
-  if (NULL == (head = walloc (EpsonHdrRec)))
b0a773
+  if (NULL == (hdrunion = walloc (EpsonHdrUnionRec)))
b0a773
   {
b0a773
     DBG (1, "out of memory (line %d)\n", __LINE__);
b0a773
     *status = SANE_STATUS_NO_MEM;
b0a773
-    return (EpsonHdr) 0;
b0a773
+    return (EpsonHdrUnion) 0;
b0a773
   }
b0a773
 
b0a773
+  head = &(hdrunion->hdr);
b0a773
+
b0a773
   send (s, cmd, cmd_size, status);
b0a773
 
b0a773
   if (SANE_STATUS_GOOD != *status)
b0a773
@@ -1869,7 +1878,7 @@ command (Epson_Scanner * s, u_char * cmd, size_t cmd_size,
b0a773
     *status = SANE_STATUS_GOOD;
b0a773
     send (s, cmd, cmd_size, status);
b0a773
     if (SANE_STATUS_GOOD != *status)
b0a773
-      return (EpsonHdr) 0;
b0a773
+      return (EpsonHdrUnion) 0;
b0a773
   }
b0a773
 
b0a773
   buf = (u_char *) head;
b0a773
@@ -1892,7 +1901,7 @@ command (Epson_Scanner * s, u_char * cmd, size_t cmd_size,
b0a773
   }
b0a773
 
b0a773
   if (SANE_STATUS_GOOD != *status)
b0a773
-    return (EpsonHdr) 0;
b0a773
+    return (EpsonHdrUnion) 0;
b0a773
 
b0a773
   DBG (4, "code   %02x\n", (int) head->code);
b0a773
 
b0a773
@@ -1921,25 +1930,30 @@ command (Epson_Scanner * s, u_char * cmd, size_t cmd_size,
b0a773
     }
b0a773
 
b0a773
     if (SANE_STATUS_GOOD != *status)
b0a773
-      return (EpsonHdr) 0;
b0a773
+      return (EpsonHdrUnion) 0;
b0a773
 
b0a773
     DBG (4, "status %02x\n", (int) head->status);
b0a773
 
b0a773
     count = head->count2 * 255 + head->count1;
b0a773
     DBG (4, "count  %d\n", count);
b0a773
 
b0a773
-    if (NULL == (head = realloc (head, sizeof (EpsonHdrRec) + count)))
b0a773
+    hdrunion_bak = hdrunion;
b0a773
+    if (NULL == (hdrunion = realloc (hdrunion,
b0a773
+            sizeof (EpsonHdrUnionRec) + count)))
b0a773
     {
b0a773
+      free(hdrunion_bak);
b0a773
       DBG (1, "out of memory (line %d)\n", __LINE__);
b0a773
       *status = SANE_STATUS_NO_MEM;
b0a773
-      return (EpsonHdr) 0;
b0a773
+      return (EpsonHdrUnion) 0;
b0a773
     }
b0a773
 
b0a773
+    head = &(hdrunion->hdr);
b0a773
+
b0a773
     buf = head->buf;
b0a773
     receive (s, buf, count, status);
b0a773
 
b0a773
     if (SANE_STATUS_GOOD != *status)
b0a773
-      return (EpsonHdr) 0;
b0a773
+      return (EpsonHdrUnion) 0;
b0a773
 
b0a773
     break;
b0a773
 
b0a773
@@ -1953,7 +1967,7 @@ command (Epson_Scanner * s, u_char * cmd, size_t cmd_size,
b0a773
     break;
b0a773
   }
b0a773
 
b0a773
-  return head;
b0a773
+  return hdrunion;
b0a773
 }
b0a773
 
b0a773
 
b0a773
diff --git a/backend/genesys.c b/backend/genesys.c
b0a773
index 6e7caad..e2c92e7 100644
b0a773
--- a/backend/genesys.c
b0a773
+++ b/backend/genesys.c
b0a773
@@ -5977,7 +5977,7 @@ attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait)
b0a773
   Genesys_Device *dev = 0;
b0a773
   SANE_Int dn, vendor, product;
b0a773
   SANE_Status status;
b0a773
-  int i;
b0a773
+  unsigned int i;
b0a773
 
b0a773
 
b0a773
   DBG (DBG_proc, "attach: start: devp %s NULL, may_wait = %d\n",
b0a773
@@ -6061,7 +6061,10 @@ attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait)
b0a773
 
b0a773
   dev->file_name = strdup (devname);
b0a773
   if (!dev->file_name)
b0a773
-    return SANE_STATUS_NO_MEM;
b0a773
+    {
b0a773
+      free(dev);
b0a773
+      return SANE_STATUS_NO_MEM;
b0a773
+    }
b0a773
 
b0a773
   dev->model = genesys_usb_device_list[i].model;
b0a773
   dev->vendorId = genesys_usb_device_list[i].vendor;
b0a773
@@ -6630,7 +6633,7 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
b0a773
 		  first_dev = dev->next;
b0a773
 		  num_devices--;
b0a773
 		  free (dev);
b0a773
-	          dev = prev->next;
b0a773
+	          dev = first_dev;
b0a773
 		}
b0a773
 	    }
b0a773
 	  /* case 2 : removed device is not first_dev */
b0a773
diff --git a/backend/genesys_devices.c b/backend/genesys_devices.c
b0a773
index fb3cd43..462c4a9 100644
b0a773
--- a/backend/genesys_devices.c
b0a773
+++ b/backend/genesys_devices.c
b0a773
@@ -3413,3 +3413,6 @@ static Genesys_USB_Device_Entry genesys_usb_device_list[] = {
b0a773
   {0x04a9, 0x190a, &canon_lide_210_model},
b0a773
   {0, 0, NULL}
b0a773
 };
b0a773
+
b0a773
+#define MAX_SCANNERS (sizeof(genesys_usb_device_list) / \
b0a773
+        sizeof(genesys_usb_device_list[0]))
b0a773
diff --git a/backend/genesys_gl124.c b/backend/genesys_gl124.c
b0a773
index 9e2fb8a..4a4b642 100644
b0a773
--- a/backend/genesys_gl124.c
b0a773
+++ b/backend/genesys_gl124.c
b0a773
@@ -2246,7 +2246,7 @@ gl124_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
b0a773
   /* TODO add scan_mode to the API */
b0a773
   scan_mode= dev->settings.scan_mode;
b0a773
   dev->settings.scan_mode=SCAN_MODE_GRAY;
b0a773
-  gl124_init_scan_regs (dev,
b0a773
+  status = gl124_init_scan_regs (dev,
b0a773
 			local_reg,
b0a773
 			resolution,
b0a773
 			resolution,
b0a773
@@ -2260,6 +2260,15 @@ gl124_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
b0a773
 			SCAN_FLAG_DISABLE_SHADING |
b0a773
 			SCAN_FLAG_DISABLE_GAMMA |
b0a773
 			SCAN_FLAG_IGNORE_LINE_DISTANCE);
b0a773
+  if (status != SANE_STATUS_GOOD)
b0a773
+    {
b0a773
+      DBG (DBG_error,
b0a773
+           "gl124_slow_back_home: failed to set up registers: %s\n",
b0a773
+           sane_strstatus (status));
b0a773
+      DBGCOMPLETED;
b0a773
+      return status;
b0a773
+    }
b0a773
+
b0a773
   dev->settings.scan_mode=scan_mode;
b0a773
 
b0a773
   /* clear scan and feed count */
b0a773
@@ -2348,7 +2357,7 @@ gl124_feed (Genesys_Device * dev, unsigned int steps)
b0a773
   memcpy (local_reg, dev->reg, GENESYS_GL124_MAX_REGS * sizeof (Genesys_Register_Set));
b0a773
 
b0a773
   resolution=sanei_genesys_get_lowest_ydpi(dev);
b0a773
-  gl124_init_scan_regs (dev,
b0a773
+  status = gl124_init_scan_regs (dev,
b0a773
 			local_reg,
b0a773
 			resolution,
b0a773
 			resolution,
b0a773
@@ -2364,6 +2373,14 @@ gl124_feed (Genesys_Device * dev, unsigned int steps)
b0a773
                         SCAN_FLAG_FEEDING |
b0a773
 			SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE |
b0a773
 			SCAN_FLAG_IGNORE_LINE_DISTANCE);
b0a773
+  if (status != SANE_STATUS_GOOD)
b0a773
+    {
b0a773
+      DBG (DBG_error,
b0a773
+           "gl124_feed: failed to set up registers: %s\n",
b0a773
+           sane_strstatus (status));
b0a773
+      DBGCOMPLETED;
b0a773
+      return status;
b0a773
+    }
b0a773
 
b0a773
   /* set exposure to zero */
b0a773
   sanei_genesys_set_triple(local_reg,REG_EXPR,0);
b0a773
diff --git a/backend/genesys_gl843.c b/backend/genesys_gl843.c
b0a773
index 3648d09..6cddd4f 100644
b0a773
--- a/backend/genesys_gl843.c
b0a773
+++ b/backend/genesys_gl843.c
b0a773
@@ -2591,7 +2591,7 @@ gl843_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
b0a773
   memcpy (local_reg, dev->reg, GENESYS_GL843_MAX_REGS * sizeof (Genesys_Register_Set));
b0a773
   resolution=sanei_genesys_get_lowest_ydpi(dev);
b0a773
 
b0a773
-  gl843_init_scan_regs (dev,
b0a773
+  status = gl843_init_scan_regs (dev,
b0a773
 			local_reg,
b0a773
 			resolution,
b0a773
 			resolution,
b0a773
@@ -2607,6 +2607,14 @@ gl843_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
b0a773
 			SCAN_FLAG_DISABLE_GAMMA |
b0a773
 			SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE |
b0a773
 			SCAN_FLAG_IGNORE_LINE_DISTANCE);
b0a773
+  if (status != SANE_STATUS_GOOD)
b0a773
+    {
b0a773
+      DBG (DBG_error,
b0a773
+           "gl843_slow_back_home: failed to set up registers: %s\n",
b0a773
+           sane_strstatus (status));
b0a773
+      DBGCOMPLETED;
b0a773
+      return status;
b0a773
+    }
b0a773
 
b0a773
   /* clear scan and feed count */
b0a773
   RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRLNCNT | REG0D_CLRMCNT));
b0a773
@@ -2879,7 +2887,7 @@ gl843_feed (Genesys_Device * dev, unsigned int steps)
b0a773
   memcpy (local_reg, dev->reg, GENESYS_GL843_MAX_REGS * sizeof (Genesys_Register_Set));
b0a773
 
b0a773
   resolution=sanei_genesys_get_lowest_ydpi(dev);
b0a773
-  gl843_init_scan_regs (dev,
b0a773
+  status = gl843_init_scan_regs (dev,
b0a773
 			local_reg,
b0a773
 			resolution,
b0a773
 			resolution,
b0a773
@@ -2895,6 +2903,14 @@ gl843_feed (Genesys_Device * dev, unsigned int steps)
b0a773
 			SCAN_FLAG_DISABLE_GAMMA |
b0a773
                         SCAN_FLAG_FEEDING |
b0a773
 			SCAN_FLAG_IGNORE_LINE_DISTANCE);
b0a773
+  if (status != SANE_STATUS_GOOD)
b0a773
+    {
b0a773
+      DBG (DBG_error,
b0a773
+           "gl843_feed: failed to set up registers: %s\n",
b0a773
+           sane_strstatus (status));
b0a773
+      DBGCOMPLETED;
b0a773
+      return status;
b0a773
+    }
b0a773
 
b0a773
   /* clear scan and feed count */
b0a773
   RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRLNCNT));
b0a773
diff --git a/backend/genesys_gl846.c b/backend/genesys_gl846.c
b0a773
index 5e1f0f4..c810604 100644
b0a773
--- a/backend/genesys_gl846.c
b0a773
+++ b/backend/genesys_gl846.c
b0a773
@@ -633,7 +633,7 @@ gl846_set_adi_fe (Genesys_Device * dev, uint8_t set)
b0a773
 
b0a773
   /* wait for FE to be ready */
b0a773
   status = sanei_genesys_get_status (dev, &val8);
b0a773
-  while (val8 & REG41_FEBUSY);
b0a773
+  while (val8 & REG41_FEBUSY)
b0a773
     {
b0a773
       usleep (10000);
b0a773
       status = sanei_genesys_get_status (dev, &val8);
b0a773
@@ -1975,7 +1975,7 @@ gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
b0a773
   /* TODO add scan_mode to the API */
b0a773
   scan_mode= dev->settings.scan_mode;
b0a773
   dev->settings.scan_mode=SCAN_MODE_LINEART;
b0a773
-  gl846_init_scan_regs (dev,
b0a773
+  status = gl846_init_scan_regs (dev,
b0a773
 			local_reg,
b0a773
 			resolution,
b0a773
 			resolution,
b0a773
@@ -1989,6 +1989,14 @@ gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
b0a773
 			SCAN_FLAG_DISABLE_SHADING |
b0a773
 			SCAN_FLAG_DISABLE_GAMMA |
b0a773
 			SCAN_FLAG_IGNORE_LINE_DISTANCE);
b0a773
+  if (status != SANE_STATUS_GOOD)
b0a773
+    {
b0a773
+      DBG (DBG_error,
b0a773
+           "gl846_slow_back_home: failed to set up registers: %s\n",
b0a773
+           sane_strstatus (status));
b0a773
+      DBGCOMPLETED;
b0a773
+      return status;
b0a773
+    }
b0a773
   dev->settings.scan_mode=scan_mode;
b0a773
 
b0a773
   /* clear scan and feed count */
b0a773
@@ -2255,7 +2263,7 @@ gl846_feed (Genesys_Device * dev, unsigned int steps)
b0a773
   memcpy (local_reg, dev->reg, GENESYS_GL846_MAX_REGS * sizeof (Genesys_Register_Set));
b0a773
 
b0a773
   resolution=sanei_genesys_get_lowest_ydpi(dev);
b0a773
-  gl846_init_scan_regs (dev,
b0a773
+  status = gl846_init_scan_regs (dev,
b0a773
 			local_reg,
b0a773
 			resolution,
b0a773
 			resolution,
b0a773
@@ -2270,6 +2278,14 @@ gl846_feed (Genesys_Device * dev, unsigned int steps)
b0a773
 			SCAN_FLAG_DISABLE_GAMMA |
b0a773
                         SCAN_FLAG_FEEDING |
b0a773
 			SCAN_FLAG_IGNORE_LINE_DISTANCE);
b0a773
+  if (status != SANE_STATUS_GOOD)
b0a773
+    {
b0a773
+      DBG (DBG_error,
b0a773
+           "gl846_feed: failed to set up registers: %s\n",
b0a773
+           sane_strstatus (status));
b0a773
+      DBGCOMPLETED;
b0a773
+      return status;
b0a773
+    }
b0a773
 
b0a773
   /* set exposure to zero */
b0a773
   sanei_genesys_set_triple(local_reg,REG_EXPR,0);
b0a773
@@ -2583,13 +2599,14 @@ gl846_send_shading_data (Genesys_Device * dev, uint8_t * data, int size)
b0a773
           ptr+=4;
b0a773
         }
b0a773
 
b0a773
-      RIE (sanei_genesys_read_register (dev, 0xd0+i, &val));
b0a773
+      RIEF (sanei_genesys_read_register (dev, 0xd0+i, &val), buffer);
b0a773
       addr = val * 8192 + 0x10000000;
b0a773
       status = sanei_genesys_write_ahb (dev->dn, dev->usb_mode, addr, pixels, buffer);
b0a773
       if (status != SANE_STATUS_GOOD)
b0a773
         {
b0a773
           DBG (DBG_error, "gl846_send_shading_data; write to AHB failed (%s)\n",
b0a773
 	      sane_strstatus (status));
b0a773
+          free(buffer);
b0a773
           return status;
b0a773
         }
b0a773
     }
b0a773
@@ -3013,7 +3030,15 @@ gl846_search_strip (Genesys_Device * dev, SANE_Bool forward, SANE_Bool black)
b0a773
   DBG (DBG_proc, "gl846_search_strip %s %s\n", black ? "black" : "white",
b0a773
        forward ? "forward" : "reverse");
b0a773
 
b0a773
-  gl846_set_fe (dev, AFE_SET);
b0a773
+  status = gl846_set_fe (dev, AFE_SET);
b0a773
+  if (status != SANE_STATUS_GOOD)
b0a773
+    {
b0a773
+      DBG (DBG_error,
b0a773
+           "gl846_search_strip: gl846_set_fe() failed: %s\n",
b0a773
+           sane_strstatus(status));
b0a773
+      return status;
b0a773
+    }
b0a773
+
b0a773
   status = gl846_stop_action (dev);
b0a773
   if (status != SANE_STATUS_GOOD)
b0a773
     {
b0a773
@@ -3572,24 +3597,10 @@ gl846_coarse_gain_calibration (Genesys_Device * dev, int dpi)
b0a773
       max[j] = 0;
b0a773
       for (i = pixels/4; i < (pixels*3/4); i++)
b0a773
 	{
b0a773
-          if(bpp==16)
b0a773
-            {
b0a773
-	  if (dev->model->is_cis)
b0a773
-	    val =
b0a773
-	      line[i * 2 + j * 2 * pixels + 1] * 256 +
b0a773
-	      line[i * 2 + j * 2 * pixels];
b0a773
-	  else
b0a773
-	    val =
b0a773
-	      line[i * 2 * channels + 2 * j + 1] * 256 +
b0a773
-	      line[i * 2 * channels + 2 * j];
b0a773
-            }
b0a773
-          else
b0a773
-            {
b0a773
 	  if (dev->model->is_cis)
b0a773
 	    val = line[i + j * pixels];
b0a773
 	  else
b0a773
 	    val = line[i * channels + j];
b0a773
-            }
b0a773
 
b0a773
 	    max[j] += val;
b0a773
 	}
b0a773
@@ -3619,12 +3630,6 @@ gl846_coarse_gain_calibration (Genesys_Device * dev, int dpi)
b0a773
       dev->frontend.gain[2] = dev->frontend.gain[1] = dev->frontend.gain[0];
b0a773
     }
b0a773
 
b0a773
-  if (channels == 1)
b0a773
-    {
b0a773
-      dev->frontend.gain[0] = dev->frontend.gain[1];
b0a773
-      dev->frontend.gain[2] = dev->frontend.gain[1];
b0a773
-    }
b0a773
-
b0a773
   free (line);
b0a773
 
b0a773
   RIE (gl846_stop_action (dev));
b0a773
diff --git a/backend/genesys_gl847.c b/backend/genesys_gl847.c
b0a773
index 7c6a3c3..47171b9 100644
b0a773
--- a/backend/genesys_gl847.c
b0a773
+++ b/backend/genesys_gl847.c
b0a773
@@ -1995,7 +1995,7 @@ gl847_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
b0a773
   /* TODO add scan_mode to the API */
b0a773
   scan_mode= dev->settings.scan_mode;
b0a773
   dev->settings.scan_mode=SCAN_MODE_LINEART;
b0a773
-  gl847_init_scan_regs (dev,
b0a773
+  status = gl847_init_scan_regs (dev,
b0a773
 			local_reg,
b0a773
 			resolution,
b0a773
 			resolution,
b0a773
@@ -2009,6 +2009,15 @@ gl847_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
b0a773
 			SCAN_FLAG_DISABLE_SHADING |
b0a773
 			SCAN_FLAG_DISABLE_GAMMA |
b0a773
 			SCAN_FLAG_IGNORE_LINE_DISTANCE);
b0a773
+  if (status != SANE_STATUS_GOOD)
b0a773
+    {
b0a773
+      DBG (DBG_error,
b0a773
+           "gl847_slow_back_home: failed to set up registers: %s\n",
b0a773
+           sane_strstatus (status));
b0a773
+      DBGCOMPLETED;
b0a773
+      return status;
b0a773
+    }
b0a773
+
b0a773
   dev->settings.scan_mode=scan_mode;
b0a773
 
b0a773
   /* clear scan and feed count */
b0a773
@@ -2276,7 +2285,7 @@ gl847_feed (Genesys_Device * dev, unsigned int steps)
b0a773
   memcpy (local_reg, dev->reg, GENESYS_GL847_MAX_REGS * sizeof (Genesys_Register_Set));
b0a773
 
b0a773
   resolution=sanei_genesys_get_lowest_ydpi(dev);
b0a773
-  gl847_init_scan_regs (dev,
b0a773
+  status = gl847_init_scan_regs (dev,
b0a773
 			local_reg,
b0a773
 			resolution,
b0a773
 			resolution,
b0a773
@@ -2291,6 +2300,14 @@ gl847_feed (Genesys_Device * dev, unsigned int steps)
b0a773
 			SCAN_FLAG_DISABLE_GAMMA |
b0a773
                         SCAN_FLAG_FEEDING |
b0a773
 			SCAN_FLAG_IGNORE_LINE_DISTANCE);
b0a773
+  if (status != SANE_STATUS_GOOD)
b0a773
+    {
b0a773
+      DBG (DBG_error,
b0a773
+           "gl847_feed: failed to set up registers: %s\n",
b0a773
+           sane_strstatus (status));
b0a773
+      DBGCOMPLETED;
b0a773
+      return status;
b0a773
+    }
b0a773
 
b0a773
   /* set exposure to zero */
b0a773
   sanei_genesys_set_triple(local_reg,REG_EXPR,0);
b0a773
diff --git a/backend/genesys_low.h b/backend/genesys_low.h
b0a773
index 1d5ef22..31e0541 100644
b0a773
--- a/backend/genesys_low.h
b0a773
+++ b/backend/genesys_low.h
b0a773
@@ -310,7 +310,6 @@ typedef enum Genesys_Color_Order
b0a773
 Genesys_Color_Order;
b0a773
 
b0a773
 
b0a773
-#define MAX_SCANNERS 50
b0a773
 #define MAX_RESOLUTIONS 13
b0a773
 #define MAX_DPI 4
b0a773
 
b0a773
diff --git a/backend/kodakaio.c b/backend/kodakaio.c
b0a773
index 8c4583a..901f7a8 100644
b0a773
--- a/backend/kodakaio.c
b0a773
+++ b/backend/kodakaio.c
b0a773
@@ -3131,14 +3131,14 @@ sane_control_option(SANE_Handle handle, SANE_Int option, SANE_Action action,
b0a773
 		    void *value, SANE_Int *info)
b0a773
 {
b0a773
 	KodakAio_Scanner *s = (KodakAio_Scanner *) handle;
b0a773
-	DBG(2, "%s: action = %x, option = %d %s\n", __func__, action, option, s->opt[option].name);
b0a773
-
b0a773
 	if (option < 0 || option >= NUM_OPTIONS)
b0a773
 	{
b0a773
-		DBG(1, "%s: option num = %d (%s) out of range\n", __func__, option, s->opt[option].name);
b0a773
+		DBG(1, "%s: option num = %d out of range (0..%d)\n", __func__, option, NUM_OPTIONS - 1);
b0a773
 		return SANE_STATUS_INVAL;
b0a773
 	}
b0a773
 
b0a773
+	DBG(2, "%s: action = %x, option = %d %s\n", __func__, action, option, s->opt[option].name);
b0a773
+
b0a773
 	if (info != NULL)
b0a773
 		*info = 0;
b0a773
 
b0a773
diff --git a/backend/pixma_bjnp.c b/backend/pixma_bjnp.c
b0a773
index a1730ad..1020b8d 100644
b0a773
--- a/backend/pixma_bjnp.c
b0a773
+++ b/backend/pixma_bjnp.c
b0a773
@@ -130,11 +130,11 @@ static void
b0a773
 u32tohex (uint32_t x, char *str)
b0a773
 {
b0a773
   uint8_t uint8[4];
b0a773
-   uint8[0]= (uint8_t) x >> 24;
b0a773
-   uint8[1] = (uint8_t)x >> 16;
b0a773
-   uint8[2] = (uint8_t)x >> 8;
b0a773
-   uint8[3] = (uint8_t)x ;
b0a773
-   u8tohex(str, uint8, 4);
b0a773
+  uint8[0] = (uint8_t)(x >> 24);
b0a773
+  uint8[1] = (uint8_t)(x >> 16);
b0a773
+  uint8[2] = (uint8_t)(x >> 8);
b0a773
+  uint8[3] = (uint8_t)x ;
b0a773
+  u8tohex(str, uint8, 4);
b0a773
 }
b0a773
 
b0a773
 static void
b0a773
@@ -284,7 +284,8 @@ parse_IEEE1284_to_model (char *scanner_id, char *model)
b0a773
   char s[BJNP_IEEE1284_MAX];
b0a773
   char *tok;
b0a773
 
b0a773
-  strcpy (s, scanner_id);
b0a773
+  strncpy (s, scanner_id, BJNP_IEEE1284_MAX);
b0a773
+  s[BJNP_IEEE1284_MAX - 1] = '\0';
b0a773
   model[0] = '\0';
b0a773
 
b0a773
   tok = strtok (s, ";");
b0a773
@@ -441,7 +442,8 @@ split_uri (const char *devname, char *method, char *host, char *port,
b0a773
   char next;
b0a773
   int i;
b0a773
 
b0a773
-  strcpy (copy, devname);
b0a773
+  strncpy (copy, devname, 1024);
b0a773
+  copy[1023] = '\0';
b0a773
   start = copy;
b0a773
 
b0a773
 /*
b0a773
@@ -2313,6 +2315,8 @@ sanei_bjnp_read_int (SANE_Int dn, SANE_Byte * buffer, size_t * size)
b0a773
         }
b0a773
       device[dn].polling_status = BJNP_POLL_STARTED;
b0a773
 
b0a773
+      /* fall through to BJNP_POLL_STARTED */
b0a773
+
b0a773
     case BJNP_POLL_STARTED:
b0a773
       /* we use only seonds accuracy between poll attempts */
b0a773
       timeout = device[dn].bjnp_timeout /1000;
b0a773
diff --git a/backend/rts8891.c b/backend/rts8891.c
b0a773
index d86347b..bdb4011 100644
b0a773
--- a/backend/rts8891.c
b0a773
+++ b/backend/rts8891.c
b0a773
@@ -2212,7 +2212,13 @@ sane_close (SANE_Handle handle)
b0a773
   /* switch off lamp and close usb */
b0a773
   if (dev->conf.allowsharing == SANE_TRUE)
b0a773
     {
b0a773
-      sanei_usb_claim_interface (dev->devnum, 0);
b0a773
+      SANE_Status status = sanei_usb_claim_interface (dev->devnum, 0);
b0a773
+      if (status != SANE_STATUS_GOOD)
b0a773
+        {
b0a773
+          DBG (DBG_warn, "sane_close: cannot claim usb interface: %s\n",
b0a773
+               sane_strstatus(status));
b0a773
+          DBG (DBG_warn, "sane_close: continuing anyway\n");
b0a773
+        }
b0a773
     }
b0a773
   set_lamp_state (session, 0);
b0a773
   sanei_usb_close (dev->devnum);
b0a773
@@ -3197,14 +3203,6 @@ find_origin (struct Rts8891_Device *dev, SANE_Bool * changed)
b0a773
       return status;
b0a773
     }
b0a773
 
b0a773
-  if (status != SANE_STATUS_GOOD)
b0a773
-    {
b0a773
-      free(image);
b0a773
-      free(data);
b0a773
-      DBG (DBG_error, "find_origin: failed to wait for data\n");
b0a773
-      return status;
b0a773
-    }
b0a773
-
b0a773
   if (DBG_LEVEL > DBG_io2)
b0a773
     {
b0a773
       write_gray_data (data, "find_origin.pnm", width, height);
b0a773
diff --git a/sanei/sanei_usb.c b/sanei/sanei_usb.c
b0a773
index 7401658..491ceeb 100644
b0a773
--- a/sanei/sanei_usb.c
b0a773
+++ b/sanei/sanei_usb.c
b0a773
@@ -460,8 +460,6 @@ sanei_libusb_strerror (int errcode)
b0a773
       default:
b0a773
 	return "Unknown libusb-1.0 error code";
b0a773
     }
b0a773
-
b0a773
-  return "Unknown libusb-1.0 error code";
b0a773
 }
b0a773
 #endif /* HAVE_LIBUSB_1_0 */
b0a773
 
b0a773
diff --git a/tools/sane-find-scanner.c b/tools/sane-find-scanner.c
b0a773
index dbfd0da..ae0e116 100644
b0a773
--- a/tools/sane-find-scanner.c
b0a773
+++ b/tools/sane-find-scanner.c
b0a773
@@ -757,8 +757,6 @@ sfs_libusb_strerror (int errcode)
b0a773
       default:
b0a773
 	return "Unknown libusb-1.0 error code";
b0a773
     }
b0a773
-
b0a773
-  return "Unknown libusb-1.0 error code";
b0a773
 }
b0a773
 
b0a773
 static char *
b0a773
-- 
b0a773
1.8.4.2
b0a773