[omniORB] generated types copy constructor problem

Michael Teske subscribe at teskor.de
Mon Apr 13 16:36:18 BST 2015


Hi,

Am 13.04.15 um 16:59 schrieb Duncan Grisby:
> On Mon, 2015-04-13 at 16:27 +0200, Michael Teske wrote:
> 
> [...]
>> Another bad habit I found (probably illegal, too) is to have a sequence
>> of these union types set to e.g. length 20, initialize 10 with values
>> and then increase the length to 21 which will in case of a needed
>> reallocation lead to a copy of the elements, which may crash between
>> elements 10 to 19....
> 
> Yes, that it likely to cause trouble too...
> 
>> Since I don't have the time to check all that code I'll have to patch
>> our local copy of onmiorb to allow copies of uninitialised unions by
>> inserting something like
>> if (!_value._pd__initialised) return;
>> at the beginning of the copy constructor.
> 
> Yes, and also operator=.

Oops, almost forgot that!

>> I understand that this will not make it into omniorb, but i guess
>> template.py would be the right location here?
> 
> Yes, header/template.py is where you will find the template used for the
> generated code.
> 
> If you come up with a simple minimal patch, it can be included in
> omniORB. The standard says that there is no guarantee what the code does
> for uninitialised unions, but it doesn't require it to be actively
> hostile. Making omniORB's code robust against these situations is no bad
> thing, it's just outside the requirements of the standard.

This would be nice, of course, and relieve me of at least some headaches
:) Attached is the simplest readable patch I could think of.

Greetings,
  Michael
-------------- next part --------------
Index: omniORB/src/lib/omniORB/python/omniidl_be/cxx/header/template.py
===================================================================
--- omniORB/src/lib/omniORB/python/omniidl_be/cxx/header/template.py	(revision 202)
+++ omniORB/src/lib/omniORB/python/omniidl_be/cxx/header/template.py	(revision 204)
@@ -1027,6 +1027,7 @@
   }
   
   @unionname@(const @unionname@& _value) : _pd__initialised(0) {
+    if (!_value._pd__initialised) return;
     @copy_constructor@
     _pd__initialised = _value._pd__initialised;
   }
@@ -1037,6 +1038,10 @@
 
   @unionname@& operator=(const @unionname@& _value) {
     if (&_value != this) {
+      if (!_value._pd__initialised) {
+        _release_member();
+        return *this;
+      } 
       @copy_constructor@
       _pd__initialised = _value._pd__initialised;
     }


More information about the omniORB-list mailing list