home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / oop / macapp3 / 197 < prev    next >
Encoding:
Internet Message Format  |  1992-12-15  |  1.7 KB

  1. Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!uwm.edu!spool.mu.edu!agate!stanford.edu!apple!applelink.apple.com
  2. From: GER.XSE0039@AppleLink.Apple.COM (Germany - C Brinkschulte Berlin,IDV)
  3. Newsgroups: comp.sys.mac.oop.macapp3
  4. Subject: Bug In TDynamicArray (MA3.0.1)
  5. Message-ID: <724440372.3097661@AppleLink.Apple.COM>
  6. Date: 15 Dec 92 17:19:00 GMT
  7. Sender: daemon@Apple.COM
  8. Organization: AppleLink Gateway
  9. Lines: 42
  10.  
  11. Hi, MacAppers,
  12.  
  13. There is a Bug in MacApp 3.0.1 in the class "TDynamicArray".
  14.  
  15. The problem arises when a TDynamicArray is cloned while an Iterator which was
  16. used for the TDynamicArray is stil in scope. TDynamicArray has a field named
  17. fIteratorPtr, which contains a linked list of Iterators currently in use for
  18. the TDynamicArray. When a TDynamicArray gets cloned, both (the old and the
  19. cloned Array's) fIteratorPtrs point to the same Iterator. If the CArrayIterator
  20. is destructed, the fIteratorPtr of the cloned TDynamicArray points to an
  21. invalid Memory-Address.
  22.  
  23. The solution is to override TObject::Clone in TDynamicArray and set the
  24. fIteratorPtr-field of the cloned Array
  25. to NULL.
  26.  
  27. TObject* TDynamicArray::Clone () // override
  28. {
  29.     TDynamicArray* clonedArray = (TDynamicArray*) inherited:Clone ();
  30.     clonedArray->fIteratorPtr = NULL;
  31.     return clonedArray;
  32. }
  33.  
  34. A Workaround is to manually set the fIteratorPtr of the CDynamicArray to NULL
  35. after cloning a TDynamicArray.
  36.  
  37. TDynamicArray* aDynamicArray = new TDynamicArray;
  38. aDynamicArray->IDynamicArray (0, sizeof (myStruct));
  39.  
  40. [...]
  41.  
  42. TDynamicArray* clonedArray = aDynamicArray->Clone ();
  43. clonedArray->fIteratorPtr = NULL;
  44.  
  45.  
  46. I am not part of MacAppTech$ anymore, because it has flooded my In-Box too
  47. much, so please send a copy of any replys directly to me (thanks).
  48.  
  49.  
  50. Carsten Brinkschulte
  51. GER.XSE0039
  52.  
  53.