IBM Support

IZ91501: SEGFAULT WHEN THROWING IN VECTOR

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • The following reduced test case segfaults if compiled with xlC
    on AIX, but runs correctly if compiled with g++ on AIX.
    
    $cat vec_throw_test.cpp
    #include <vector>
    #include <iostream>
    #include <stdexcept>
    
    using namespace std;
    
    static int n;
    
    class A
    {
    public:
        A()
        {
            me = n++;
            cout << "A() me=" << me << endl;
        }
        A(const A & x)
        {
            me = n++;
            cout << "A(A) me=" << me << ", x=" << x.me << endl;
            if ( me==13 )
                throw runtime_error("constructor failure");
        }
        const A & operator=(const A & x)
        {
            cout << "A=A me=" << me << ", x=" << x.me << endl;
            return *this;
        }
        ~A()
        {
            cout << "~A me=" << me << endl;
        }
    
        int me;
    };
    
    int main()
    {
        try
        {
        vector<A> a_vec;
        a_vec.reserve(10);
        A a;
        for (size_t i=0; i<15; ++i)
        {
            cout << "create " << i << endl;
            a_vec.push_back(a);
            cout << "vec=[";
            for (size_t j=0; j<a_vec.size(); ++j)
                cout << " " << a_vec[j].me;
            cout << " ]" << endl;
        }
        }
        catch ( const exception & x )
        {
            cout << "caught exception: " << x.what() << endl;
        }
        return 0;
    }
    
    
    
    $xlC vec_throw_test.cpp
    $./a.out
    ....
    ....
    Memory Fault
    

Local fix

  • N/A
    

Problem summary

  • PROBLEM DESCRIPTION: When a throw occurs in a user copy ctor
    when insertion causes a vector to relocate and grow, an
    unitialized pointer is used when cleaning up the partially
    constructed vector.
    
    USERS AFFECTED: std::vector on aix.
    

Problem conclusion

  • The vector pointer is now initialized. Apply recommended
    service.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IZ91501

  • Reported component name

    XL C/C++ AIX

  • Reported component ID

    5724X1300

  • Reported release

    B10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2011-01-03

  • Closed date

    2011-01-03

  • Last modified date

    2011-01-05

  • APAR is sysrouted FROM one or more of the following:

    IZ81882

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    XL C/C++ AIX

  • Fixed component ID

    5724X1300

Applicable component levels

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSGH3R","label":"XL C\/C++ for AIX"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"11.1","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]

Document Information

Modified date:
05 January 2011