From 930966f5460e697411ae5c9ddab541468e79ac90 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Thu, 25 Sep 2025 17:50:53 -0400 Subject: [PATCH] Fix clang warnings, clean up cupsArray usage. --- cgi-bin/home.c | 2 - cgi-bin/ipp-var.c | 18 ++++- cups/array.c | 100 ++++++++++++++++----------- cups/oauth.c | 2 +- cups/string-private.h | 8 +-- cups/string.c | 16 +---- cups/testdnssd.c | 10 ++- locale/cups_uk.po | 4 +- tools/ipptool.c | 6 +- xcode/CUPS.xcodeproj/project.pbxproj | 8 ++- 10 files changed, 99 insertions(+), 75 deletions(-) diff --git a/cgi-bin/home.c b/cgi-bin/home.c index 84c8d7e28a..a4e38febf9 100644 --- a/cgi-bin/home.c +++ b/cgi-bin/home.c @@ -112,7 +112,6 @@ do_login(void) fputs("DEBUG2: do_login()\n", stderr); // Get the metadata... - oauth_uri = getenv("CUPS_OAUTH_SERVER"); if ((metadata = cupsOAuthGetMetadata(oauth_uri)) == NULL) { show_error(cgiText(_("OAuth Login")), cgiText(_("Unable to get authorization server information")), cupsGetErrorString()); @@ -261,7 +260,6 @@ finish_login(void) } // Get the metadata... - oauth_uri = getenv("CUPS_OAUTH_SERVER"); if ((metadata = cupsOAuthGetMetadata(oauth_uri)) == NULL) { show_error(cgiText(_("OAuth Login")), cgiText(_("Unable to get authorization server information")), cupsGetErrorString()); diff --git a/cgi-bin/ipp-var.c b/cgi-bin/ipp-var.c index 0f00a75118..939c3734c1 100644 --- a/cgi-bin/ipp-var.c +++ b/cgi-bin/ipp-var.c @@ -86,8 +86,12 @@ cgiGetAttributes(ipp_t *request, /* I - IPP request */ attrs[0] = NULL; /* Eliminate compiler warning */ while ((ch = getc(in)) != EOF) + { if (ch == '\\') - getc(in); + { + if (getc(in) == EOF) + break; + } else if (ch == '{' && num_attrs < (int)(sizeof(attrs) / sizeof(attrs[0]))) { /* @@ -95,10 +99,15 @@ cgiGetAttributes(ipp_t *request, /* I - IPP request */ */ for (nameptr = name; (ch = getc(in)) != EOF;) + { if (strchr("}]<>=!~ \t\n", ch)) + { break; + } else if (nameptr > name && ch == '?') + { break; + } else if (nameptr < (name + sizeof(name) - 1)) { if (ch == '_') @@ -106,6 +115,7 @@ cgiGetAttributes(ipp_t *request, /* I - IPP request */ else *nameptr++ = (char)ch; } + } *nameptr = '\0'; @@ -117,15 +127,21 @@ cgiGetAttributes(ipp_t *request, /* I - IPP request */ */ for (i = 0; i < num_attrs; i ++) + { if (!strcmp(attrs[i], name)) break; + } if (i >= num_attrs) { attrs[num_attrs] = strdup(name); num_attrs ++; } + + if (ch == EOF) + break; } + } /* * If we have attributes, add a requested-attributes attribute to the diff --git a/cups/array.c b/cups/array.c index a12ce99cd9..f21ec7445d 100644 --- a/cups/array.c +++ b/cups/array.c @@ -433,6 +433,20 @@ cupsArrayFirst(cups_array_t *a) // I - Array } +// +// '_cupsArrayFree()' - Free a string in an array. +// + +void +_cupsArrayFree(void *s, // I - String to free + void *data) // I - Callback data (unused) +{ + (void)data; + + free(s); +} + + // // 'cupsArrayGetCount()' - Get the number of elements in the array. // @@ -827,7 +841,7 @@ cupsArrayNewStrings(const char *s, // I - Delimited strings or `NULL` cups_array_t *a; // Array - if ((a = cupsArrayNew3((cups_array_cb_t)strcmp, NULL, NULL, 0, (cups_acopy_cb_t)_cupsArrayStrdup, (cups_afree_cb_t)_cupsArrayFree)) != NULL) + if ((a = cupsArrayNew3(_cupsArrayStrcmp, NULL, NULL, 0, _cupsArrayStrdup, _cupsArrayFree)) != NULL) cupsArrayAddStrings(a, s, delim); return (a); @@ -988,6 +1002,50 @@ cupsArraySave(cups_array_t *a) // I - Array } +// +// '_cupsArrayStrcasecmp()' - Compare two strings in an array, ignoring case... +// + +int // O - Result of comparison +_cupsArrayStrcasecmp(void *s, // I - First string + void *t, // I - Second string + void *data) // I - Callback data (unused) +{ + (void)data; + + return (_cups_strcasecmp((const char *)s, (const char *)t)); +} + + +// +// '_cupsArrayStrcmp()' - Compare two strings in an array. +// + +int // O - Result of comparison +_cupsArrayStrcmp(void *s, // I - first string to compare + void *t, // I - second string to compare + void *data) // I - Callback data (unused) +{ + (void)data; + + return (strcmp((const char *)s, (const char *)t)); +} + + +// +// '_cupsArrayStrdup()' - Copy a string in an array. +// + +void * // O - Copy of string +_cupsArrayStrdup(void *s, // I - String to copy + void *data) // I - Callback data (unused) +{ + (void)data; + + return (strdup((const char *)s)); +} + + // // 'cupsArrayUserData()' - Return the user data for an array. // @@ -1253,43 +1311,3 @@ cups_array_find(cups_array_t *a, // I - Array return (current); } - - -/* - * '_cupsArrayStrcmp()' - Meant to be passed as a pointer to CUPS arrays instead - * of strcmp. Will also work if called directly. - */ - -int _cupsArrayStrcmp(const char *s1, /* I - first string to compare */ - const char *s2, /* I - second string to compare */ - void *data) /* Unused */ -{ - (void)data; - return (strcmp(s1, s2)); -} - - -/* - * '_cupsArrayStrdup()' - Meant to be passed as a pointer to CUPS arrays instead - * of strdup. Will also work if called directly. - */ - -char *_cupsArrayStrdup(const char *element, /* I - element to duplicate */ - void *data) /* Unused */ -{ - (void)data; - return (strdup(element)); -} - - -/* - * '_cupsArrayFree()' - Meant to be passed as a pointer to CUPS arrays instead - * of free. Will also work if called directly. - */ - -void _cupsArrayFree(void *element, /* I - element to free */ - void *data) /* Unused */ -{ - (void)data; - free(element); -} diff --git a/cups/oauth.c b/cups/oauth.c index 0388cb15f6..7aa371ed49 100644 --- a/cups/oauth.c +++ b/cups/oauth.c @@ -861,7 +861,7 @@ cupsOAuthGetDeviceGrant( char *client_id = NULL, // `client_id` value *scopes_supported = NULL; // Supported scopes - size_t num_form = 0; // Number of form variables + int num_form = 0; // Number of form variables cups_option_t *form = NULL; // Form variables char *request = NULL; // Form request data cups_json_t *grant = NULL; // Device grant diff --git a/cups/string-private.h b/cups/string-private.h index 966382238c..62178c13c8 100644 --- a/cups/string-private.h +++ b/cups/string-private.h @@ -129,10 +129,10 @@ extern void _cups_strcpy(char *dst, const char *src) _CUPS_PRIVATE; extern int _cups_strcasecmp(const char *, const char *) _CUPS_PRIVATE; extern int _cups_strncasecmp(const char *, const char *, size_t n) _CUPS_PRIVATE; -extern int _cupsArrayStrcasecmp(const char *s, const char *t, void *data) _CUPS_PRIVATE; -extern int _cupsArrayStrcmp(const char *s1, const char *s2, void *data) _CUPS_PRIVATE; -extern char *_cupsArrayStrdup(const char *element, void *data) _CUPS_PRIVATE; -extern void _cupsArrayFree(void *element, void *data) _CUPS_PRIVATE; +extern void _cupsArrayFree(void *s, void *data) _CUPS_PRIVATE; +extern int _cupsArrayStrcasecmp(void *s, void *t, void *data) _CUPS_PRIVATE; +extern int _cupsArrayStrcmp(void *s, void *t, void *data) _CUPS_PRIVATE; +extern void *_cupsArrayStrdup(void *s, void *data) _CUPS_PRIVATE; extern char *_cupsStrAlloc(const char *s) _CUPS_PRIVATE; extern char *_cupsStrDate(char *buf, size_t bufsize, time_t timeval) _CUPS_PRIVATE; diff --git a/cups/string.c b/cups/string.c index 615caadf02..a3786da379 100644 --- a/cups/string.c +++ b/cups/string.c @@ -30,7 +30,7 @@ static cups_array_t *stringpool = NULL; * Local functions... */ -static int compare_sp_items(_cups_sp_item_t *a, _cups_sp_item_t *b, void *data); +static int compare_sp_items(_cups_sp_item_t *a, _cups_sp_item_t *b, void *data); static void validate_end(char *s, char *end); @@ -1162,17 +1162,3 @@ validate_end(char *s, // I - Pointer to start of string } } } - - -/* - * '_cupsArrayStrcasecmp()' - Compare two strings... - */ - -int /* O - Result of comparison */ -_cupsArrayStrcasecmp(const char *s, /* I - First string */ - const char *t, /* I - Second string */ - void *data) /* I - Unused */ -{ - (void)data; - return (_cups_strcasecmp(s, t)); -} diff --git a/cups/testdnssd.c b/cups/testdnssd.c index bdf4413c37..e67497d42c 100644 --- a/cups/testdnssd.c +++ b/cups/testdnssd.c @@ -1,7 +1,7 @@ // // DNS-SD API test program for CUPS. // -// Copyright © 2022-2024 by OpenPrinting. +// Copyright © 2022-2025 by OpenPrinting. // // Licensed under Apache License v2.0. See the file "LICENSE" for more // information. @@ -10,6 +10,7 @@ #include #include "test-internal.h" #include "dnssd.h" +#include "string-private.h" #include "thread.h" @@ -60,14 +61,14 @@ main(int argc, // I - Number of command-line arguments // cups_dnssd_query_t *query; // DNS-SD query request cups_dnssd_resolve_t *resolve; // DNS-SD resolve request cups_dnssd_service_t *service; // DNS-SD service registration - size_t num_txt; // Number of TXT record key/value pairs + int num_txt; // Number of TXT record key/value pairs cups_option_t *txt; // TXT record key/value pairs testdata_t testdata; // Test data // Clear test data... memset(&testdata, 0, sizeof(testdata)); - testdata.messages = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); + testdata.messages = cupsArrayNew3(NULL, NULL, NULL, 0, _cupsArrayStrdup, _cupsArrayFree); #if _WIN32 snprintf(testdata.name, sizeof(testdata.name), "Test Service %d", (int)GetCurrentProcessId()); #else @@ -319,6 +320,9 @@ browse_print_cb( // Test data + (void)browse; + (void)flags; + printf("%5u %s.%s.%s\n", if_index, name, regtype, domain); cupsMutexLock(&data->mutex); diff --git a/locale/cups_uk.po b/locale/cups_uk.po index e849465abc..00b95d0498 100644 --- a/locale/cups_uk.po +++ b/locale/cups_uk.po @@ -5379,7 +5379,7 @@ msgstr "" #: cups/ppd.c:2017 msgid "No" -msgstr "" +msgstr "Ні" #: cups/http-support.c:1349 msgid "No Content" @@ -7097,7 +7097,7 @@ msgstr "" #: cups/ppd.c:2015 msgid "Yes" -msgstr "" +msgstr "Так" #: scheduler/client.c:2048 msgid "You cannot access this page." diff --git a/tools/ipptool.c b/tools/ipptool.c index f44b4779ec..ccdd6f4289 100644 --- a/tools/ipptool.c +++ b/tools/ipptool.c @@ -841,7 +841,7 @@ alloc_data(void) data->family = AF_UNSPEC; data->def_transfer = IPPTOOL_TRANSFER_AUTO; data->def_version = 20; - data->errors = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_cb_t)strdup, (cups_afree_cb_t)free); + data->errors = cupsArrayNew3(NULL, NULL, NULL, 0, _cupsArrayStrdup, _cupsArrayFree); data->pass = true; data->prev_pass = true; data->request_id = (cupsGetRand() % 1000) * 137; @@ -1933,7 +1933,7 @@ do_test(ipp_file_t *f, // I - IPP data file break; } - exp_errors = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_cb_t)strdup, (cups_afree_cb_t)free); + exp_errors = cupsArrayNew3(NULL, NULL, NULL, 0, _cupsArrayStrdup, _cupsArrayFree); exp_member = strchr(expect->name, '/') != NULL; exp_pass = false; @@ -6970,7 +6970,7 @@ with_distinct_values( } // Collect values and determine they are all unique... - values = cupsArrayNew3((cups_array_cb_t)_cupsArrayStrcmp, NULL, NULL, 0, (cups_acopy_cb_t)strdup, (cups_afree_cb_t)free); + values = cupsArrayNew3((cups_array_cb_t)_cupsArrayStrcmp, NULL, NULL, 0, _cupsArrayStrdup, _cupsArrayFree); for (i = 0; i < count; i ++) { diff --git a/xcode/CUPS.xcodeproj/project.pbxproj b/xcode/CUPS.xcodeproj/project.pbxproj index fe9f4e0179..b7e1cd7581 100644 --- a/xcode/CUPS.xcodeproj/project.pbxproj +++ b/xcode/CUPS.xcodeproj/project.pbxproj @@ -774,7 +774,7 @@ 278C58E3136B647200836530 /* testhttp.c in Sources */ = {isa = PBXBuildFile; fileRef = 278C58E2136B647200836530 /* testhttp.c */; }; 279AE6F52395B80F004DD600 /* libpam.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 279AE6F42395B80F004DD600 /* libpam.tbd */; }; 27A034821A8BDC3A00650675 /* lpadmin.c in Sources */ = {isa = PBXBuildFile; fileRef = 2732E08D137A3F5200FAFEF6 /* lpadmin.c */; }; - 27A034851A8BDC5C00650675 /* libcups2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72220EAE1333047D00FCA411 /* libcups2.dylib */; }; + 27A9AE9D2E85EEB200D3B3F6 /* libcups2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72220EAE1333047D00FCA411 /* libcups2.dylib */; }; 27B493C22C8FC125004C7A73 /* GSS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 72D53A2915B49110003F877F /* GSS.framework */; }; 27B493C32C8FC125004C7A73 /* GSS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 72D53A2915B49110003F877F /* GSS.framework */; }; 27B493C42C8FC125004C7A73 /* GSS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 72D53A2915B49110003F877F /* GSS.framework */; }; @@ -4612,7 +4612,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 27A034851A8BDC5C00650675 /* libcups2.dylib in Frameworks */, + 27A9AE9D2E85EEB200D3B3F6 /* libcups2.dylib in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -7917,7 +7917,7 @@ isa = PBXProject; attributes = { BuildIndependentTargetsInParallel = YES; - LastUpgradeCheck = 1600; + LastUpgradeCheck = 2600; ORGANIZATIONNAME = "Apple Inc."; TargetAttributes = { 270695FD1CADF3E200FFE5FB = { @@ -12739,6 +12739,7 @@ "-D_CUPS_SOURCE", "-Wno-shorten-64-to-32", ); + STRING_CATALOG_GENERATE_SYMBOLS = YES; USE_HEADERMAP = NO; WARNING_CFLAGS = "-Wno-deprecated-declarations"; }; @@ -12809,6 +12810,7 @@ "-D_CUPS_SOURCE", "-Wno-shorten-64-to-32", ); + STRING_CATALOG_GENERATE_SYMBOLS = YES; USE_HEADERMAP = NO; WARNING_CFLAGS = "-Wno-deprecated-declarations"; }; -- 2.47.3