On Thu, Sep 29, 2011 at 10:33:50AM +0200, Maciej Rumianowski wrote: > Hi David, > > > @@ -53,7 +54,7 @@ TYPEINIT1_FACTORY( SvxClipboardFmtItem, SfxPoolItem , > > > new SvxClipboardFmtItem(0 > > > SvxClipboardFmtItem_Impl::SvxClipboardFmtItem_Impl( > > > const SvxClipboardFmtItem_Impl& rCpy ) > > > { > > > - aFmtIds.Insert( &rCpy.aFmtIds, 0 ); > > > + std::copy(rCpy.aFmtIds.begin(), rCpy.aFmtIds.end(), aFmtIds.begin()); > > > for( sal_uInt16 n = 0, nEnd = rCpy.aFmtNms.Count(); n < nEnd; ++n ) > > > { > > > String* pStr = rCpy.aFmtNms[ n ]; > > > > This is totally wrong! The original line _inserts_ all items from > > rCpy.aFmtIds at the beginning of aFmtIds. std::copy _overwrites_ the > > first n elements of aFmtIds by items from the given range--this requires > > that aFmtIds has sufficient size. Since this is constructor, aFmtIds is > > always empty, therefore the line is practically guaranteed to corrupt > > memory (unless rCpy.aFmtIds is empty). I changed it to simple copy > > construction of aFmtIds from rCpy.aFmtIds. > Thanks, sorry for that. I thought if I am working on vector than i will > automatically resize, but I missed in description that I have to > manually resize.
Hi, it will if you use vector fuctions. But standard algorithms work with iterator ranges and know nothing about the structure behind them. E.g., std::copy will work just as well if the destination is plain old array. This is nothing to be ashamed of--I suppose every one of us made the same (or similar) invalid assumption at some time in the past :) D. _______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice