Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#902 [python] returned value may be uninitialised

open
nobody
python (259)
5
2011-02-19
2008-03-25
Philipp Thomas
No

Under certain circumstances swig will generate C++ code for Python which returns an uninitialized local variable. This patch initializes c_result in that case.

Discussion

  • Olly Betts
    Olly Betts
    2008-03-26

    • summary: Initialize return value --> [python] Initialize return value
     
  • Olly Betts
    Olly Betts
    2008-03-26

    Logged In: YES
    user_id=14972
    Originator: NO

    This line looks potentially problematic to me - will we always be able to cast 0 to type return_type?

    + Printf(w->code, "c_result = (%s)0;\n", return_type);

     
  • William Fulton
    William Fulton
    2008-04-06

    Logged In: YES
    user_id=242951
    Originator: NO

    This patch needs to address values returned by value. Take a look at java.cxx for the usage of SwigValueInit to solve this problem.

     
  • Olly Betts
    Olly Betts
    2010-10-01

    It seems there is (or at least was) a genuine issue here. However the patch supplied isn't suitable because you can't cast 0 to arbitrary types, so moving this from the patch tracker to the bug tracker.

    Philipp: Do you have a test case for this? "Under certain circumstances" is rather vague, and it would be good to add a regression test for this.

     
  • Olly Betts
    Olly Betts
    2010-10-01

    • summary: [python] Initialize return value --> [python] returned value may be uninitialised
     
  • Olly Betts
    Olly Betts
    2011-02-19

    • labels: --> python
     
  • Olly Betts
    Olly Betts
    2011-02-19

    To reiterate, a test case for this would be very useful.

     
  • William Fulton
    William Fulton
    2011-02-20

    The director_ignore testcase replicates it with g++ -Wuninitialized
    william@caracal:~/swig/trunk/Examples/test-suite/python$ make -s director_ignore.cpptest CFLAGS="-Wuninitialized"
    checking testcase director_ignore under python
    director_ignore_wrap.cxx: In member function ‘virtual double SwigDirector_DTemplateAbstractIgnoresInt::OverloadedProtectedMethod(int, int, int)’:
    director_ignore_wrap.cxx:4057: warning: ‘c_result’ is used uninitialized in this function
    director_ignore_wrap.cxx: In member function ‘virtual double SwigDirector_DTemplateAbstractIgnoresInt::OverloadedMethod(int, int, int)’:
    director_ignore_wrap.cxx:3978: warning: ‘c_result’ is used uninitialized in this function
    director_ignore_wrap.cxx: In member function ‘virtual double SwigDirector_DAbstractIgnores::OverloadedProtectedMethod(int, int, int)’:
    director_ignore_wrap.cxx:3903: warning: ‘c_result’ is used uninitialized in this function
    director_ignore_wrap.cxx: In member function ‘virtual double SwigDirector_DAbstractIgnores::OverloadedMethod(int, int, int)’:
    director_ignore_wrap.cxx:3824: warning: ‘c_result’ is used uninitialized in this function
    director_ignore_wrap.cxx: In member function ‘virtual double SwigDirector_DIgnores::ProtectedPureVirtualMethod1()’:
    director_ignore_wrap.cxx:3797: warning: ‘c_result’ is used uninitialized in this function
    director_ignore_wrap.cxx: In member function ‘virtual double SwigDirector_DIgnores::PublicPureVirtualMethod1()’:
    director_ignore_wrap.cxx:3726: warning: ‘c_result’ is used uninitialized in this function