]> git.ozlabs.org Git - ccan/commit
global: avoid using sprintf.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 13 Oct 2025 03:38:56 +0000 (14:08 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 13 Oct 2025 03:38:56 +0000 (14:08 +1030)
commit9d97f36eff481b1b6168a07fee1caa7bf56d9981
tree1ed4d5996738f8743e157050add7e5d063c72ec6
parentea141afa296c7cbb031e81188d132edef461ccf3
global: avoid using sprintf.

snprintf has different footguns, but MacOS started complaining, a-la:

Core Lightning fails to compile on macOS with the latest Command Line Tools (macOS 15 SDK) due to sprintf being marked as deprecated and -Werror treating the deprecation as a compilation error.

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 <rusty@rustcorp.com.au>
19 files changed:
ccan/closefrom/closefrom.c
ccan/json/json.c
ccan/json_out/_info
ccan/likely/likely.c
ccan/opt/helpers.c
ccan/opt/opt.c
ccan/opt/test/run-helpers.c
ccan/rfc822/test/run-hdr-and-body.c
ccan/rfc822/test/run-hdr-of-name.c
ccan/rune/rune.c
ccan/str/test/run-STR_MAX_CHARS.c
ccan/str/test/run.c
ccan/strmap/test/run-order.c
ccan/strmap/test/run-prefix.c
ccan/strset/test/run-order.c
ccan/strset/test/run-prefix.c
ccan/take/take.c
ccan/tal/tal.c
tools/tools.c