]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix compiler warnings about non-null and casting 568/head
authorRose <83477269+AtariDreams@users.noreply.github.com>
Thu, 1 Dec 2022 21:32:14 +0000 (16:32 -0500)
committerRose <83477269+AtariDreams@users.noreply.github.com>
Fri, 2 Dec 2022 00:31:44 +0000 (19:31 -0500)
Explicitly cast to unsigned char, and check for NULL before passing pointers to functions that expect nonnull.

backend/ipp.c
backend/lpd.c
tools/ippeveps.c

index d260692c5dc969dcc6d70d6fdc73c66d09ab7b23..438773dfe97de7d42b65db3a63577724c474bbda 100644 (file)
@@ -70,9 +70,6 @@ typedef struct _cups_monitor_s                /**** Monitoring data ****/
 /*
  * Globals...
  */
-
-static const char      *auth_info_required;
-                                       /* New auth-info-required value */
 #if defined(HAVE_GSSAPI) && defined(HAVE_XPC)
 static pid_t           child_pid = 0;  /* Child process ID */
 #endif /* HAVE_GSSAPI && HAVE_XPC */
@@ -260,7 +257,8 @@ main(int  argc,                             /* I - Number of command-line args */
                validate_retried = 0,   /* Was Validate-Job request retried? */
                copies,                 /* Number of copies for job */
                copies_remaining;       /* Number of copies remaining */
-  const char   *content_type,          /* CONTENT_TYPE environment variable */
+  const char   *auth_info_required,            /* New auth-info-required value */
+    *content_type,             /* CONTENT_TYPE environment variable */
                *final_content_type,    /* FINAL_CONTENT_TYPE environment var */
                *document_format;       /* document-format value */
   int          fd;                     /* File descriptor */
@@ -354,11 +352,11 @@ main(int  argc,                           /* I - Number of command-line args */
 
   if (!getuid() && (value = getenv("AUTH_UID")) != NULL)
   {
-    uid_t      uid = (uid_t)atoi(value);
+    uid_t      uid = (uid_t)strtoul(value, NULL, 10);
                                        /* User ID */
 
 #  ifdef HAVE_XPC
-    if (uid > 0)
+    if (uid)
     {
       if (argc == 6)
         return (run_as_user(argv, uid, device_uri, 0));
@@ -385,7 +383,7 @@ main(int  argc,                             /* I - Number of command-line args */
     }
 
 #  else /* No XPC, just try to run as the user ID */
-    if (uid > 0)
+    if (uid)
       setuid(uid);
 #  endif /* HAVE_XPC */
   }
@@ -567,12 +565,13 @@ main(int  argc,                           /* I - Number of command-line args */
 #endif /* HAVE_LIBZ */
       else if (!_cups_strcasecmp(name, "contimeout"))
       {
+        int value_int = atoi(value);
        /*
         * Set the connection timeout...
        */
 
-       if (atoi(value) > 0)
-         contimeout = atoi(value);
+       if (value_int > 0)
+         contimeout = value_int;
       }
       else
       {
@@ -789,8 +788,6 @@ main(int  argc,                             /* I - Number of command-line args */
 
   if (job_canceled)
     return (CUPS_BACKEND_OK);
-  else if (!http)
-    return (CUPS_BACKEND_FAILED);
 
   if (httpIsEncrypted(http))
   {
@@ -1354,12 +1351,13 @@ main(int  argc,                         /* I - Number of command-line args */
         * the printer...
         */
 
-        for (i = 0; i < (int)(sizeof(hashes) / sizeof(hashes[0])); i ++)
-          if (ippContainsString(encryption_sup, hashes[i]))
+        size_t j;
+        for (j = 0; j < (sizeof(hashes) / sizeof(hashes[0])); j ++)
+          if (ippContainsString(encryption_sup, hashes[j]))
+          {
+            num_options = cupsAddOption("job-password-encryption", hashes[j], num_options, &options);
             break;
-
-        if (i < (int)(sizeof(hashes) / sizeof(hashes[0])))
-          num_options = cupsAddOption("job-password-encryption", hashes[i], num_options, &options);
+          }
       }
     }
   }
@@ -2943,8 +2941,6 @@ password_cb(const char *prompt,           /* I - Prompt (not used) */
     * Remember that we need to authenticate...
     */
 
-    auth_info_required = "username,password";
-
     if (httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE, "username",
                        def_username))
     {
@@ -3244,7 +3240,8 @@ run_as_user(char       *argv[],           /* I - Command-line arguments */
            int        fd)              /* I - File to print */
 {
   const char           *auth_negotiate,/* AUTH_NEGOTIATE env var */
-                       *content_type;  /* [FINAL_]CONTENT_TYPE env vars */
+                       *content_type,  /* [FINAL_]CONTENT_TYPE env vars */
+                       *auth_info_required;    /* New auth-info-required value */
   xpc_connection_t     conn;           /* Connection to XPC service */
   xpc_object_t         request;        /* Request message dictionary */
   __block xpc_object_t response;       /* Response message dictionary */
@@ -3302,8 +3299,9 @@ run_as_user(char       *argv[],           /* I - Command-line arguments */
   xpc_dictionary_set_string(request, "title", argv[3]);
   xpc_dictionary_set_string(request, "copies", argv[4]);
   xpc_dictionary_set_string(request, "options", argv[5]);
-  xpc_dictionary_set_string(request, "auth-info-required",
-                            getenv("AUTH_INFO_REQUIRED"));
+  if ((auth_info_required = getenv("AUTH_INFO_REQUIRED")) != NULL)
+    xpc_dictionary_set_string(request, "auth-info-required",
+                              auth_info_required);
   if ((auth_negotiate = getenv("AUTH_NEGOTIATE")) != NULL)
     xpc_dictionary_set_string(request, "auth-negotiate", auth_negotiate);
   if ((content_type = getenv("CONTENT_TYPE")) != NULL)
index 720499a941b9a3975edbaecb561106dcfed3cac1..af68c958dbc0d717da0e0f5e37f138217e801e33 100644 (file)
@@ -101,8 +101,7 @@ main(int  argc,                             /* I - Number of command-line arguments (6 or 7) */
                *options,               /* Pointer to options */
                *name,                  /* Name of option */
                *value,                 /* Value of option */
-               sep,                    /* Separator character */
-               *filename,              /* File to print */
+               sep,            /* Separator character */
                title[256];             /* Title string */
   int          port;                   /* Port number */
   http_addrlist_t *addrlist;           /* List of addresses for printer */
@@ -460,13 +459,11 @@ main(int  argc,                           /* I - Number of command-line arguments (6 or 7) */
     * Stream from stdin...
     */
 
-    filename = NULL;
     fd       = 0;
   }
   else
   {
-    filename = argv[6];
-    fd       = open(filename, O_RDONLY);
+    fd       = open(argv[6], O_RDONLY);
 
     if (fd == -1)
     {
index 8cde19521768508c05442176555f4cdac523d7fa..04f33120eb77f216822bbd24778775bde6b4481b 100644 (file)
@@ -141,16 +141,16 @@ ascii85(const unsigned char *data,        /* I - Data to write */
     switch (leftcount)
     {
       case 0 :
-          b = (unsigned)((((((data[0] << 8) | data[1]) << 8) | data[2]) << 8) | data[3]);
+          b = (unsigned)((data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]);
          break;
       case 1 :
-          b = (unsigned)((((((leftdata[0] << 8) | data[0]) << 8) | data[1]) << 8) | data[2]);
+          b = (unsigned)((leftdata[0] << 24) | (data[0] << 16) | (data[1] << 8) | data[2]);
          break;
       case 2 :
-          b = (unsigned)((((((leftdata[0] << 8) | leftdata[1]) << 8) | data[0]) << 8) | data[1]);
+          b = (unsigned)((leftdata[0] << 24) | (leftdata[1] << 16) | (data[0] << 8) | data[1]);
          break;
       case 3 :
-          b = (unsigned)((((((leftdata[0] << 8) | leftdata[1]) << 8) | leftdata[2]) << 8) | data[0]);
+          b = (unsigned)((leftdata[0] << 24) | (leftdata[1] << 16) | (leftdata[2] << 8) | data[0]);
          break;
     }
 
@@ -167,13 +167,13 @@ ascii85(const unsigned char *data,        /* I - Data to write */
     }
     else
     {
-      c[4] = (b % 85) + '!';
+      c[4] = (unsigned char) ((b % 85) + '!');
       b /= 85;
-      c[3] = (b % 85) + '!';
+      c[3] = (unsigned char) ((b % 85) + '!');
       b /= 85;
-      c[2] = (b % 85) + '!';
+      c[2] = (unsigned char) ((b % 85) + '!');
       b /= 85;
-      c[1] = (b % 85) + '!';
+      c[1] = (unsigned char) ((b % 85) + '!');
       b /= 85;
       c[0] = (unsigned char)(b + '!');
 
@@ -209,15 +209,15 @@ ascii85(const unsigned char *data,        /* I - Data to write */
     if (leftcount > 0)
     {
       // Write the remaining bytes as needed...
-      b = (unsigned)((((((leftdata[0] << 8) | leftdata[1]) << 8) | leftdata[2]) << 8) | leftdata[3]);
+      b = (unsigned)((leftdata[0] << 24) | (leftdata[1] << 16) | (leftdata[2] << 8) | leftdata[3]);
 
-      c[4] = (b % 85) + '!';
+      c[4] = (unsigned char) ((b % 85) + '!');
       b /= 85;
-      c[3] = (b % 85) + '!';
+      c[3] = (unsigned char) ((b % 85) + '!');
       b /= 85;
-      c[2] = (b % 85) + '!';
+      c[2] = (unsigned char) ((b % 85) + '!');
       b /= 85;
-      c[1] = (b % 85) + '!';
+      c[1] = (unsigned char) ((b % 85) + '!');
       b /= 85;
       c[0] = (unsigned char)(b + '!');
 
@@ -430,7 +430,7 @@ get_options(cups_option_t **options)        /* O - Options */
     if (value)
     {
       char     *ptr;                   /* Pointer into value */
-      int      fin;                    /* Current value */
+      long     fin;                    /* Current value */
 
       for (fin = strtol(value, &ptr, 10); fin > 0; fin = strtol(ptr + 1, &ptr, 10))
       {
@@ -533,8 +533,8 @@ jpeg_to_ps(const char    *filename, /* I - Filename */
   int          copy;                   /* Current copy */
   int          width = 0,              /* Width */
                height = 0,             /* Height */
-               depth = 0,              /* Number of colors */
-               length;                 /* Length of marker */
+               depth = 0;              /* Number of colors */
+       ssize_t         length;                 /* Length of marker */
   unsigned char        buffer[65536],          /* Copy buffer */
                *bufptr,                /* Pointer info buffer */
                *bufend;                /* End of buffer */
@@ -630,7 +630,7 @@ jpeg_to_ps(const char    *filename, /* I - Filename */
        bufend += bytes;
       }
 
-      length = (size_t)((bufptr[1] << 8) | bufptr[2]);
+      length = (ssize_t)((bufptr[1] << 8) | bufptr[2]);
 
       if ((*bufptr >= 0xc0 && *bufptr <= 0xc3) || (*bufptr >= 0xc5 && *bufptr <= 0xc7) || (*bufptr >= 0xc9 && *bufptr <= 0xcb) || (*bufptr >= 0xcd && *bufptr <= 0xcf))
       {
@@ -902,7 +902,7 @@ ps_to_ps(const char    *filename,   /* I - Filename */
                first_page,                     /* First page */
                last_page;                      /* Last page */
   const char   *page_ranges;                   /* page-ranges option */
-  long         first_pos = -1;                 /* Offset for first page */
+  long         first_pos;                      /* Offset for first page */
   char         line[1024];                     /* Line from file */
 
 
@@ -1131,7 +1131,7 @@ raster_to_ps(const char *filename)        /* I - Filename */
         break;
     }
 
-    fprintf(stderr, "DEBUG: y=%d at end...\n", y);
+    fprintf(stderr, "DEBUG: y=%u at end...\n", y);
 
     puts("grestore grestore");
     puts("showpage");