[omniORB] generated types copy constructor problem

Johnny Willemsen jwillemsen at remedy.nl
Mon Apr 13 14:44:47 BST 2015


Hi,

I don't know the details of the omniORB implementation, but the formal
IDL to C++ language mapping says the following:

The default union constructor performs no application-visible
initialization of the union. It does not initialize the discriminator,
nor does it initialize any union members to a state useful to an
application. (The implementation of the default constructor can do
whatever type of initialization it wants to, but such initialization is
implementation-dependent. No compliant application can count on a union
ever being properly initialized by the default constructor alone.)

The IDL to C++11 language mapping does make sure that union have a
defined default state.

Best regards,

Johnny


On 04/13/2015 03:05 PM, Michael Teske wrote:
> 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
> 
> _______________________________________________
> omniORB-list mailing list
> omniORB-list at omniorb-support.com
> http://www.omniorb-support.com/mailman/listinfo/omniorb-list
> 
> 




More information about the omniORB-list mailing list