Fixed bug for bounded sequnce

Tsuyoshi HANAMURA tsuy-h@ascii.co.jp
Fri, 12 Dec 1997 09:56:01 +0900


Hello Sai-Lai;


Thanks for your early release of omniorb 2.4.0.

During porting my client code from VisiBroker fro SunOS, I found bugs
on _CORBA_Bounded_Sequence and corresponding Array type in 'seqtemplates.
h' and fixed them with a small patch.

The problem was that a nest of bounded sequence could not be
instantiated due to memory allocation fault (not enough memory). I
attached the extracted portion of IDL definitons of an actually
existing stanadard. 

struct SubDescriptor {
	octet subDescriptorType;
	octet subDescriptorLength;
	sequence<octet, 255> additionalInformation;
};
struct InterfaceDescriptor {
	octet descriptorType;
	octet descriptorLength;
	u_long specifier;
	u_short model;
	u_short version;
	sequence<SubDescriptor, 255> subDescriptorList;
};
struct CompatibilityDescriptor {
	u_short length;
	sequence<InterfaceDescriptor, 65535> interfaceDescriptorList;
};
struct InfoRequest {
	u_long bufferSize;
	u_short maximumBlockSize;
	CompatibilityDescriptor userCompatibilitiesBytes;
	sequence<octet, 65535> privateDataBytes; 
};


After several hour investigation, I found the source of the problem in
seqtemplates.h that on an instantiation of _CORBA_Bounded_Sequence,
memory allocation take place by using the constructor of corresponding
base class _CORBA_Sequence with a size of maximum value. In the above
example, neccessary memory size was product of max value of all the
elements (i.e. 65535 * 65535 * 255 * 255), which exhaustively ate
whole of available memory space on my Linux system.

Refering to p.16-23 of CORBA 2.0 July 1995, the maximum value for
sequence is specified as follows:

For an unbounded sequence, the maximum() accessor function returns the 
total amount of buffer space currently available. ....  For a bounded
sequence, maximum() always returns the bound of the sequence as given
in its OMG IDL type declaration.

My interpretation from this sentence is that there is no need to
reserve memory space of maximum size for unbounded sequence. So I
patched with the file "seqtemplates.h" to get my system work correctly 
without memory allocation fault.

I would attach the diff file from the version of
snapshot_971120. Please incorporate them to the next release after
examination of acceptability.

PS: Additional patch for _CORBA_Sequence is included in to make it
    compatible to VisiBroker.


-----
Tsuyoshi Hanamura, PhD
ASCII Laboratories Inc.
tsuy-h@ascii.co.jp


--------------------< patch for bounded sequence >-------------------
*** snapshot_971120/include/omniORB2/seqtemplates.h-orig	Mon Nov  3 21:10:30 1997
--- snapshot_971120/include/omniORB2/seqtemplates.h	Thu Dec 11 13:05:09 1997
***************
*** 77,83 ****
  		pd_len(s.pd_len),
  		pd_rel(1)
    {
!     if (!(pd_buf = allocbuf(s.pd_len))) {
        _CORBA_new_operator_return_null();
        // never reach here
      }
--- 77,83 ----
  		pd_len(s.pd_len),
  		pd_rel(1)
    {
!     if (!(pd_buf = allocbuf(s.pd_max))) {
        _CORBA_new_operator_return_null();
        // never reach here
      }
***************
*** 238,244 ****
  template <class T,int max>
  class _CORBA_Bounded_Sequence : public _CORBA_Sequence<T> {
  public:
!   inline _CORBA_Bounded_Sequence() : _CORBA_Sequence<T>(max) {}
    inline _CORBA_Bounded_Sequence(_CORBA_ULong length,
  				 T           *value,
  				 _CORBA_Boolean release = 0)
--- 238,244 ----
  template <class T,int max>
  class _CORBA_Bounded_Sequence : public _CORBA_Sequence<T> {
  public:
!   inline _CORBA_Bounded_Sequence() {}
    inline _CORBA_Bounded_Sequence(_CORBA_ULong length,
  				 T           *value,
  				 _CORBA_Boolean release = 0)
***************
*** 247,252 ****
--- 247,253 ----
              : _CORBA_Sequence<T>(s) {}
    inline ~_CORBA_Bounded_Sequence() {}
    inline _CORBA_Bounded_Sequence<T,max> &operator= (const _CORBA_Bounded_Sequence<T,max> &s);
+   inline _CORBA_ULong maximum() const { return max; }
    inline _CORBA_ULong length() const { return _CORBA_Sequence<T>::length(); }
    inline void length(_CORBA_ULong len);
    inline size_t NP_alignedSize(size_t initialoffset) const;
***************
*** 275,280 ****
--- 276,282 ----
          (const 
            _CORBA_Bounded_Sequence_w_FixSizeElement<T,max,elmSize,elmAlignment>&
              s);
+   inline _CORBA_ULong maximum() const { return max; }
    inline _CORBA_ULong length() const;
    inline void length(_CORBA_ULong len);
    // omniORB2 extensions
***************
*** 323,329 ****
  		pd_len(s.pd_len),
  		pd_rel(1)
    {
!     if (!(pd_buf = allocbuf(s.pd_len))) {
        _CORBA_new_operator_return_null();
        // never reach here
      }
--- 325,331 ----
  		pd_len(s.pd_len),
  		pd_rel(1)
    {
!     if (!(pd_buf = allocbuf(s.pd_max))) {
        _CORBA_new_operator_return_null();
        // never reach here
      }
***************
*** 490,496 ****
  template <class T,class T_slice,class Telm,int dimension,int max>
  class _CORBA_Bounded_Sequence_Array : public _CORBA_Sequence_Array<T,T_slice,Telm,dimension> {
  public:
!   inline _CORBA_Bounded_Sequence_Array() : _CORBA_Sequence_Array<T,T_slice,Telm,dimension>(max) {}
    inline _CORBA_Bounded_Sequence_Array(_CORBA_ULong length,
  				       T           *value,
  				       _CORBA_Boolean release = 0)
--- 492,498 ----
  template <class T,class T_slice,class Telm,int dimension,int max>
  class _CORBA_Bounded_Sequence_Array : public _CORBA_Sequence_Array<T,T_slice,Telm,dimension> {
  public:
!   inline _CORBA_Bounded_Sequence_Array() {}
    inline _CORBA_Bounded_Sequence_Array(_CORBA_ULong length,
  				       T           *value,
  				       _CORBA_Boolean release = 0)
***************
*** 499,504 ****
--- 501,507 ----
              : _CORBA_Sequence_Array<T,T_slice,Telm,dimension>(s) {}
    inline ~_CORBA_Bounded_Sequence_Array() {}
    inline _CORBA_Bounded_Sequence_Array<T,T_slice,Telm,dimension,max> &operator= (const _CORBA_Bounded_Sequence_Array<T,T_slice,Telm,dimension,max> &s);
+   inline _CORBA_ULong maximum() const { return max; }
    inline _CORBA_ULong length() const { return _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::length(); }
    inline void length(_CORBA_ULong len);
    inline size_t NP_alignedSize(size_t initialoffset) const;
***************
*** 527,532 ****
--- 530,536 ----
          (const 
            _CORBA_Bounded_Sequence_Array_w_FixSizeElement<T,T_slice,Telm,dimension,max,elmSize,elmAlignment>&
              s);
+   inline _CORBA_ULong maximum() const { return max; }
    inline _CORBA_ULong length() const;
    inline void length(_CORBA_ULong len);
    // omniORB2 extensions