cppcheck errors and warings fixes

merge-requests/1/head
Stphane Voltz 2013-02-14 21:19:51 +01:00
rodzic d7d91aa1e0
commit 6b78c69876
2 zmienionych plików z 46 dodań i 22 usunięć

Wyświetl plik

@ -1,6 +1,6 @@
/* sane - Scanner Access Now Easy. /* sane - Scanner Access Now Easy.
Copyright (C) 2007-2012 stef.dev@free.fr Copyright (C) 2007-2013 stef.dev@free.fr
This file is part of the SANE package. This file is part of the SANE package.
@ -567,11 +567,12 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking)
SANE_Status SANE_Status
sane_get_select_fd (SANE_Handle handle, SANE_Int * fdp) sane_get_select_fd (SANE_Handle handle, SANE_Int * fdp)
{ {
/* make compiler happy ... */
handle = handle;
fdp = fdp;
DBG (DBG_proc, "sane_get_select_fd: start\n"); DBG (DBG_proc, "sane_get_select_fd: start\n");
if(handle==0 || fdp==NULL)
{
return SANE_STATUS_INVAL;
}
DBG (DBG_warn, "sane_get_select_fd: unsupported ...\n"); DBG (DBG_warn, "sane_get_select_fd: unsupported ...\n");
DBG (DBG_proc, "sane_get_select_fd: exit\n"); DBG (DBG_proc, "sane_get_select_fd: exit\n");
return SANE_STATUS_UNSUPPORTED; return SANE_STATUS_UNSUPPORTED;
@ -1068,7 +1069,7 @@ SANE_Status
sane_start (SANE_Handle handle) sane_start (SANE_Handle handle)
{ {
struct Rts8891_Session *session = handle; struct Rts8891_Session *session = handle;
int ret = SANE_STATUS_GOOD, light, mode; int light, mode;
struct Rts8891_Device *dev = session->dev; struct Rts8891_Device *dev = session->dev;
SANE_Status status; SANE_Status status;
SANE_Bool changed; SANE_Bool changed;
@ -1376,13 +1377,13 @@ sane_start (SANE_Handle handle)
/* commit the scan */ /* commit the scan */
/* TODO send_calibration seems to embbed its commit */ /* TODO send_calibration seems to embbed its commit */
sanei_rts88xx_cancel (dev->devnum); sanei_rts88xx_cancel (dev->devnum);
status = sanei_rts88xx_write_control (dev->devnum, 0x08); sanei_rts88xx_write_control (dev->devnum, 0x08);
status = sanei_rts88xx_write_control (dev->devnum, 0x08); status = sanei_rts88xx_write_control (dev->devnum, 0x08);
session->scanning = SANE_TRUE; session->scanning = SANE_TRUE;
DBG (DBG_proc, "sane_start: exit\n"); DBG (DBG_proc, "sane_start: exit\n");
return ret; return status;
} }
/** /**
@ -1708,8 +1709,8 @@ SANE_Status
sane_read (SANE_Handle handle, SANE_Byte * buf, sane_read (SANE_Handle handle, SANE_Byte * buf,
SANE_Int max_len, SANE_Int * len) SANE_Int max_len, SANE_Int * len)
{ {
struct Rts8891_Session *session = (struct Rts8891_Session *) handle; struct Rts8891_Session *session;
struct Rts8891_Device *dev = session->dev; struct Rts8891_Device *dev;
SANE_Status status; SANE_Status status;
SANE_Int length; SANE_Int length;
SANE_Int data_size; SANE_Int data_size;
@ -1720,12 +1721,20 @@ sane_read (SANE_Handle handle, SANE_Byte * buf,
DBG (DBG_io, "sane_read: up to %d bytes required by frontend\n", max_len); DBG (DBG_io, "sane_read: up to %d bytes required by frontend\n", max_len);
/* some sanity checks first to protect from would be buggy frontends */ /* some sanity checks first to protect from would be buggy frontends */
if (!session) if (!handle)
{ {
DBG (DBG_error, "sane_read: handle is null!\n"); DBG (DBG_error, "sane_read: handle is null!\n");
return SANE_STATUS_INVAL; return SANE_STATUS_INVAL;
} }
session = (struct Rts8891_Session *) handle;
if (!session)
{
DBG (DBG_error, "sane_read: session is null!\n");
return SANE_STATUS_INVAL;
}
dev = session->dev;
if (!buf) if (!buf)
{ {
DBG (DBG_error, "sane_read: buf is null!\n"); DBG (DBG_error, "sane_read: buf is null!\n");
@ -2388,7 +2397,10 @@ config_attach_rts8891 (SANEI_Config * config, const char *devname)
/* currently, the config is a global variable so config is useless here */ /* currently, the config is a global variable so config is useless here */
/* the correct thing would be to have a generic sanei_attach_matching_devices /* the correct thing would be to have a generic sanei_attach_matching_devices
* using an attach function with a config parameter */ * using an attach function with a config parameter */
config = config; if(config==NULL)
{
return SANE_STATUS_INVAL;
}
/* the devname has been processed and is ready to be used /* the devname has been processed and is ready to be used
* directly. Since the backend is an USB only one, we can * directly. Since the backend is an USB only one, we can
@ -3142,12 +3154,18 @@ find_origin (struct Rts8891_Device *dev, SANE_Bool * changed)
/* allocate memory for the data */ /* allocate memory for the data */
total = width * height; total = width * height;
data = (unsigned char *) malloc (total); data = (unsigned char *) malloc (total);
image = (unsigned char *) malloc (total); if (data == NULL)
if (image == NULL || data == NULL)
{ {
DBG (DBG_error, "find_origin: failed to allocate %d bytes\n", total); DBG (DBG_error, "find_origin: failed to allocate %d bytes\n", total);
return SANE_STATUS_NO_MEM; return SANE_STATUS_NO_MEM;
} }
image = (unsigned char *) malloc (total);
if (image == NULL)
{
free(data);
DBG (DBG_error, "find_origin: failed to allocate %d bytes\n", total);
return SANE_STATUS_NO_MEM;
}
/* set vertical and horizontal start/end positions */ /* set vertical and horizontal start/end positions */
sanei_rts88xx_set_scan_area (dev->regs, starty, starty + height, startx, sanei_rts88xx_set_scan_area (dev->regs, starty, starty + height, startx,
@ -3173,12 +3191,16 @@ find_origin (struct Rts8891_Device *dev, SANE_Bool * changed)
total, data); total, data);
if (status != SANE_STATUS_GOOD) if (status != SANE_STATUS_GOOD)
{ {
free(image);
free(data);
DBG (DBG_error, "find_origin: failed to scan\n"); DBG (DBG_error, "find_origin: failed to scan\n");
return status; return status;
} }
if (status != SANE_STATUS_GOOD) if (status != SANE_STATUS_GOOD)
{ {
free(image);
free(data);
DBG (DBG_error, "find_origin: failed to wait for data\n"); DBG (DBG_error, "find_origin: failed to wait for data\n");
return status; return status;
} }
@ -3450,6 +3472,7 @@ find_margin (struct Rts8891_Device *dev)
total, data); total, data);
if (status != SANE_STATUS_GOOD) if (status != SANE_STATUS_GOOD)
{ {
free(data);
DBG (DBG_error, "find_margin: failed to scan\n"); DBG (DBG_error, "find_margin: failed to scan\n");
return status; return status;
} }

Wyświetl plik

@ -461,9 +461,9 @@ sanei_rts88xx_write_mem (SANE_Int devnum, SANE_Int length, SANE_Int extra,
char message[(0xFFC0 + 10) * 3] = ""; char message[(0xFFC0 + 10) * 3] = "";
buffer = (SANE_Byte *) malloc (length + 10); buffer = (SANE_Byte *) malloc (length + 10);
memset (buffer, 0, length + 10);
if (buffer == NULL) if (buffer == NULL)
return SANE_STATUS_NO_MEM; return SANE_STATUS_NO_MEM;
memset (buffer, 0, length + 10);
buffer[0] = 0x89; buffer[0] = 0x89;
buffer[1] = 0x00; buffer[1] = 0x00;
@ -601,11 +601,13 @@ sanei_rts88xx_get_mem (SANE_Int devnum, SANE_Byte ctrl1,
SANE_Status SANE_Status
sanei_rts88xx_nvram_ctrl (SANE_Int devnum, SANE_Int length, SANE_Byte * value) sanei_rts88xx_nvram_ctrl (SANE_Int devnum, SANE_Int length, SANE_Byte * value)
{ {
SANE_Status status = SANE_STATUS_GOOD; SANE_Status status;
SANE_Int size = 0;
SANE_Int i; SANE_Int i;
SANE_Byte buffer[60];
char message[60 * 5]; char message[60 * 5];
#ifdef HAZARDOUS_EXPERIMENT
SANE_Int size = 0;
SANE_Byte buffer[60];
#endif
if (DBG_LEVEL > DBG_io) if (DBG_LEVEL > DBG_io)
{ {
@ -613,10 +615,11 @@ sanei_rts88xx_nvram_ctrl (SANE_Int devnum, SANE_Int length, SANE_Byte * value)
{ {
sprintf (message + 5 * i, "0x%02x ", value[i]); sprintf (message + 5 * i, "0x%02x ", value[i]);
} }
DBG (DBG_io, "sanei_rts88xx_nvram_ctrl : nvram_ctrl(0x00,%d)=%s\n", DBG (DBG_io, "sanei_rts88xx_nvram_ctrl : devnum=%d, nvram_ctrl(0x00,%d)=%s\n",
length, message); devnum, length, message);
} }
#ifdef HAZARDOUS_EXPERIMENT
buffer[0] = 0x8a; buffer[0] = 0x8a;
buffer[1] = 0x00; buffer[1] = 0x00;
buffer[2] = 0x00; buffer[2] = 0x00;
@ -625,10 +628,8 @@ sanei_rts88xx_nvram_ctrl (SANE_Int devnum, SANE_Int length, SANE_Byte * value)
buffer[i + 4] = value[i]; buffer[i + 4] = value[i];
/* the USB block is size + 4 bytes of header long */ /* the USB block is size + 4 bytes of header long */
size = length + 4; size = length + 4;
#ifdef HAZARDOUS_EXPERIMENT
status = sanei_usb_write_bulk (devnum, buffer, &size); status = sanei_usb_write_bulk (devnum, buffer, &size);
#else #else
devnum = devnum;
status = SANE_STATUS_GOOD; status = SANE_STATUS_GOOD;
#endif #endif
if (status != SANE_STATUS_GOOD) if (status != SANE_STATUS_GOOD)
@ -780,7 +781,7 @@ sanei_rts88xx_wait_data (SANE_Int devnum, SANE_Bool busy, SANE_Word * count)
{ {
DBG (DBG_io, "sanei_rts88xx_wait_data: %d bytes available\n", DBG (DBG_io, "sanei_rts88xx_wait_data: %d bytes available\n",
*count); *count);
return SANE_STATUS_GOOD; return status;
} }
/* check that the scanner is busy scanning */ /* check that the scanner is busy scanning */