From: Michael R Sweet Date: Sat, 20 Apr 2019 13:13:32 +0000 (-0400) Subject: More clang warning fixes. X-Git-Tag: v2.3b8~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=507c4adcc817c2d80643ecee2cb55dff305236f9;p=thirdparty%2Fcups.git More clang warning fixes. --- diff --git a/backend/lpd.c b/backend/lpd.c index e705ed406f..45cdde8e7f 100644 --- a/backend/lpd.c +++ b/backend/lpd.c @@ -1,7 +1,7 @@ /* * Line Printer Daemon backend for CUPS. * - * Copyright © 2007-2016 by Apple Inc. + * Copyright © 2007-2019 by Apple Inc. * Copyright © 1997-2007 by Easy Software Products, all rights reserved. * * Licensed under Apache License v2.0. See the file "LICENSE" for more @@ -72,12 +72,7 @@ static int abort_job = 0; /* Non-zero if we get SIGTERM */ static int cups_rresvport(int *port, int family); static int lpd_command(int lpd_fd, char *format, ...); -static int lpd_queue(const char *hostname, http_addrlist_t *addrlist, - const char *printer, int print_fd, int snmp_fd, - int mode, const char *user, const char *title, - int copies, int banner, int format, int order, - int reserve, int manual_copies, int timeout, - int contimeout, const char *orighost); +static int lpd_queue(const char *hostname, http_addrlist_t *addrlist, const char *printer, int print_fd, int snmp_fd, int mode, const char *user, const char *title, int copies, int banner, int format, int order, int reserve, int manual_copies, int timeout, int contimeout, const char *orighost) _CUPS_NONNULL((1,2,3,7,8,17)); static ssize_t lpd_write(int lpd_fd, char *buffer, size_t length); static void sigterm_handler(int sig); diff --git a/cgi-bin/cgi.h b/cgi-bin/cgi.h index c7e221b28c..11acb224d2 100644 --- a/cgi-bin/cgi.h +++ b/cgi-bin/cgi.h @@ -1,10 +1,11 @@ /* * CGI support library definitions for CUPS. * - * Copyright 2007-2010 by Apple Inc. - * Copyright 1997-2006 by Easy Software Products. + * Copyright © 2007-2019 by Apple Inc. + * Copyright © 1997-2006 by Easy Software Products. * - * Licensed under Apache License v2.0. See the file "LICENSE" for more information. + * Licensed under Apache License v2.0. See the file "LICENSE" for more + * information. */ #ifndef _CUPS_CGI_H_ @@ -66,14 +67,14 @@ extern void cgiEndMultipart(void); extern char *cgiFormEncode(char *dst, const char *src, size_t dstsize); extern void cgiFreeSearch(void *search); -extern const char *cgiGetArray(const char *name, int element); +extern char *cgiGetArray(const char *name, int element); extern void cgiGetAttributes(ipp_t *request, const char *tmpl); extern const char *cgiGetCookie(const char *name); extern const cgi_file_t *cgiGetFile(void); extern cups_array_t *cgiGetIPPObjects(ipp_t *response, void *search); extern int cgiGetSize(const char *name); extern char *cgiGetTemplateDir(void); -extern const char *cgiGetVariable(const char *name); +extern char *cgiGetVariable(const char *name); extern int cgiInitialize(void); extern int cgiIsPOST(void); extern void cgiMoveJobs(http_t *http, const char *dest, int job_id); diff --git a/cgi-bin/help-index.c b/cgi-bin/help-index.c index a49536d6ab..ce97e47a43 100644 --- a/cgi-bin/help-index.c +++ b/cgi-bin/help-index.c @@ -1,10 +1,11 @@ /* * Online help index routines for CUPS. * - * Copyright 2007-2017 by Apple Inc. - * Copyright 1997-2007 by Easy Software Products. + * Copyright © 2007-2019 by Apple Inc. + * Copyright © 1997-2007 by Easy Software Products. * - * Licensed under Apache License v2.0. See the file "LICENSE" for more information. + * Licensed under Apache License v2.0. See the file "LICENSE" for more + * information. */ /* @@ -340,6 +341,8 @@ helpLoadIndex(const char *hifile, /* I - Index filename */ while (isspace(*ptr & 255)) ptr ++; } + else + section[0] = '\0'; if (*ptr != '\"') break; @@ -1188,7 +1191,7 @@ help_new_node(const char *filename, /* I - Filename */ n->filename = strdup(filename); n->anchor = anchor ? strdup(anchor) : NULL; - n->section = *section ? strdup(section) : NULL; + n->section = (section && *section) ? strdup(section) : NULL; n->text = strdup(text); n->mtime = mtime; n->offset = offset; diff --git a/cgi-bin/var.c b/cgi-bin/var.c index 21b3c5308d..306375bd6c 100644 --- a/cgi-bin/var.c +++ b/cgi-bin/var.c @@ -4,7 +4,8 @@ * Copyright © 2007-2019 by Apple Inc. * Copyright © 1997-2005 by Easy Software Products. * - * Licensed under Apache License v2.0. See the file "LICENSE" for more information. + * Licensed under Apache License v2.0. See the file "LICENSE" for more + * information. */ /* @@ -113,7 +114,12 @@ cgiCheckVariables(const char *names) /* I - Variables to look for */ return (0); if (*val == '\0') + { + free((void *)val); return (0); /* Can't be blank, either! */ + } + + free((void *)val); } return (1); @@ -151,7 +157,7 @@ cgiClearVariables(void) * 'cgiGetArray()' - Get an element from a form array. */ -const char * /* O - Element value or NULL */ +char * /* O - Element value or NULL */ cgiGetArray(const char *name, /* I - Name of array variable */ int element) /* I - Element number (0 to N) */ { @@ -214,7 +220,7 @@ cgiGetSize(const char *name) /* I - Name of variable */ * array of values, returns the last element. */ -const char * /* O - Value of variable */ +char * /* O - Value of variable */ cgiGetVariable(const char *name) /* I - Name of variable */ { const _cgi_var_t *var; /* Returned variable */ @@ -312,11 +318,18 @@ cgiInitialize(void) else fputs("DEBUG: " CUPS_SID " form variable is not present.\n", stderr); + free((void *)cups_sid_form); + cgiClearVariables(); + return (0); } else + { + free((void *)cups_sid_form); + return (1); + } } else return (0); @@ -868,12 +881,13 @@ cgi_initialize_multipart( if (line[0]) cgiSetArray(name, atoi(ptr) - 1, line); } - else if (cgiGetVariable(name)) + else if ((ptr = cgiGetVariable(name)) != NULL) { /* * Add another element in the array... */ + free(ptr); cgiSetArray(name, cgiGetSize(name), line); } else @@ -1028,7 +1042,8 @@ cgi_initialize_string(const char *data) /* I - Form data string */ char *s, /* Pointer to current form string */ ch, /* Temporary character */ name[255], /* Name of form variable */ - value[65536]; /* Variable value */ + value[65536], /* Variable value */ + *temp; /* Temporary pointer */ /* @@ -1130,8 +1145,11 @@ cgi_initialize_string(const char *data) /* I - Form data string */ if (value[0]) cgiSetArray(name, atoi(s) - 1, value); } - else if (cgiGetVariable(name) != NULL) + else if ((temp = cgiGetVariable(name)) != NULL) + { + free(temp); cgiSetArray(name, cgiGetSize(name), value); + } else cgiSetVariable(name, value); } diff --git a/ppdc/ppdc-driver.cxx b/ppdc/ppdc-driver.cxx index 9547e91fa2..7f739b2dd7 100644 --- a/ppdc/ppdc-driver.cxx +++ b/ppdc/ppdc-driver.cxx @@ -1,10 +1,11 @@ // // PPD file compiler definitions for the CUPS PPD Compiler. // -// Copyright 2007-2018 by Apple Inc. -// Copyright 2002-2006 by Easy Software Products. +// Copyright © 2007-2019 by Apple Inc. +// Copyright © 2002-2006 by Easy Software Products. // -// Licensed under Apache License v2.0. See the file "LICENSE" for more information. +// Licensed under Apache License v2.0. See the file "LICENSE" for more +// information. // // @@ -705,6 +706,7 @@ ppdcDriver::write_ppd_file( _cupsLangPrintf(stderr, _("ppdc: No message catalog provided for locale " "%s."), locale->value); + delete locatalog; continue; } diff --git a/scheduler/cups-driverd.cxx b/scheduler/cups-driverd.cxx index 07e78a49d3..85516eb8cb 100644 --- a/scheduler/cups-driverd.cxx +++ b/scheduler/cups-driverd.cxx @@ -347,8 +347,7 @@ cat_drv(const char *name, /* I - PPD name */ return (1); } - if ((fp = get_file(resource, request_id, "drv", filename, sizeof(filename), - &pc_file_name)) == NULL) + if ((fp = get_file(resource, request_id, "drv", filename, sizeof(filename), &pc_file_name)) == NULL || !pc_file_name) return (1); src = new ppdcSource(filename, fp); diff --git a/scheduler/job.c b/scheduler/job.c index 092d87962a..26cffdb612 100644 --- a/scheduler/job.c +++ b/scheduler/job.c @@ -1303,9 +1303,7 @@ cupsdContinueJob(cupsd_job_t *job) /* I - Job */ cupsdClosePipe(filterfds[slot]); for (i = 6; i < argc; i ++) - if (argv[i]) - free(argv[i]); - + free(argv[i]); free(argv); if (printer_state_reasons) @@ -1338,8 +1336,9 @@ cupsdContinueJob(cupsd_job_t *job) /* I - Job */ if (argv) { for (i = 6; i < argc; i ++) - if (argv[i]) - free(argv[i]); + free(argv[i]); + + free(argv); } if (printer_state_reasons) diff --git a/scheduler/main.c b/scheduler/main.c index 616cf2c376..3a2fe7ec90 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -345,6 +345,7 @@ main(int argc, /* I - Number of command-line args */ strlcpy(filename, ConfigurationFile, len); if ((slash = strrchr(filename, '/')) == NULL) { + free(filename); _cupsLangPrintf(stderr, _("cupsd: Unable to get path to " "cups-files.conf file.")); diff --git a/scheduler/type.c b/scheduler/type.c index 2cceeda58c..5df77e9bf0 100644 --- a/scheduler/type.c +++ b/scheduler/type.c @@ -1,10 +1,11 @@ /* * MIME typing routines for CUPS. * - * Copyright 2007-2016 by Apple Inc. - * Copyright 1997-2006 by Easy Software Products, all rights reserved. + * Copyright © 2007-2019 by Apple Inc. + * Copyright © 1997-2006 by Easy Software Products, all rights reserved. * - * Licensed under Apache License v2.0. See the file "LICENSE" for more information. + * Licensed under Apache License v2.0. See the file "LICENSE" for more + * information. */ /* @@ -527,14 +528,16 @@ mimeAddTypeRule(mime_type_t *mt, /* I - Type to add to */ case MIME_MAGIC_STRING : case MIME_MAGIC_ISTRING : temp->offset = strtol(value[0], NULL, 0); - if ((size_t)length[1] > sizeof(temp->value.stringv)) + if (num_values < 2 || (size_t)length[1] > sizeof(temp->value.stringv)) return (-1); temp->length = length[1]; memcpy(temp->value.stringv, value[1], (size_t)length[1]); break; case MIME_MAGIC_CHAR : temp->offset = strtol(value[0], NULL, 0); - if (length[1] == 1) + if (num_values < 2) + return (-1); + else if (length[1] == 1) temp->value.charv = (unsigned char)value[1][0]; else temp->value.charv = (unsigned char)strtol(value[1], NULL, 0); @@ -559,7 +562,7 @@ mimeAddTypeRule(mime_type_t *mt, /* I - Type to add to */ case MIME_MAGIC_CONTAINS : temp->offset = strtol(value[0], NULL, 0); temp->region = strtol(value[1], NULL, 0); - if ((size_t)length[2] > sizeof(temp->value.stringv)) + if (num_values < 3 || (size_t)length[2] > sizeof(temp->value.stringv)) return (-1); temp->length = length[2]; memcpy(temp->value.stringv, value[2], (size_t)length[2]); diff --git a/test/ippeveprinter.c b/test/ippeveprinter.c index 0e87203661..d37a4ff0c5 100644 --- a/test/ippeveprinter.c +++ b/test/ippeveprinter.c @@ -4660,7 +4660,6 @@ process_http(ippeve_client_t *client) /* I - Client connection */ hostname[HTTP_MAX_HOST]; /* Hostname */ int port; /* Port number */ - const char *encoding; /* Content-Encoding value */ static const char * const http_states[] = { /* Strings for logging HTTP method */ "WAITING", @@ -4839,8 +4838,6 @@ process_http(ippeve_client_t *client) /* I - Client connection */ * Handle new transfers... */ - encoding = httpGetContentEncoding(client->http); - switch (client->operation) { case HTTP_STATE_OPTIONS : diff --git a/test/ipptool.c b/test/ipptool.c index e9a38274e1..2c0f0c6237 100644 --- a/test/ipptool.c +++ b/test/ipptool.c @@ -4777,6 +4777,8 @@ with_value(_cups_testdata_t *data, /* I - Test data */ * Value is an extended, case-sensitive POSIX regular expression... */ + void *adata; /* Pointer to octetString data */ + int adatalen; /* Length of octetString */ regex_t re; /* Regular expression */ if ((i = regcomp(&re, value, REG_EXTENDED | REG_NOSUB)) != 0) @@ -4793,16 +4795,13 @@ with_value(_cups_testdata_t *data, /* I - Test data */ for (i = 0; i < count; i ++) { - void *data; /* Pointer to octetString data */ - int datalen; /* Length of octetString */ - - if ((data = ippGetOctetString(attr, i, &datalen)) == NULL || datalen >= (int)sizeof(temp)) + if ((adata = ippGetOctetString(attr, i, &adatalen)) == NULL || adatalen >= (int)sizeof(temp)) { match = 0; break; } - memcpy(temp, data, (size_t)datalen); - temp[datalen] = '\0'; + memcpy(temp, adata, (size_t)adatalen); + temp[adatalen] = '\0'; if (!regexec(&re, temp, 0, NULL, 0)) { @@ -4828,9 +4827,7 @@ with_value(_cups_testdata_t *data, /* I - Test data */ { for (i = 0; i < count; i ++) { - int adatalen; - void *adata = ippGetOctetString(attr, i, &adatalen); - + adata = ippGetOctetString(attr, i, &adatalen); copy_hex_string(temp, adata, adatalen, sizeof(temp)); add_stringf(data->errors, "GOT: %s=\"%s\"", name, temp); }