From c5610fd4b3ff948a0220368f92dd842ef877b3f0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 16 Sep 2022 18:52:52 +0100 Subject: Guile - Add error checking to SWIGTYPE and SWIGTYPE & in typemaps To prevent seg faults when passing #nil to these parameter types. --- Lib/guile/typemaps.i | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/guile/typemaps.i b/Lib/guile/typemaps.i index 37dfaee64..45a2208f2 100644 --- a/Lib/guile/typemaps.i +++ b/Lib/guile/typemaps.i @@ -14,9 +14,14 @@ /* Pointers */ -%typemap(in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { +%typemap(in) SWIGTYPE *, SWIGTYPE [] { $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0); } +%typemap(in) SWIGTYPE & ($1_ltype argp) { + argp = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0); + if (!argp) { %argument_nullref("$1_type", $symname, $argnum); } + $1 = argp; +} %typemap(in, noblock=1, fragment="") SWIGTYPE && (void *argp = 0, int res = 0, std::unique_ptr<$*1_ltype> rvrdeleter) { res = SWIG_ConvertPtr($input, &argp, $descriptor, SWIG_POINTER_RELEASE); if (!SWIG_IsOK(res)) { @@ -136,8 +141,9 @@ /* Pass-by-value */ -%typemap(in) SWIGTYPE($&1_ltype argp) { +%typemap(in) SWIGTYPE ($&1_ltype argp) { argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, $argnum, 0); + if (!argp) { %argument_nullref("$1_type", $symname, $argnum); } $1 = *argp; } -- cgit v1.2.1