Skip to content

Commit

Permalink
Fix invalid code in testcase typemap_qualifier_strip.i
Browse files Browse the repository at this point in the history
This testcase was using a pointer to a variable which had gone out
of scope, which is undefined behaviour.  The test was only passing
because the tests are compiled without optimisation by default and
the memory where this value lived happened to remain intact in that
case with current versions of compilers we test with.  Running the
testsuite with CXXFLAGS=-O2 causes this test to fail.

Fix by extending the lifetime of the variable to the whole wrapper
function.

Fixes #1925
  • Loading branch information
ojwb committed Jan 26, 2022
1 parent 4173892 commit 07f5b37
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Examples/test-suite/typemap_qualifier_strip.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
%typemap(freearg) int *const ptrConst ""
%typemap(freearg) int const* constPtr ""

%typemap(in) int *ptr {
int temp = 1234;
%typemap(in) int *ptr (int temp) {
temp = 1234;
$1 = &temp;
}

%typemap(in) int *const ptrConst {
int temp = 5678;
%typemap(in) int *const ptrConst (int temp) {
temp = 5678;
$1 = &temp;
}

%typemap(in) int const* constPtr {
int temp = 3456;
%typemap(in) int const* constPtr (int temp) {
temp = 3456;
$1 = &temp;
}

Expand Down

0 comments on commit 07f5b37

Please sign in to comment.