diff options
author | Olly Betts <olly@survex.com> | 2023-04-23 12:10:21 +1200 |
---|---|---|
committer | Olly Betts <olly@survex.com> | 2023-04-27 10:08:57 +1200 |
commit | 1f5ff2e6a585d0b5dca501945fabfeb48b1bf547 (patch) | |
tree | 8e89ad3733384a7dc952b74a8243562bee3cb85e /Lib/ocaml/cstring.i | |
parent | 589373309dae750ed05a46b1b955993da253a287 (diff) | |
download | swig-1f5ff2e6a585d0b5dca501945fabfeb48b1bf547.tar.gz |
Allow using snprintf() instead of sprintf() in wrappers
We aim to produce code that works with C90 or C++98 so we can't
assume snprintf() is available, but it almost always is (even
on systems from before it was standardised) so having a way to
use it is helpful.
Enable this automatically if the compiler claims conformance
with at least C90 or C++98 and check SWIG_HAVE_SNPRINTF to allow
turning on manually, but disable if SWIG_NO_SNPRINTF if defined.
The fallback is to call sprintf() without a buffer size check -
checking after the call is really shutting the stable door after
the horse has bolted, and most of our uses either have a fixed maximum
possible size or dynamically allocate a buffer that's large enough.
Fixes: #2502 (sprintf deprecation warnings on macos)
Fixes: #2548
Diffstat (limited to 'Lib/ocaml/cstring.i')
-rw-r--r-- | Lib/ocaml/cstring.i | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/ocaml/cstring.i b/Lib/ocaml/cstring.i index f1190ad5c..8b72be9d0 100644 --- a/Lib/ocaml/cstring.i +++ b/Lib/ocaml/cstring.i @@ -25,7 +25,7 @@ * * %cstring_bounded_output(char *outx, 512); * void foo(char *outx) { - * sprintf(outx,"blah blah\n"); + * strcpy(outx,"blah blah\n"); * } * */ @@ -144,7 +144,7 @@ * * %cstring_output_maxsize(char *outx, int max) { * void foo(char *outx, int max) { - * sprintf(outx,"blah blah\n"); + * strcpy(outx,"blah blah\n"); * } */ @@ -175,7 +175,7 @@ * * %cstring_output_maxsize(char *outx, int *max) { * void foo(char *outx, int *max) { - * sprintf(outx,"blah blah\n"); + * strcpy(outx,"blah blah\n"); * *max = strlen(outx); * } */ @@ -213,7 +213,7 @@ * %cstring_output_allocated(char **outx, free($1)); * void foo(char **outx) { * *outx = (char *) malloc(512); - * sprintf(outx,"blah blah\n"); + * strcpy(outx,"blah blah\n"); * } */ @@ -241,7 +241,7 @@ * %cstring_output_allocated(char **outx, int *sz, free($1)); * void foo(char **outx, int *sz) { * *outx = (char *) malloc(512); - * sprintf(outx,"blah blah\n"); + * strcpy(outx,"blah blah\n"); * *sz = strlen(outx); * } */ |