Skip to content

Commit 930966f

Browse files
committed
Fix clang warnings, clean up cupsArray usage.
1 parent 9dab50d commit 930966f

10 files changed

Lines changed: 99 additions & 75 deletions

File tree

cgi-bin/home.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ do_login(void)
112112
fputs("DEBUG2: do_login()\n", stderr);
113113

114114
// Get the metadata...
115-
oauth_uri = getenv("CUPS_OAUTH_SERVER");
116115
if ((metadata = cupsOAuthGetMetadata(oauth_uri)) == NULL)
117116
{
118117
show_error(cgiText(_("OAuth Login")), cgiText(_("Unable to get authorization server information")), cupsGetErrorString());
@@ -261,7 +260,6 @@ finish_login(void)
261260
}
262261

263262
// Get the metadata...
264-
oauth_uri = getenv("CUPS_OAUTH_SERVER");
265263
if ((metadata = cupsOAuthGetMetadata(oauth_uri)) == NULL)
266264
{
267265
show_error(cgiText(_("OAuth Login")), cgiText(_("Unable to get authorization server information")), cupsGetErrorString());

cgi-bin/ipp-var.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,36 @@ cgiGetAttributes(ipp_t *request, /* I - IPP request */
8686
attrs[0] = NULL; /* Eliminate compiler warning */
8787

8888
while ((ch = getc(in)) != EOF)
89+
{
8990
if (ch == '\\')
90-
getc(in);
91+
{
92+
if (getc(in) == EOF)
93+
break;
94+
}
9195
else if (ch == '{' && num_attrs < (int)(sizeof(attrs) / sizeof(attrs[0])))
9296
{
9397
/*
9498
* Grab the name...
9599
*/
96100

97101
for (nameptr = name; (ch = getc(in)) != EOF;)
102+
{
98103
if (strchr("}]<>=!~ \t\n", ch))
104+
{
99105
break;
106+
}
100107
else if (nameptr > name && ch == '?')
108+
{
101109
break;
110+
}
102111
else if (nameptr < (name + sizeof(name) - 1))
103112
{
104113
if (ch == '_')
105114
*nameptr++ = '-';
106115
else
107116
*nameptr++ = (char)ch;
108117
}
118+
}
109119

110120
*nameptr = '\0';
111121

@@ -117,15 +127,21 @@ cgiGetAttributes(ipp_t *request, /* I - IPP request */
117127
*/
118128

119129
for (i = 0; i < num_attrs; i ++)
130+
{
120131
if (!strcmp(attrs[i], name))
121132
break;
133+
}
122134

123135
if (i >= num_attrs)
124136
{
125137
attrs[num_attrs] = strdup(name);
126138
num_attrs ++;
127139
}
140+
141+
if (ch == EOF)
142+
break;
128143
}
144+
}
129145

130146
/*
131147
* If we have attributes, add a requested-attributes attribute to the

cups/array.c

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,20 @@ cupsArrayFirst(cups_array_t *a) // I - Array
433433
}
434434

435435

436+
//
437+
// '_cupsArrayFree()' - Free a string in an array.
438+
//
439+
440+
void
441+
_cupsArrayFree(void *s, // I - String to free
442+
void *data) // I - Callback data (unused)
443+
{
444+
(void)data;
445+
446+
free(s);
447+
}
448+
449+
436450
//
437451
// 'cupsArrayGetCount()' - Get the number of elements in the array.
438452
//
@@ -827,7 +841,7 @@ cupsArrayNewStrings(const char *s, // I - Delimited strings or `NULL`
827841
cups_array_t *a; // Array
828842

829843

830-
if ((a = cupsArrayNew3((cups_array_cb_t)strcmp, NULL, NULL, 0, (cups_acopy_cb_t)_cupsArrayStrdup, (cups_afree_cb_t)_cupsArrayFree)) != NULL)
844+
if ((a = cupsArrayNew3(_cupsArrayStrcmp, NULL, NULL, 0, _cupsArrayStrdup, _cupsArrayFree)) != NULL)
831845
cupsArrayAddStrings(a, s, delim);
832846

833847
return (a);
@@ -988,6 +1002,50 @@ cupsArraySave(cups_array_t *a) // I - Array
9881002
}
9891003

9901004

1005+
//
1006+
// '_cupsArrayStrcasecmp()' - Compare two strings in an array, ignoring case...
1007+
//
1008+
1009+
int // O - Result of comparison
1010+
_cupsArrayStrcasecmp(void *s, // I - First string
1011+
void *t, // I - Second string
1012+
void *data) // I - Callback data (unused)
1013+
{
1014+
(void)data;
1015+
1016+
return (_cups_strcasecmp((const char *)s, (const char *)t));
1017+
}
1018+
1019+
1020+
//
1021+
// '_cupsArrayStrcmp()' - Compare two strings in an array.
1022+
//
1023+
1024+
int // O - Result of comparison
1025+
_cupsArrayStrcmp(void *s, // I - first string to compare
1026+
void *t, // I - second string to compare
1027+
void *data) // I - Callback data (unused)
1028+
{
1029+
(void)data;
1030+
1031+
return (strcmp((const char *)s, (const char *)t));
1032+
}
1033+
1034+
1035+
//
1036+
// '_cupsArrayStrdup()' - Copy a string in an array.
1037+
//
1038+
1039+
void * // O - Copy of string
1040+
_cupsArrayStrdup(void *s, // I - String to copy
1041+
void *data) // I - Callback data (unused)
1042+
{
1043+
(void)data;
1044+
1045+
return (strdup((const char *)s));
1046+
}
1047+
1048+
9911049
//
9921050
// 'cupsArrayUserData()' - Return the user data for an array.
9931051
//
@@ -1253,43 +1311,3 @@ cups_array_find(cups_array_t *a, // I - Array
12531311

12541312
return (current);
12551313
}
1256-
1257-
1258-
/*
1259-
* '_cupsArrayStrcmp()' - Meant to be passed as a pointer to CUPS arrays instead
1260-
* of strcmp. Will also work if called directly.
1261-
*/
1262-
1263-
int _cupsArrayStrcmp(const char *s1, /* I - first string to compare */
1264-
const char *s2, /* I - second string to compare */
1265-
void *data) /* Unused */
1266-
{
1267-
(void)data;
1268-
return (strcmp(s1, s2));
1269-
}
1270-
1271-
1272-
/*
1273-
* '_cupsArrayStrdup()' - Meant to be passed as a pointer to CUPS arrays instead
1274-
* of strdup. Will also work if called directly.
1275-
*/
1276-
1277-
char *_cupsArrayStrdup(const char *element, /* I - element to duplicate */
1278-
void *data) /* Unused */
1279-
{
1280-
(void)data;
1281-
return (strdup(element));
1282-
}
1283-
1284-
1285-
/*
1286-
* '_cupsArrayFree()' - Meant to be passed as a pointer to CUPS arrays instead
1287-
* of free. Will also work if called directly.
1288-
*/
1289-
1290-
void _cupsArrayFree(void *element, /* I - element to free */
1291-
void *data) /* Unused */
1292-
{
1293-
(void)data;
1294-
free(element);
1295-
}

cups/oauth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ cupsOAuthGetDeviceGrant(
861861
char *client_id = NULL, // `client_id` value
862862
*scopes_supported = NULL;
863863
// Supported scopes
864-
size_t num_form = 0; // Number of form variables
864+
int num_form = 0; // Number of form variables
865865
cups_option_t *form = NULL; // Form variables
866866
char *request = NULL; // Form request data
867867
cups_json_t *grant = NULL; // Device grant

cups/string-private.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ extern void _cups_strcpy(char *dst, const char *src) _CUPS_PRIVATE;
129129
extern int _cups_strcasecmp(const char *, const char *) _CUPS_PRIVATE;
130130
extern int _cups_strncasecmp(const char *, const char *, size_t n) _CUPS_PRIVATE;
131131

132-
extern int _cupsArrayStrcasecmp(const char *s, const char *t, void *data) _CUPS_PRIVATE;
133-
extern int _cupsArrayStrcmp(const char *s1, const char *s2, void *data) _CUPS_PRIVATE;
134-
extern char *_cupsArrayStrdup(const char *element, void *data) _CUPS_PRIVATE;
135-
extern void _cupsArrayFree(void *element, void *data) _CUPS_PRIVATE;
132+
extern void _cupsArrayFree(void *s, void *data) _CUPS_PRIVATE;
133+
extern int _cupsArrayStrcasecmp(void *s, void *t, void *data) _CUPS_PRIVATE;
134+
extern int _cupsArrayStrcmp(void *s, void *t, void *data) _CUPS_PRIVATE;
135+
extern void *_cupsArrayStrdup(void *s, void *data) _CUPS_PRIVATE;
136136

137137
extern char *_cupsStrAlloc(const char *s) _CUPS_PRIVATE;
138138
extern char *_cupsStrDate(char *buf, size_t bufsize, time_t timeval) _CUPS_PRIVATE;

cups/string.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static cups_array_t *stringpool = NULL;
3030
* Local functions...
3131
*/
3232

33-
static int compare_sp_items(_cups_sp_item_t *a, _cups_sp_item_t *b, void *data);
33+
static int compare_sp_items(_cups_sp_item_t *a, _cups_sp_item_t *b, void *data);
3434
static void validate_end(char *s, char *end);
3535

3636

@@ -1162,17 +1162,3 @@ validate_end(char *s, // I - Pointer to start of string
11621162
}
11631163
}
11641164
}
1165-
1166-
1167-
/*
1168-
* '_cupsArrayStrcasecmp()' - Compare two strings...
1169-
*/
1170-
1171-
int /* O - Result of comparison */
1172-
_cupsArrayStrcasecmp(const char *s, /* I - First string */
1173-
const char *t, /* I - Second string */
1174-
void *data) /* I - Unused */
1175-
{
1176-
(void)data;
1177-
return (_cups_strcasecmp(s, t));
1178-
}

cups/testdnssd.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DNS-SD API test program for CUPS.
33
//
4-
// Copyright © 2022-2024 by OpenPrinting.
4+
// Copyright © 2022-2025 by OpenPrinting.
55
//
66
// Licensed under Apache License v2.0. See the file "LICENSE" for more
77
// information.
@@ -10,6 +10,7 @@
1010
#include <config.h>
1111
#include "test-internal.h"
1212
#include "dnssd.h"
13+
#include "string-private.h"
1314
#include "thread.h"
1415

1516

@@ -60,14 +61,14 @@ main(int argc, // I - Number of command-line arguments
6061
// cups_dnssd_query_t *query; // DNS-SD query request
6162
cups_dnssd_resolve_t *resolve; // DNS-SD resolve request
6263
cups_dnssd_service_t *service; // DNS-SD service registration
63-
size_t num_txt; // Number of TXT record key/value pairs
64+
int num_txt; // Number of TXT record key/value pairs
6465
cups_option_t *txt; // TXT record key/value pairs
6566
testdata_t testdata; // Test data
6667

6768

6869
// Clear test data...
6970
memset(&testdata, 0, sizeof(testdata));
70-
testdata.messages = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free);
71+
testdata.messages = cupsArrayNew3(NULL, NULL, NULL, 0, _cupsArrayStrdup, _cupsArrayFree);
7172
#if _WIN32
7273
snprintf(testdata.name, sizeof(testdata.name), "Test Service %d", (int)GetCurrentProcessId());
7374
#else
@@ -319,6 +320,9 @@ browse_print_cb(
319320
// Test data
320321

321322

323+
(void)browse;
324+
(void)flags;
325+
322326
printf("%5u %s.%s.%s\n", if_index, name, regtype, domain);
323327

324328
cupsMutexLock(&data->mutex);

locale/cups_uk.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5379,7 +5379,7 @@ msgstr ""
53795379

53805380
#: cups/ppd.c:2017
53815381
msgid "No"
5382-
msgstr ""
5382+
msgstr "Ні"
53835383

53845384
#: cups/http-support.c:1349
53855385
msgid "No Content"
@@ -7097,7 +7097,7 @@ msgstr ""
70977097

70987098
#: cups/ppd.c:2015
70997099
msgid "Yes"
7100-
msgstr ""
7100+
msgstr "Так"
71017101

71027102
#: scheduler/client.c:2048
71037103
msgid "You cannot access this page."

tools/ipptool.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ alloc_data(void)
841841
data->family = AF_UNSPEC;
842842
data->def_transfer = IPPTOOL_TRANSFER_AUTO;
843843
data->def_version = 20;
844-
data->errors = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_cb_t)strdup, (cups_afree_cb_t)free);
844+
data->errors = cupsArrayNew3(NULL, NULL, NULL, 0, _cupsArrayStrdup, _cupsArrayFree);
845845
data->pass = true;
846846
data->prev_pass = true;
847847
data->request_id = (cupsGetRand() % 1000) * 137;
@@ -1933,7 +1933,7 @@ do_test(ipp_file_t *f, // I - IPP data file
19331933
break;
19341934
}
19351935

1936-
exp_errors = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_cb_t)strdup, (cups_afree_cb_t)free);
1936+
exp_errors = cupsArrayNew3(NULL, NULL, NULL, 0, _cupsArrayStrdup, _cupsArrayFree);
19371937
exp_member = strchr(expect->name, '/') != NULL;
19381938
exp_pass = false;
19391939

@@ -6970,7 +6970,7 @@ with_distinct_values(
69706970
}
69716971

69726972
// Collect values and determine they are all unique...
6973-
values = cupsArrayNew3((cups_array_cb_t)_cupsArrayStrcmp, NULL, NULL, 0, (cups_acopy_cb_t)strdup, (cups_afree_cb_t)free);
6973+
values = cupsArrayNew3((cups_array_cb_t)_cupsArrayStrcmp, NULL, NULL, 0, _cupsArrayStrdup, _cupsArrayFree);
69746974

69756975
for (i = 0; i < count; i ++)
69766976
{

xcode/CUPS.xcodeproj/project.pbxproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@
774774
278C58E3136B647200836530 /* testhttp.c in Sources */ = {isa = PBXBuildFile; fileRef = 278C58E2136B647200836530 /* testhttp.c */; };
775775
279AE6F52395B80F004DD600 /* libpam.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 279AE6F42395B80F004DD600 /* libpam.tbd */; };
776776
27A034821A8BDC3A00650675 /* lpadmin.c in Sources */ = {isa = PBXBuildFile; fileRef = 2732E08D137A3F5200FAFEF6 /* lpadmin.c */; };
777-
27A034851A8BDC5C00650675 /* libcups2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72220EAE1333047D00FCA411 /* libcups2.dylib */; };
777+
27A9AE9D2E85EEB200D3B3F6 /* libcups2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72220EAE1333047D00FCA411 /* libcups2.dylib */; };
778778
27B493C22C8FC125004C7A73 /* GSS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 72D53A2915B49110003F877F /* GSS.framework */; };
779779
27B493C32C8FC125004C7A73 /* GSS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 72D53A2915B49110003F877F /* GSS.framework */; };
780780
27B493C42C8FC125004C7A73 /* GSS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 72D53A2915B49110003F877F /* GSS.framework */; };
@@ -4612,7 +4612,7 @@
46124612
isa = PBXFrameworksBuildPhase;
46134613
buildActionMask = 2147483647;
46144614
files = (
4615-
27A034851A8BDC5C00650675 /* libcups2.dylib in Frameworks */,
4615+
27A9AE9D2E85EEB200D3B3F6 /* libcups2.dylib in Frameworks */,
46164616
);
46174617
runOnlyForDeploymentPostprocessing = 0;
46184618
};
@@ -7917,7 +7917,7 @@
79177917
isa = PBXProject;
79187918
attributes = {
79197919
BuildIndependentTargetsInParallel = YES;
7920-
LastUpgradeCheck = 1600;
7920+
LastUpgradeCheck = 2600;
79217921
ORGANIZATIONNAME = "Apple Inc.";
79227922
TargetAttributes = {
79237923
270695FD1CADF3E200FFE5FB = {
@@ -12739,6 +12739,7 @@
1273912739
"-D_CUPS_SOURCE",
1274012740
"-Wno-shorten-64-to-32",
1274112741
);
12742+
STRING_CATALOG_GENERATE_SYMBOLS = YES;
1274212743
USE_HEADERMAP = NO;
1274312744
WARNING_CFLAGS = "-Wno-deprecated-declarations";
1274412745
};
@@ -12809,6 +12810,7 @@
1280912810
"-D_CUPS_SOURCE",
1281012811
"-Wno-shorten-64-to-32",
1281112812
);
12813+
STRING_CATALOG_GENERATE_SYMBOLS = YES;
1281212814
USE_HEADERMAP = NO;
1281312815
WARNING_CFLAGS = "-Wno-deprecated-declarations";
1281412816
};

0 commit comments

Comments
 (0)