#239 perl - invalid code if C++ method has default parameters


If method of a C++ class has parameters with default values, and is not overloaded, the code generated for Perl crashes, because it tries to assign value to contents of a NULL pointer. The patch is attached. I've applied the same solution as used in the equivalent python file (if statement added).


  • MarkoK

    MarkoK - 2010-03-10

    patch for perl5

  • MarkoK

    MarkoK - 2010-03-10

    Forgot to mention - the patch was made against the current trunk, svn. rev. 11934

  • Robert Stone

    Robert Stone - 2010-03-13
    • assigned_to: nobody --> talby
  • Robert Stone

    Robert Stone - 2010-03-13

    Thanks for the report! There's clearly something wrong in this area of the code if you were able to get an attempt to dereference a NULL pointer, but I'm having trouble reproducing the issue. I'd like to build a testcase so I can be certain this problem won't re-emerge.

    I tried something like:
    class Thing {
    int method(Thing *p = 0) {
    return p ? 1 : 0;

    but can't seem find a way to make the generated code crash with this.

  • MarkoK

    MarkoK - 2010-03-16

    There is another important change in my copy of SWIG 1.3.40 I forgot to mention - I've copied
    boost_shared_ptr.i from your branch. It seems to work with the exception of
    this problem.

    One of my 'broken' methods is:
    void addFunction(const std::string &functionName,
    bool isIncludeFunctionLines = false);

    The generated code:

    XS(_wrap_CProfilerController_addFunction) {

    unsigned long _index = 0;
    SWIG_TypeRank _rank = 0;
    if (items == 2) {
    SWIG_TypeRank _ranki = 0;
    SWIG_TypeRank _rankm = 0;
    SWIG_TypeRank _pi = 1;
    int _v = 0;
    int res = SWIG_ConvertPtr(ST(0), 0, SWIGTYPE_p_std__tr1__shared_ptrT_isys__CProfilerController_t, 0);
    _v = SWIG_CheckState(res);

    The problem is in the second parameter of SWIG_ConvertPtr(), which is 0 and
    breaks in the code I've patched.


  • Robert Stone

    Robert Stone - 2014-10-01

    I tried to reproduce this issue in the current version of SWIG and the caller of SWIG_ConvertPtr() no longer sends null pointers in this context.

  • Robert Stone

    Robert Stone - 2014-10-01
    • status: open --> closed-out-of-date
    • Group: -->

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks