Pete - 2013-05-23

I'm running into an out of bounds error using TinyXML with pgCC 11.9-0. This happens very early on. Here's the call:

TiXmlDocument doc("abc.xml");

which generates the error:

PGC++ F-Subscript out of range for array _42539_8_str (tinystr.h: 229)
   subscript=3, upper bound=0, dimension=1

when compiled with "-g -Mbounds -Ktrap=fp". Looking at tinystr.h, I dont understand how the code should work.

    struct Rep
    {
            size_type size, capacity;
            char str[1];
    };

    void init(size_type sz, size_type cap)
    {
            if (cap)
            {
                    // Lee: the original form:
                    //      rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
                    // doesn't work in some cases of new being overloaded. Switching
                    // to the normal allocation, although use an 'int' for systems
                    // that are overly picky about structure alignment.
                    const size_type bytesNeeded = sizeof(Rep) + cap;
                    const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
                    rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
                    rep_->str[ rep_->size = sz ] = '\0';
                    rep_->capacity = cap;
            }
            ...
    }

The error occurs on line
rep_->str[ rep_->size = sz ] = '\0';
This doesn't make sense to me. Rep::str is a character array with 1 element, but sz is the length of the string being initialized. With "abc.xml", sz==7.

What am I doing wrong/not understanding?

Thanks!
Pete