misc: Correct a small pile of cppcheck/scan-build warnings.

No actual bugs, thankfully.
This commit is contained in:
Solomon Peachy 2020-01-22 11:25:06 -05:00
parent dcb76902fb
commit a30fa619f1
7 changed files with 43 additions and 42 deletions

View file

@ -1,7 +1,7 @@
/*
* CUPS Backend common code
*
* (c) 2013-2019 Solomon Peachy <pizza@shaftnet.org>
* (c) 2013-2020 Solomon Peachy <pizza@shaftnet.org>
*
* The latest version of this program can be found at:
*

View file

@ -1,7 +1,7 @@
/*
* Citizen / DNP Photo Printer CUPS backend -- libusb-1.0 version
*
* (c) 2013-2019 Solomon Peachy <pizza@shaftnet.org>
* (c) 2013-2020 Solomon Peachy <pizza@shaftnet.org>
*
* Development of this backend was sponsored by:
*
@ -876,10 +876,10 @@ static int dnpds40_attach(void *vctx, struct libusb_device_handle *dev, int type
/* Figure out actual Manufacturer */
{
struct libusb_device_descriptor desc;
struct libusb_device *dev;
struct libusb_device *udev;
dev = libusb_get_device(ctx->dev);
libusb_get_device_descriptor(dev, &desc);
udev = libusb_get_device(ctx->dev);
libusb_get_device_descriptor(udev, &desc);
char buf[256];
buf[0] = 0;
@ -1537,9 +1537,7 @@ parsed:
}
/* Use the larger of the copy arguments */
if (job->copies > copies)
copies = job->copies;
else
if (job->copies < copies)
job->copies = copies;
/* Sanity check matte mode */

View file

@ -1274,7 +1274,7 @@ static int hiti_read_parse(void *vctx, const void **vjob, int data_fd, int copie
{
struct hiti_ctx *ctx = vctx;
struct hiti_printjob *job = NULL;
int i;
int ret;
if (!ctx)
return CUPS_BACKEND_FAILED;
@ -1289,21 +1289,22 @@ static int hiti_read_parse(void *vctx, const void **vjob, int data_fd, int copie
job->copies = copies;
/* Read in header */
i = read(data_fd, &job->hdr, sizeof(job->hdr));
if (i < 0 || i != sizeof(job->hdr)) {
ret = read(data_fd, &job->hdr, sizeof(job->hdr));
if (ret < 0 || ret != sizeof(job->hdr)) {
hiti_cleanup_job(job);
if (i == 0)
if (ret == 0)
return CUPS_BACKEND_CANCEL;
ERROR("Read failed (%d/%d)\n",
i, (int)sizeof(job->hdr));
ret, (int)sizeof(job->hdr));
perror("ERROR: Read failed");
return i;
return ret;
}
/* Byteswap everything */
{
uint32_t *ptr = (uint32_t*) &job->hdr;
int i;
for (i = 0 ; i < (int)(sizeof(job->hdr) / sizeof(uint32_t)) ; i++)
ptr[i] = le32_to_cpu(ptr[i]);
}
@ -1358,16 +1359,16 @@ static int hiti_read_parse(void *vctx, const void **vjob, int data_fd, int copie
/* Read in data */
uint32_t remain = job->hdr.payload_len;
while (remain) {
i = read(data_fd, job->databuf + job->datalen, remain);
if (i < 0) {
ret = read(data_fd, job->databuf + job->datalen, remain);
if (ret < 0) {
ERROR("Read failed (%d/%u/%u)\n",
i, remain, job->datalen);
ret, remain, job->datalen);
perror("ERROR: Read failed");
hiti_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
job->datalen += i;
remain -= i;
job->datalen += ret;
remain -= ret;
}
/* Sanity check against paper */

View file

@ -1,7 +1,7 @@
/*
* Mitsubishi CP-D70/D707 Photo Printer CUPS backend -- libusb-1.0 version
*
* (c) 2013-2019 Solomon Peachy <pizza@shaftnet.org>
* (c) 2013-2020 Solomon Peachy <pizza@shaftnet.org>
*
* The latest version of this program can be found at:
*

View file

@ -1,7 +1,7 @@
/*
/*
* Shinko/Sinfonia CHC-S2145 CUPS backend -- libusb-1.0 version
*
* (c) 2013-2019 Solomon Peachy <pizza@shaftnet.org>
* (c) 2013-2020 Solomon Peachy <pizza@shaftnet.org>
*
* Development of this backend was sponsored by:
*
@ -1191,15 +1191,15 @@ static int shinkos2145_query_stats(void *vctx, struct printerstats *stats)
stats->serial = ctx->serial;
{
struct sinfonia_fwinfo_cmd cmd;
struct sinfonia_fwinfo_cmd fcmd;
struct sinfonia_fwinfo_resp resp;
int num = 0;
cmd.hdr.cmd = cpu_to_le16(SINFONIA_CMD_FWINFO);
cmd.hdr.len = cpu_to_le16(1);
cmd.target = FWINFO_TARGET_MAIN_APP;
fcmd.hdr.cmd = cpu_to_le16(SINFONIA_CMD_FWINFO);
fcmd.hdr.len = cpu_to_le16(1);
fcmd.target = FWINFO_TARGET_MAIN_APP;
num = 0;
if (sinfonia_docmd(&ctx->dev,
(uint8_t*)&cmd, sizeof(cmd),
(uint8_t*)&fcmd, sizeof(fcmd),
(uint8_t*)&resp, sizeof(resp),
&num))
return CUPS_BACKEND_FAILED;

View file

@ -1,7 +1,7 @@
/*
* Shinko/Sinfonia CHC-S6145 CUPS backend -- libusb-1.0 version
*
* (c) 2015-2019 Solomon Peachy <pizza@shaftnet.org>
* (c) 2015-2020 Solomon Peachy <pizza@shaftnet.org>
*
* Low-level documentation was provided by Sinfonia. Thank you!
*
@ -1619,15 +1619,16 @@ static int shinkos6145_query_stats(void *vctx, struct printerstats *stats)
stats->serial = ctx->serial;
{
struct sinfonia_fwinfo_cmd cmd;
struct sinfonia_fwinfo_cmd fcmd;
struct sinfonia_fwinfo_resp resp;
int num = 0;
cmd.hdr.cmd = cpu_to_le16(SINFONIA_CMD_FWINFO);
cmd.hdr.len = cpu_to_le16(1);
cmd.target = FWINFO_TARGET_MAIN_APP;
num = 0;
fcmd.hdr.cmd = cpu_to_le16(SINFONIA_CMD_FWINFO);
fcmd.hdr.len = cpu_to_le16(1);
fcmd.target = FWINFO_TARGET_MAIN_APP;
if (sinfonia_docmd(&ctx->dev,
(uint8_t*)&cmd, sizeof(cmd),
(uint8_t*)&fcmd, sizeof(fcmd),
(uint8_t*)&resp, sizeof(resp),
&num))
return CUPS_BACKEND_FAILED;

View file

@ -1,7 +1,7 @@
/*
* Shinko/Sinfonia CHC-S6245 CUPS backend -- libusb-1.0 version
*
* (c) 2015-2019 Solomon Peachy <pizza@shaftnet.org>
* (c) 2015-2020 Solomon Peachy <pizza@shaftnet.org>
*
* Low-level documentation was provided by Sinfonia, Inc. Thank you!
*
@ -1464,15 +1464,16 @@ static int shinkos6245_query_stats(void *vctx, struct printerstats *stats)
stats->serial = ctx->serial;
{
struct sinfonia_fwinfo_cmd cmd;
struct sinfonia_fwinfo_cmd fcmd;
struct sinfonia_fwinfo_resp resp;
int num = 0;
cmd.hdr.cmd = cpu_to_le16(SINFONIA_CMD_FWINFO);
cmd.hdr.len = cpu_to_le16(1);
cmd.target = FWINFO_TARGET_MAIN_APP;
num = 0;
fcmd.hdr.cmd = cpu_to_le16(SINFONIA_CMD_FWINFO);
fcmd.hdr.len = cpu_to_le16(1);
fcmd.target = FWINFO_TARGET_MAIN_APP;
if (sinfonia_docmd(&ctx->dev,
(uint8_t*)&cmd, sizeof(cmd),
(uint8_t*)&fcmd, sizeof(fcmd),
(uint8_t*)&resp, sizeof(resp),
&num))
return CUPS_BACKEND_FAILED;