summaryrefslogtreecommitdiff
path: root/Lib/d
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2023-04-23 12:10:21 +1200
committerOlly Betts <olly@survex.com>2023-04-27 10:08:57 +1200
commit1f5ff2e6a585d0b5dca501945fabfeb48b1bf547 (patch)
tree8e89ad3733384a7dc952b74a8243562bee3cb85e /Lib/d
parent589373309dae750ed05a46b1b955993da253a287 (diff)
downloadswig-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/d')
-rw-r--r--Lib/d/dexception.swg2
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/d/dexception.swg b/Lib/d/dexception.swg
index 1aadbaada..74e0422b1 100644
--- a/Lib/d/dexception.swg
+++ b/Lib/d/dexception.swg
@@ -15,7 +15,7 @@
unsigned long,
unsigned short
%{ char error_msg[256];
- sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
+ SWIG_snprintf(error_msg, sizeof(error_msg), "C++ $1_type exception thrown, value: %d", $1);
SWIG_DSetPendingException(SWIG_DException, error_msg);
return $null; %}