checking SfxItem types ?

Miklos Vajna vmiklos at collabora.com
Fri Jan 21 08:06:58 UTC 2022


Hi Michael,

On Thu, Jan 20, 2022 at 04:25:25PM +0000, Michael Meeks <michael.meeks at collabora.com> wrote:
> 	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();

You can write the second line as:

nPosDX=pPoolItem->StaticWhichCast(SID_ATTR_TRANSFORM_POS_X).GetValue() - aRect.Left();

Because SID_ATTR_TRANSFORM_POS_X is a TypedWhichId<SfxInt32Item>(...).

The easy hack to do such conversions is:

https://bugs.documentfoundation.org/show_bug.cgi?id=140226

> 	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 ) );

I'm not sure we have a mechanism to prevent mistakes on the Put() side.

Regards,

Miklos


More information about the LibreOffice mailing list