misc: Fix up a pile of cppcheck warnings.

* memory leaks in error paths
 * not checking return values in a couple of places
 * logic errors in s1245
This commit is contained in:
Solomon Peachy 2018-04-26 14:45:32 -04:00
parent 6e5ff77e5d
commit c3d9a9b151
8 changed files with 39 additions and 26 deletions

View file

@ -77,7 +77,7 @@ $(BACKENDS): $(EXEC_NAME)
$(LN) -sf $(EXEC_NAME) $@
cppcheck:
$(CPPCHECK) -q -v --std=c99 --enable=all -I/usr/include $(CPPFLAGS) $(SOURCES)
$(CPPCHECK) -q -v --std=c99 --enable=all --suppress=variableScope --suppress=selfAssignment --suppress=unusedStructMember -I. -I/usr/include -DCORRTABLE_PATH=\"$(BACKEND_DATA_DIR)\" --include=lib70x/libMitsuD70ImageReProcess.h $(CPPFLAGS) $(SOURCES)
install:
$(MKDIR) -p $(CUPS_BACKEND_DIR)

View file

@ -589,6 +589,9 @@ static int canonselphy_get_status(struct canonselphy_ctx *ctx)
/* Read in the printer status, twice. */
ret = read_data(ctx->dev, ctx->endp_up,
(uint8_t*) rdbuf, READBACK_LEN, &num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
ret = read_data(ctx->dev, ctx->endp_up,
(uint8_t*) rdbuf, READBACK_LEN, &num);
@ -750,7 +753,7 @@ static int canonselphy_read_parse(void *vctx, int data_fd)
return CUPS_BACKEND_CANCEL;
}
if (ctx->printer->type != ctx->type) {
if (printer_type != ctx->type) {
ERROR("Printer/Job mismatch (%d/%d)\n", ctx->type, ctx->printer->type);
return CUPS_BACKEND_CANCEL;
}
@ -1112,7 +1115,7 @@ static const char *canonselphy_prefixes[] = {
struct dyesub_backend canonselphy_backend = {
.name = "Canon SELPHY CP/ES (legacy)",
.version = "0.98",
.version = "0.99",
.uri_prefixes = canonselphy_prefixes,
.cmdline_usage = canonselphy_cmdline,
.cmdline_arg = canonselphy_cmdline_arg,

View file

@ -285,6 +285,9 @@ static int selphyneo_main_loop(void *vctx, int copies) {
ret = read_data(ctx->dev, ctx->endp_up,
(uint8_t*) &rdback, sizeof(rdback), &num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
/* And again, for the markers */
ret = read_data(ctx->dev, ctx->endp_up,
(uint8_t*) &rdback, sizeof(rdback), &num);
@ -435,7 +438,7 @@ static const char *canonselphyneo_prefixes[] = {
struct dyesub_backend canonselphyneo_backend = {
.name = "Canon SELPHY CP (new)",
.version = "0.13",
.version = "0.14",
.uri_prefixes = canonselphyneo_prefixes,
.cmdline_usage = selphyneo_cmdline,
.cmdline_arg = selphyneo_cmdline_arg,

View file

@ -29,7 +29,7 @@
#include "backend_common.h"
#define BACKEND_VERSION "0.78"
#define BACKEND_VERSION "0.79"
#ifndef URI_PREFIX
#error "Must Define URI_PREFIX"
#endif
@ -840,7 +840,6 @@ int main (int argc, char **argv)
struct libusb_context *ctx = NULL;
struct libusb_device **list = NULL;
struct libusb_device_handle *dev;
struct libusb_config_descriptor *config = NULL;
struct dyesub_backend *backend = NULL;
void * backend_ctx = NULL;
@ -1033,9 +1032,6 @@ int main (int argc, char **argv)
}
}
if (config)
libusb_free_config_descriptor(config);
/* Initialize backend */
DEBUG("Initializing '%s' backend (version %s)\n",
backend->name, backend->version);

View file

@ -1277,7 +1277,7 @@ parsed:
}
if (dpi == 334 && ctx->type != P_CITIZEN_CW01)
{
ERROR("Illegal resolution (%d) for printer!\n", dpi);
ERROR("Illegal resolution (%u) for printer!\n", dpi);
return CUPS_BACKEND_CANCEL;
}
@ -1358,7 +1358,7 @@ parsed:
break;
case 600: //"A4"
if (ctx->multicut < MULTICUT_A5 || ctx->multicut > MULTICUT_A4x5X2) {
ERROR("Incorrect media for job loaded (%d vs %d)\n", ctx->media, ctx->multicut);
ERROR("Incorrect media for job loaded (%u vs %u)\n", ctx->media, ctx->multicut);
return CUPS_BACKEND_CANCEL;
}
/* A4xn and A5 can be rewound */
@ -2720,7 +2720,7 @@ static const char *dnpds40_prefixes[] = {
/* Exported */
struct dyesub_backend dnpds40_backend = {
.name = "DNP DS-series / Citizen C-series",
.version = "0.99",
.version = "0.100",
.uri_prefixes = dnpds40_prefixes,
.cmdline_usage = dnpds40_cmdline,
.cmdline_arg = dnpds40_cmdline_arg,
@ -2768,8 +2768,10 @@ static int cw01_read_parse(struct dnpds40_ctx *ctx, int data_fd,
while (remain) {
i = read(data_fd, buf + j, remain);
if (i < 0)
if (i < 0) {
free(buf);
return i;
}
remain -= i;
j += i;

View file

@ -733,11 +733,13 @@ static int magicard_read_parse(void *vctx, int data_fd) {
while (remain > 0) {
i = read(data_fd, srcbuf + srcbuf_offset, remain);
if (i < 0) {
ERROR("Data Read Error: %d (%d) @%d)\n", i, remain, srcbuf_offset);
ERROR("Data Read Error: %d (%u) @%u)\n", i, remain, srcbuf_offset);
free(srcbuf);
return i;
}
if (i == 0) {
ERROR("Short read! (%d/%d)\n", i, remain);
ERROR("Short read! (%d/%u)\n", i, remain);
free(srcbuf);
return CUPS_BACKEND_CANCEL;
}
srcbuf_offset += i;
@ -794,11 +796,11 @@ static int magicard_read_parse(void *vctx, int data_fd) {
while (remain > 0) {
i = read(data_fd, ctx->databuf + ctx->datalen, remain);
if (i < 0) {
ERROR("Data Read Error: %d (%d) @%d)\n", i, remain, ctx->datalen);
ERROR("Data Read Error: %d (%u) @%d)\n", i, remain, ctx->datalen);
return i;
}
if (i == 0) {
ERROR("Short read! (%d/%d)\n", i, remain);
ERROR("Short read! (%d/%u)\n", i, remain);
return CUPS_BACKEND_CANCEL;
}
ctx->datalen += i;
@ -895,7 +897,7 @@ static const char *magicard_prefixes[] = {
struct dyesub_backend magicard_backend = {
.name = "Magicard family",
.version = "0.10",
.version = "0.11",
.uri_prefixes = magicard_prefixes,
.cmdline_arg = magicard_cmdline_arg,
.cmdline_usage = magicard_cmdline,

View file

@ -1011,7 +1011,8 @@ repeat:
remain = ctx->rows * ctx->cols * 3;
DEBUG("Reading in %d bytes of 8bpp BGR data\n", remain);
spoolbuflen = 0; spoolbuf = malloc(remain);
spoolbuflen = 0;
spoolbuf = malloc(remain);
if (!spoolbuf) {
ERROR("Memory allocation failure!\n");
return CUPS_BACKEND_RETRY_CURRENT;
@ -1020,10 +1021,14 @@ repeat:
/* Read in the BGR data */
while (remain) {
i = read(data_fd, spoolbuf + spoolbuflen, remain);
if (i == 0)
if (i == 0) {
free(spoolbuf);
return CUPS_BACKEND_CANCEL;
if (i < 0)
}
if (i < 0) {
free(spoolbuf);
return CUPS_BACKEND_CANCEL;
}
spoolbuflen += i;
remain -= i;
}
@ -1116,7 +1121,7 @@ repeat:
if (ctx->matte) {
int fd;
uint32_t j;
DEBUG("Reading %d bytes of matte data from disk (%d/%d)\n", ctx->matte, ctx->cols, LAMINATE_STRIDE);
DEBUG("Reading %u bytes of matte data from disk (%d/%d)\n", ctx->matte, ctx->cols, LAMINATE_STRIDE);
fd = open(ctx->laminatefname, O_RDONLY);
if (fd < 0) {
ERROR("Unable to open matte lamination data file '%s'\n", ctx->laminatefname);
@ -1450,7 +1455,7 @@ static int d70_library_callback(void *context, void *buffer, uint32_t len)
if (chunk > CHUNK_LEN)
chunk = CHUNK_LEN;
ret = send_data(ctx->dev, ctx->endp_down, buffer + offset, chunk);
ret = send_data(ctx->dev, ctx->endp_down, (uint8_t*)buffer + offset, chunk);
if (ret < 0)
break;
@ -1998,7 +2003,7 @@ static const char *mitsu70x_prefixes[] = {
/* Exported */
struct dyesub_backend mitsu70x_backend = {
.name = "Mitsubishi CP-D70 family",
.version = "0.76",
.version = "0.77",
.uri_prefixes = mitsu70x_prefixes,
.cmdline_usage = mitsu70x_cmdline,
.cmdline_arg = mitsu70x_cmdline_arg,

View file

@ -1025,6 +1025,7 @@ static int get_tonecurve(struct shinkos1245_ctx *ctx, int type, int table, char
if (ret < 0)
goto done;
ptr += num;
remaining -= num;
}
/* Issue a tone_end */
@ -1148,6 +1149,7 @@ static int set_tonecurve(struct shinkos1245_ctx *ctx, int type, int table, char
if (ret < 0)
goto done;
ptr += num;
remaining -= num;
}
/* Issue a tone_end */
@ -1320,7 +1322,7 @@ static int shinkos1245_read_parse(void *vctx, int data_fd) {
ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr));
if (ret < 0)
return ret;
if (ret < 0 || ret != sizeof(ctx->hdr))
if (ret != sizeof(ctx->hdr))
return CUPS_BACKEND_CANCEL;
if (le32_to_cpu(ctx->hdr.len1) != 0x10 ||
@ -1648,7 +1650,7 @@ static const char *shinkos1245_prefixes[] = {
struct dyesub_backend shinkos1245_backend = {
.name = "Shinko/Sinfonia CHC-S1245/E1",
.version = "0.19",
.version = "0.20",
.uri_prefixes = shinkos1245_prefixes,
.cmdline_usage = shinkos1245_cmdline,
.cmdline_arg = shinkos1245_cmdline_arg,