Skip to content

Commit 005d6ea

Browse files
rustyrussellShahanaFarooqui
authored andcommitted
ccan: update to latest.
We fix the configure test which was bogus, and breaks on 32-bit gcc with optimization: ``` checking for unaligned access to int... ccan/tools/configurator/configurator: Test for HAVE_UNALIGNED_ACCESS did not compile: configuratortest.c: In function 'main': configuratortest.c:8:22: error: array subscript 'int[0]' is partly outside array bounds of 'char[4]' [-Werror=array-bounds] 8 | return *x == *y; | ^~ configuratortest.c:5:11: note: at offset 1 into object 'pad' of size 4 5 | char pad[sizeof(int *) * 1]; | ^~~ cc1: all warnings being treated as errors ``` And also removes sprintf() calls, which apparently MacOS no longer likes: Environment: Sequoia 15.6.1 (24G90) SDK Version: MacOSX15.sdk ``` ccan/ccan/closefrom/closefrom.c:83:2: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations] 83 | sprintf(dnam, "/proc/%ld/fd", (long) getpid()); | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:278:1: note: 'sprintf' has been explicitly marked deprecated here 278 | deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.") | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:218:48: note: expanded from macro 'deprecated_msg' 218 | #define deprecated_msg(_msg) attribute((deprecated(_msg))) | ^ ccan/ccan/closefrom/closefrom.c:162:2: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations] 162 | sprintf(dnam, "/proc/%ld/fd", (long) getpid()); | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:278:1: note: 'sprintf' has been explicitly marked deprecated here 278 | deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.") | ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:218:48: note: expanded from macro 'deprecated_msg' 218 | #define deprecated_msg(_msg) attribute((deprecated(_msg))) | ^ 2 errors generated. make: *** [ccan-closefrom.o] Error 1 ``` Signed-off-by: Rusty Russell <[email protected]> Reported-by: Sangbida Fixes: #8581 Reported-by: https://github.com/Raimo33 Fixes: #8501 Changelog-Fixed: build: we now build on MacOS without errors on the latest Command Line Tools (macOS 15 SDK). Changelog-Fixes: build: fix build with -O2 on 32 bit arm (armhf)
1 parent a780004 commit 005d6ea

File tree

24 files changed

+57
-92
lines changed

24 files changed

+57
-92
lines changed

ccan/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
CCAN imported from http://ccodearchive.net.
22

3-
CCAN version: init-2597-gc4760b30
3+
CCAN version: init-2602-gfd3fd70c

ccan/ccan/closefrom/closefrom.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static bool can_open_proc_pid_fd(void)
8080
char dnam[PROC_PID_FD_LEN];
8181
DIR *dir;
8282

83-
sprintf(dnam, "/proc/%ld/fd", (long) getpid());
83+
snprintf(dnam, sizeof(dnam), "/proc/%ld/fd", (long) getpid());
8484
dir = opendir(dnam);
8585
if (!dir)
8686
return false;
@@ -159,7 +159,7 @@ void closefrom(int fromfd)
159159

160160
maxfd = sysconf(_SC_OPEN_MAX);
161161

162-
sprintf(dnam, "/proc/%ld/fd", (long) getpid());
162+
snprintf(dnam, sizeof(dnam), "/proc/%ld/fd", (long) getpid());
163163
dir = try_opendir(dnam, &fromfd, maxfd);
164164
if (!dir)
165165
dir = try_opendir("/dev/fd", &fromfd, maxfd);

ccan/ccan/json_escape/_info

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ int main(int argc, char *argv[])
3232

3333
if (strcmp(argv[1], "depends") == 0) {
3434
printf("ccan/tal\n");
35+
printf("ccan/tal/str\n");
3536
return 0;
3637
}
3738

ccan/ccan/json_out/_info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* json_out_start(jout, NULL, '{');
4141
* for (int i = 1; i < argc; i++) {
4242
* char fieldname[80];
43-
* sprintf(fieldname, "argv%i", i);
43+
* snprintf(fieldname, sizeof(fieldname), "argv%i", i);
4444
* json_out_add(jout, fieldname,
4545
* !can_be_json_literal(argv[i]),
4646
* "%s", argv[i]);

ccan/ccan/likely/likely.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ char *likely_stats(unsigned int min_hits, unsigned int percent)
8484
struct thash_iter i;
8585
char *ret;
8686
struct trace *t;
87+
size_t maxlen;
8788

8889
worst = NULL;
8990
worst_ratio = 2;
@@ -101,15 +102,16 @@ char *likely_stats(unsigned int min_hits, unsigned int percent)
101102
if (worst_ratio * 100 > percent)
102103
return NULL;
103104

104-
ret = malloc(strlen(worst->condstr) +
105-
strlen(worst->file) +
106-
sizeof(long int) * 8 +
107-
sizeof("%s:%u:%slikely(%s) correct %u%% (%lu/%lu)"));
108-
sprintf(ret, "%s:%u:%slikely(%s) correct %u%% (%lu/%lu)",
109-
worst->file, worst->line,
110-
worst->expect ? "" : "un", worst->condstr,
111-
(unsigned)(worst_ratio * 100),
112-
worst->right, worst->count);
105+
maxlen = strlen(worst->condstr) +
106+
strlen(worst->file) +
107+
sizeof(long int) * 8 +
108+
sizeof("%s:%u:%slikely(%s) correct %u%% (%lu/%lu)");
109+
ret = malloc(maxlen);
110+
snprintf(ret, maxlen - 1, "%s:%u:%slikely(%s) correct %u%% (%lu/%lu)",
111+
worst->file, worst->line,
112+
worst->expect ? "" : "un", worst->condstr,
113+
(unsigned)(worst_ratio * 100),
114+
worst->right, worst->count);
113115

114116
thash_del(&htable, worst);
115117
free(worst);

ccan/ccan/opt/helpers.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616

1717
static char *arg_bad(const char *fmt, const char *arg)
1818
{
19-
char *str = opt_alloc.alloc(strlen(fmt) + strlen(arg));
20-
sprintf(str, fmt, arg);
19+
char *str = opt_alloc.alloc(strlen(fmt) + strlen(arg) + 1);
20+
snprintf(str, strlen(fmt) + strlen(arg), fmt, arg);
21+
str[strlen(fmt) + strlen(arg)] = '\0';
2122
return str;
2223
}
2324

ccan/ccan/opt/opt.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,10 @@ void opt_log_stderr_exit(const char *fmt, ...)
296296

297297
char *opt_invalid_argument(const char *arg)
298298
{
299-
char *str = opt_alloc.alloc(sizeof("Invalid argument '%s'") + strlen(arg));
300-
sprintf(str, "Invalid argument '%s'", arg);
299+
size_t maxlen = sizeof("Invalid argument '%s'") + strlen(arg);
300+
char *str = opt_alloc.alloc(maxlen + 1);
301+
snprintf(str, maxlen, "Invalid argument '%s'", arg);
302+
str[maxlen] = '\0';
301303
return str;
302304
}
303305

ccan/ccan/opt/test/run-helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ int main(int argc, char *argv[])
163163
pass("Can't test error message");
164164
} else {
165165
char buf[30];
166-
sprintf(buf, "%lu", ULONG_MAX);
166+
snprintf(buf, sizeof(buf), "%lu", ULONG_MAX);
167167
ok1(!parse_args(&argc, &argv, "-a", buf, NULL));
168168
ok1(strstr(err_output, ": -a: value '")
169169
&& strstr(err_output, buf)

ccan/ccan/rune/rune.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ static const char *rune_alt_single(const tal_t *ctx,
308308
/* Caller can't set both! */
309309
if (fieldval_int) {
310310
assert(!fieldval_str);
311-
sprintf(strfield, "%"PRIi64, *fieldval_int);
311+
snprintf(strfield, sizeof(strfield) - 1, "%"PRIi64, *fieldval_int);
312+
strfield[sizeof(strfield) - 1] = '\0';
312313
fieldval_str = strfield;
313314
fieldval_strlen = strlen(strfield);
314315
}

ccan/ccan/str/test/run-STR_MAX_CHARS.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,35 @@ int main(void)
2424
memset(&types, 0xFF, sizeof(types));
2525

2626
/* Hex versions */
27-
sprintf(str, "0x%llx", (unsigned long long)types.u1byte);
27+
snprintf(str, sizeof(str), "0x%llx", (unsigned long long)types.u1byte);
2828
ok1(strlen(str) < STR_MAX_CHARS(types.u1byte));
29-
sprintf(str, "0x%llx", (unsigned long long)types.u2byte);
29+
snprintf(str, sizeof(str), "0x%llx", (unsigned long long)types.u2byte);
3030
ok1(strlen(str) < STR_MAX_CHARS(types.u2byte));
31-
sprintf(str, "0x%llx", (unsigned long long)types.u4byte);
31+
snprintf(str, sizeof(str), "0x%llx", (unsigned long long)types.u4byte);
3232
ok1(strlen(str) < STR_MAX_CHARS(types.u4byte));
33-
sprintf(str, "0x%llx", (unsigned long long)types.u8byte);
33+
snprintf(str, sizeof(str), "0x%llx", (unsigned long long)types.u8byte);
3434
ok1(strlen(str) < STR_MAX_CHARS(types.u8byte));
3535

3636
/* Decimal versions */
37-
sprintf(str, "%u", types.u1byte);
37+
snprintf(str, sizeof(str), "%u", types.u1byte);
3838
ok1(strlen(str) < STR_MAX_CHARS(types.u1byte));
39-
sprintf(str, "%d", types.s1byte);
39+
snprintf(str, sizeof(str), "%d", types.s1byte);
4040
ok1(strlen(str) < STR_MAX_CHARS(types.s1byte));
41-
sprintf(str, "%u", types.u2byte);
41+
snprintf(str, sizeof(str), "%u", types.u2byte);
4242
ok1(strlen(str) < STR_MAX_CHARS(types.u2byte));
43-
sprintf(str, "%d", types.s2byte);
43+
snprintf(str, sizeof(str), "%d", types.s2byte);
4444
ok1(strlen(str) < STR_MAX_CHARS(types.s2byte));
45-
sprintf(str, "%u", types.u4byte);
45+
snprintf(str, sizeof(str), "%u", types.u4byte);
4646
ok1(strlen(str) < STR_MAX_CHARS(types.u4byte));
47-
sprintf(str, "%d", types.s4byte);
47+
snprintf(str, sizeof(str), "%d", types.s4byte);
4848
ok1(strlen(str) < STR_MAX_CHARS(types.s4byte));
49-
sprintf(str, "%llu", (unsigned long long)types.u8byte);
49+
snprintf(str, sizeof(str), "%llu", (unsigned long long)types.u8byte);
5050
ok1(strlen(str) < STR_MAX_CHARS(types.u8byte));
51-
sprintf(str, "%lld", (long long)types.s8byte);
51+
snprintf(str, sizeof(str), "%lld", (long long)types.s8byte);
5252
ok1(strlen(str) < STR_MAX_CHARS(types.s8byte));
5353

5454
/* Pointer version. */
55-
sprintf(str, "%p", types.ptr);
55+
snprintf(str, sizeof(str), "%p", types.ptr);
5656
ok1(strlen(str) < STR_MAX_CHARS(types.ptr));
5757

5858
return exit_status();

0 commit comments

Comments
 (0)