]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
More clang warning fixes.
authorMichael R Sweet <michael.r.sweet@gmail.com>
Sat, 20 Apr 2019 13:13:32 +0000 (09:13 -0400)
committerMichael R Sweet <michael.r.sweet@gmail.com>
Sat, 20 Apr 2019 13:13:32 +0000 (09:13 -0400)
backend/lpd.c
cgi-bin/cgi.h
cgi-bin/help-index.c
cgi-bin/var.c
ppdc/ppdc-driver.cxx
scheduler/cups-driverd.cxx
scheduler/job.c
scheduler/main.c
scheduler/type.c
test/ippeveprinter.c
test/ipptool.c

index e705ed406fe2fd6dea226b9d88f1d16923dd6d59..45cdde8e7f0a50fa488c12ca501373ff071b1b65 100644 (file)
@@ -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);
 
index c7e221b28c54306f0713ed6133dfcd671b95478c..11acb224d22b4ed1e7ba9c1db03cbe9108b2628a 100644 (file)
@@ -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);
index a49536d6ab150e2b6af4f9ee2db56e827c83018c..ce97e47a43e3777f29bc8abdd048b7b59ac79a04 100644 (file)
@@ -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;
index 21b3c5308d7a705eebe8318423886d71e4f45335..306375bd6c84e25eee28ecd0f7a7b91a94b8d879 100644 (file)
@@ -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);
   }
index 9547e91fa23e44835984f40754de2dbb394878da..7f739b2dd77b33b707b942b515192e5a3b7cf69c 100644 (file)
@@ -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;
        }
 
index 07e78a49d39326d90eb71fb2d6a3b49be5e3f8f8..85516eb8cbeaca48aedeafc6855751060454c61d 100644 (file)
@@ -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);
index 092d87962a42d0d8062d7c098f8315b276874f7e..26cffdb612b31c48a7633c5566857a8bfcf0b137 100644 (file)
@@ -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)
index 616cf2c3760333964412a7109d155c5129368064..3a2fe7ec90bc8e02223660de6cd0f506e3fd089a 100644 (file)
@@ -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."));
index 2cceeda58c8ed43dd6abc6c337aa0dc457aaf2e2..5df77e9bf0a50695b76d5fe405d490fa1cc9d9f1 100644 (file)
@@ -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]);
index 0e87203661bb61fe96f37eafb6703957642ecc95..d37a4ff0c5386f29f4fb3265c947deabb4d5a498 100644 (file)
@@ -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 :
index e9a38274e1b88221932f2f3f91f615c1c947f997..2c0f0c6237ccf3d5209b10045d50f32b346a006b 100644 (file)
@@ -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);
            }