From 9ca26d04f170626a66a23cde3eac29dac7e89260 Mon Sep 17 00:00:00 2001 From: Zdenek Dohnal Date: Thu, 16 Feb 2023 15:49:10 +0100 Subject: [PATCH] Coverity fixes 2 --- filter/foomatic-rip/foomaticrip.c | 4 +++- filter/foomatic-rip/options.c | 7 ++----- filter/foomatic-rip/postscript.c | 11 +++++++---- filter/rastertoescpx.c | 3 +++ utils/driverless.c | 3 ++- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/filter/foomatic-rip/foomaticrip.c b/filter/foomatic-rip/foomaticrip.c index b6abe4d33..036d6138b 100644 --- a/filter/foomatic-rip/foomaticrip.c +++ b/filter/foomatic-rip/foomaticrip.c @@ -639,7 +639,7 @@ int print_file(const char *filename, int convert) { - FILE *file; + FILE *file = NULL; char buf[8192]; char tmpfilename[PATH_MAX] = ""; int type; @@ -664,6 +664,8 @@ print_file(const char *filename, n = fread_or_die(buf, 1, sizeof(buf) - 1, file); if (!n) { _log("Input is empty, outputting empty file.\n"); + if (strcasecmp(filename, "")) + fclose(file); return (1); } buf[n] = '\0'; diff --git a/filter/foomatic-rip/options.c b/filter/foomatic-rip/options.c index ae5bac2ed..bad833bc1 100644 --- a/filter/foomatic-rip/options.c +++ b/filter/foomatic-rip/options.c @@ -1255,8 +1255,6 @@ option_has_choice(option_t *opt, const char * option_text(option_t *opt) { - if (isempty(opt->text)) - return (opt->text); return (opt->text); } @@ -2263,9 +2261,8 @@ ppd_supports_pdf() // line if (startswith(cmd, "gs")) { - strncpy(cmd_pdf, cmd, 4096); - if (strlen(cmd) > 4095) - cmd_pdf[4095] = '\0'; + strncpy(cmd_pdf, cmd, 4095); + cmd_pdf[4095] = '\0'; return (1); } diff --git a/filter/foomatic-rip/postscript.c b/filter/foomatic-rip/postscript.c index b09c5b8ff..e6fbd2ac0 100644 --- a/filter/foomatic-rip/postscript.c +++ b/filter/foomatic-rip/postscript.c @@ -178,17 +178,14 @@ print_ps(FILE *file, const char *filename) { stream_t stream; - char gscommand[65536]; int pagefound = 0; FILE *in, *out; pid_t pid; - char buf[4096]; struct pollfd pfd; size_t bytes, bytes_sent; char *pos; int pres; - dstr_t *line = create_dstr(); - dstr_t *data_read = create_dstr(); + dstr_t *line = NULL, *data_read = NULL; // Define input data stream for reading @@ -228,6 +225,11 @@ print_ps(FILE *file, // lines, we only need the boolean answer whether there are pages or // not // + + char buf[4096]; + char gscommand[65536]; + line = create_dstr(); + data_read = create_dstr(); snprintf(gscommand, 65536, "%s -q -dNOPAUSE -dBATCH -sDEVICE=bbox -dDEVICEWIDTHPOINTS=1 -dDEVICEHEIGHTPOINTS=1 -_ 2>&1", CUPS_GHOSTSCRIPT); @@ -313,6 +315,7 @@ print_ps(FILE *file, _log("No pages left, outputting empty file.\n"); free_dstr(data_read); + free_dstr(line); } return (1); diff --git a/filter/rastertoescpx.c b/filter/rastertoescpx.c index ccd599ea5..f060db0b3 100644 --- a/filter/rastertoescpx.c +++ b/filter/rastertoescpx.c @@ -335,6 +335,9 @@ StartPage(ppd_file_t *ppd, // I - PPD file DitherLuts[6] = ppdLutLoad(ppd, colormodel, header->MediaType, resolution, "LightBlack", logfunc, ld); break; + default : // ERROR + fputs("ERROR: Unexpected number of channels\n", stderr); + exit(1); } for (plane = 0; plane < PrinterPlanes; plane ++) diff --git a/utils/driverless.c b/utils/driverless.c index 8af843333..7c67cbe19 100644 --- a/utils/driverless.c +++ b/utils/driverless.c @@ -495,19 +495,20 @@ list_printers (int mode, int reg_type_no, int isFax) if (fp) { while ((bytes = cupsFileGetLine(fp, buffer, sizeof(buffer))) > 0 || (bytes < 0 && (errno == EAGAIN || errno == EINTR))) { - ippfind_output = (char *)malloc(MAX_OUTPUT_LEN*(sizeof(char))); ptr = buffer; while (ptr && !isalnum(*ptr & 255)) ptr ++; if ((!strncasecmp(ptr, "ipps", 4) && ptr[4] == '\t')) { ptr += 4; *ptr = '\0'; ptr ++; + ippfind_output = (char *)malloc(MAX_OUTPUT_LEN*(sizeof(char))); snprintf(ippfind_output, MAX_OUTPUT_LEN, "%s", ptr); cupsArrayAdd(service_uri_list_ipps, ippfind_output); } else if ((!strncasecmp(ptr, "ipp", 3) && ptr[3] == '\t')) { ptr += 3; *ptr = '\0'; ptr ++; + ippfind_output = (char *)malloc(MAX_OUTPUT_LEN*(sizeof(char))); snprintf(ippfind_output, MAX_OUTPUT_LEN, "%s", ptr); cupsArrayAdd(service_uri_list_ipp, ippfind_output); } else -- 2.39.2