[omniORB] generated types copy constructor problem

Michael Teske subscribe at teskor.de
Mon Apr 13 14:05:32 BST 2015


Hi,

we have a complex union datatype in our idls, but it can be simplified
to this idl:

---
module TestUnion
{
  enum DataType {
    StringType,
    IntegerType,
    StringArrayType
  };

  typedef sequence<string> _StringArray;
  typedef string _String;
  typedef long _Integer;

  union Foo switch (DataType) {
    case StringType:
      _String StringData;
    case IntegerType:
      _Integer IntegerData;


    case StringArrayType:
      _StringArray   StringArrayData;
  };
};
---
In the generated c++ code, the copy constructor of TestUnion::Foo will be

    Foo& operator=(const Foo& _value) {
      if (&_value != this) {
        switch(_value._pd__d) {
          case StringType: StringData(_value.StringData()); break;

          case IntegerType: IntegerData(_value.IntegerData()); break;

          case StringArrayType:
StringArrayData(_value.StringArrayData()); break;

            default: break;


        }
        _pd__d = _value._pd__d;

        _pd__initialised = _value._pd__initialised;
      }

the problem here is, that if _value here is not yet initialised,
_value._pd__d points to uninitialised data. If this is e.g.
2(StringArrayType) by accident the program crashes.  IMHO there should
be a check of _value._pd__initialised first, so nothing is done if
_value._pd__initialised is not true.
This happened all the time in one of our applications which used such a
datatype in a QMap with the []-operator , which initialises the value
with a default constructed one.
I'd provide a patch but this must be somewhere in the idl compiler and I
hope maybe someone else (probably Duncan ;-) ) immediately knows where
to look and could give me a hint where to find the location...

Greetings,
  Michael



More information about the omniORB-list mailing list