checking SfxItem types ?

Michael Meeks michael.meeks at collabora.com
Thu Jan 20 16:25:25 UTC 2022


Hi Noel,

	I just saw this ubsan thing.

	Looks like there is a mix-up with:

     if (SfxItemState::SET==rAttr.GetItemState(SID_ATTR_TRANSFORM_POS_X,true,&pPoolItem)) {
         nPosDX=static_cast<const SfxInt32Item*>(pPoolItem)->GetValue() - aRect.Left();
         bChgPos=true;
     }
     if (SfxItemState::SET==rAttr.GetItemState(SID_ATTR_TRANSFORM_POS_Y,true,&pPoolItem)){
         nPosDY=static_cast<const SfxInt32Item*>(pPoolItem)->GetValue() - aRect.Top();
         bChgPos=true;
     }

	and so on - and the signed-ness of their types:

	SfxUInt32Ite vs. SfxInt32Item

	And I wondered - is that something we could build a table for, and a
clang plugin that could catch whenever we do something like:

cui/source/tabpages/swpossizetabpage.cxx:                rSet->Put( SfxInt32Item( GetWhich( SID_ATTR_TRANSFORM_POS_X ), nHoriByPos ) );

or perhaps harder:

chart2/source/controller/main/ChartController_Position.cxx:                    nWhich = pPool->GetWhich(SID_ATTR_TRANSFORM_POS_X);
chart2/source/controller/main/ChartController_Position.cxx-                    aItemSet.Put(SfxInt32Item(nWhich, nValue));

	And warn in the code that the wrong type is going
into this pool of 'any's ? =) [ or perhaps we have something like
that already? ]

	Just a thought,

		Michael.

Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: /home/collabora/online-buildscripts/staging/builddir/libreoffice/svx/source/svdraw/svdedtv1.cxx:1588:16: runtime error: downcast of address 0x6030016eb260 which does not point to an object of type 'const SfxInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: 0x6030016eb260: note: object is of type 'SfxUInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:  c7 07 00 62  b0 71 99 c5 2b 7f 00 00  01 00 00 00 68 27 00 be  94 09 00 00 be be be be  01 00 00 00
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:               ^~~~~~~~~~~~~~~~~~~~~~~
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:               vptr for 'SfxUInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/collabora/online-buildscripts/staging/builddir/libreoffice/svx/source/svdraw/svdedtv1.cxx:1588:16 in
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: /home/collabora/online-buildscripts/staging/builddir/libreoffice/svx/source/svdraw/svdedtv1.cxx:1588:61: runtime error: member call on address 0x6030016eb260 which does not point to an object of type 'CntInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: 0x6030016eb260: note: object is of type 'SfxUInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:  c7 07 00 62  b0 71 99 c5 2b 7f 00 00  01 00 00 00 68 27 00 be  94 09 00 00 be be be be  01 00 00 00
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:               ^~~~~~~~~~~~~~~~~~~~~~~
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:               vptr for 'SfxUInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/collabora/online-buildscripts/staging/builddir/libreoffice/svx/source/svdraw/svdedtv1.cxx:1588:61 in
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: /home/collabora/online-buildscripts/staging/builddir/libreoffice/include/svl/cintitem.hxx:126:41: runtime error: member access within address 0x6030016eb260 which does not point to an object of type 'const CntInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: 0x6030016eb260: note: object is of type 'SfxUInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:  c7 07 00 62  b0 71 99 c5 2b 7f 00 00  01 00 00 00 68 27 00 be  94 09 00 00 be be be be  01 00 00 00
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:               ^~~~~~~~~~~~~~~~~~~~~~~
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:               vptr for 'SfxUInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/collabora/online-buildscripts/staging/builddir/libreoffice/include/svl/cintitem.hxx:126:41 in
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: /home/collabora/online-buildscripts/staging/builddir/libreoffice/svx/source/svdraw/svdedtv1.cxx:1592:16: runtime error: downcast of address 0x6030020a1300 which does not point to an object of type 'const SfxInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: 0x6030020a1300: note: object is of type 'SfxUInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:  c7 07 00 62  b0 71 99 c5 2b 7f 00 00  01 00 00 00 69 27 00 be  ec 03 00 00 be be be be  01 00 00 00
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:               ^~~~~~~~~~~~~~~~~~~~~~~
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:               vptr for 'SfxUInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/collabora/online-buildscripts/staging/builddir/libreoffice/svx/source/svdraw/svdedtv1.cxx:1592:16 in
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: /home/collabora/online-buildscripts/staging/builddir/libreoffice/svx/source/svdraw/svdedtv1.cxx:1592:61: runtime error: member call on address 0x6030020a1300 which does not point to an object of type 'CntInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]: 0x6030020a1300: note: object is of type 'SfxUInt32Item'
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:  c7 07 00 62  b0 71 99 c5 2b 7f 00 00  01 00 00 00 69 27 00 be  ec 03 00 00 be be be be  01 00 00 00
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:               ^~~~~~~~~~~~~~~~~~~~~~~
Jan 18 06:42:13 ip-172-31-35-149 coolwsd[23775]:               vptr for 'SfxUInt32Item'


-- 
michael.meeks at collabora.com <><, GM Collabora Productivity
Hangout: mejmeeks at gmail.com, Skype: mmeeks
(M) +44 7795 666 147 - timezone usually UK / Europe


More information about the LibreOffice mailing list