include/svx/TableAutoFmt.hxx          |    2 
 include/svx/autoformathelper.hxx      |   36 ++++++++++++++---
 sc/source/core/tool/autoform.cxx      |   69 ++++++++++++++++------------------
 svx/source/items/autoformathelper.cxx |   27 ++++++++++++-
 svx/source/table/tableautofmt.cxx     |    5 ++
 sw/source/core/doc/tblafmt.cxx        |   69 ++++++++++++++++++----------------
 6 files changed, 133 insertions(+), 75 deletions(-)

New commits:
commit ad3873bdb39e1e40613908ef5dbff7f2b6dcbe60
Author:     Caolán McNamara <[email protected]>
AuthorDate: Fri Mar 6 09:23:37 2026 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Sat Mar 7 12:32:54 2026 +0100

    cid#1681370 Explicit null dereferenced
    
    and
    
    cid#1681367 Explicit null dereferenced
    cid#1681363 Explicit null dereferenced
    
    this appears to be basically bogus, it sees that the base class
    doesn't enforce that the std::unique_ptr are non-null even though
    the inherited ones do and then reports where those are dereferenced.
    
    Reorg so things are always created.
    
    Change-Id: Ifbc88b8abddc1474a2f5962aacbcbaea5c878162
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201111
    Reviewed-by: Caolán McNamara <[email protected]>
    Tested-by: Jenkins

diff --git a/include/svx/TableAutoFmt.hxx b/include/svx/TableAutoFmt.hxx
index 78106832f58f..213e4105871f 100644
--- a/include/svx/TableAutoFmt.hxx
+++ b/include/svx/TableAutoFmt.hxx
@@ -84,7 +84,7 @@ private:
     std::bitset<Autoformat::PROP_COUNT> mSetProperties;
 
 public:
-    SvxAutoFormatDataField(){};
+    SvxAutoFormatDataField(const AutoFormatWhichIds& rIds);
     SvxAutoFormatDataField(const SvxAutoFormatDataField& rCopy);
 
     virtual ~SvxAutoFormatDataField() = default;
diff --git a/include/svx/autoformathelper.hxx b/include/svx/autoformathelper.hxx
index e2f384093923..148e2567e516 100644
--- a/include/svx/autoformathelper.hxx
+++ b/include/svx/autoformathelper.hxx
@@ -23,7 +23,6 @@
 #include <svx/svxdllapi.h>
 #include <memory>
 
-class SvStream;
 class SvxFontItem;
 class SvxFontHeightItem;
 class SvxWeightItem;
@@ -40,13 +39,38 @@ class SvxBrushItem;
 class SvxAdjustItem;
 class SvxHorJustifyItem;
 class SvxVerJustifyItem;
-class SfxBoolItem;
-class SvxMarginItem;
-class SfxInt32Item;
-class SvxRotateModeItem;
 
 //////////////////////////////////////////////////////////////////////////////
 
+struct SVX_DLLPUBLIC AutoFormatWhichIds
+{
+    sal_uInt16 nFont;
+    sal_uInt16 nHeight;
+    sal_uInt16 nWeight;
+    sal_uInt16 nPosture;
+    sal_uInt16 nCJKFont;
+    sal_uInt16 nCJKHeight;
+    sal_uInt16 nCJKWeight;
+    sal_uInt16 nCJKPosture;
+    sal_uInt16 nCTLFont;
+    sal_uInt16 nCTLHeight;
+    sal_uInt16 nCTLWeight;
+    sal_uInt16 nCTLPosture;
+    sal_uInt16 nUnderline;
+    sal_uInt16 nOverline;
+    sal_uInt16 nCrossedOut;
+    sal_uInt16 nContour;
+    sal_uInt16 nShadowed;
+    sal_uInt16 nColor;
+    sal_uInt16 nBox;
+    sal_uInt16 nTLBR;
+    sal_uInt16 nBLTR;
+    sal_uInt16 nBackground;
+    sal_uInt16 nAdjust;
+    sal_uInt16 nHorJustify;
+    sal_uInt16 nVerJustify;
+};
+
 class SVX_DLLPUBLIC AutoFormatBase
 {
 protected:
@@ -84,7 +108,7 @@ protected:
     std::unique_ptr<SvxHorJustifyItem>      m_aHorJustify;
     std::unique_ptr<SvxVerJustifyItem>      m_aVerJustify;
 
-    AutoFormatBase();
+    AutoFormatBase(const AutoFormatWhichIds& rIds);
     AutoFormatBase( const AutoFormatBase& rNew );
     ~AutoFormatBase();
 
diff --git a/sc/source/core/tool/autoform.cxx b/sc/source/core/tool/autoform.cxx
index fa4f9a98a31c..eac1dfb55ada 100644
--- a/sc/source/core/tool/autoform.cxx
+++ b/sc/source/core/tool/autoform.cxx
@@ -46,43 +46,42 @@
 using namespace com::sun::star::beans;
 using namespace com::sun::star;
 
+constexpr AutoFormatWhichIds aScWhichIds = {
+    ATTR_FONT,             // nFont
+    ATTR_FONT_HEIGHT,      // nHeight
+    ATTR_FONT_WEIGHT,      // nWeight
+    ATTR_FONT_POSTURE,     // nPosture
+    ATTR_CJK_FONT,         // nCJKFont
+    ATTR_CJK_FONT_HEIGHT,  // nCJKHeight
+    ATTR_CJK_FONT_WEIGHT,  // nCJKWeight
+    ATTR_CJK_FONT_POSTURE, // nCJKPosture
+    ATTR_CTL_FONT,         // nCTLFont
+    ATTR_CTL_FONT_HEIGHT,  // nCTLHeight
+    ATTR_CTL_FONT_WEIGHT,  // nCTLWeight
+    ATTR_CTL_FONT_POSTURE, // nCTLPosture
+    ATTR_FONT_UNDERLINE,   // nUnderline
+    ATTR_FONT_OVERLINE,    // nOverline
+    ATTR_FONT_CROSSEDOUT,  // nCrossedOut
+    ATTR_FONT_CONTOUR,     // nContour
+    ATTR_FONT_SHADOWED,    // nShadowed
+    ATTR_FONT_COLOR,       // nColor
+    ATTR_BORDER,           // nBox
+    ATTR_BORDER_TLBR,      // nTLBR
+    ATTR_BORDER_BLTR,      // nBLTR
+    ATTR_BACKGROUND,       // nBackground
+    0,                     // nAdjust
+    ATTR_HOR_JUSTIFY,      // nHorJustify
+    ATTR_VER_JUSTIFY,      // nVerJustify
+};
+
 ScAutoFormatDataField::ScAutoFormatDataField()
+    : SvxAutoFormatDataField(aScWhichIds)
+    , m_aStacked(std::make_unique<ScVerticalStackCell>(ATTR_STACKED))
+    , m_aMargin(std::make_unique<SvxMarginItem>(ATTR_MARGIN))
+    , m_aLinebreak(std::make_unique<ScLineBreakCell>(ATTR_LINEBREAK))
+    , m_aRotateAngle(std::make_unique<ScRotateValueItem>(0_deg100))
+    , 
m_aRotateMode(std::make_unique<SvxRotateModeItem>(SVX_ROTATE_MODE_STANDARD, 
ATTR_ROTATE_MODE))
 {
-    // need to set default instances for base class AutoFormatBase here
-    // due to resource defines (e.g. ATTR_FONT) which are not available
-    // in svx and different in the different usages of derivations
-    m_aFont = std::make_unique<SvxFontItem>(ATTR_FONT);
-    m_aHeight = std::make_unique<SvxFontHeightItem>(240, 100, 
ATTR_FONT_HEIGHT);
-    m_aWeight = std::make_unique<SvxWeightItem>(WEIGHT_NORMAL, 
ATTR_FONT_WEIGHT);
-    m_aPosture = std::make_unique<SvxPostureItem>(ITALIC_NONE, 
ATTR_FONT_POSTURE);
-    m_aCJKFont = std::make_unique<SvxFontItem>(ATTR_CJK_FONT);
-    m_aCJKHeight = std::make_unique<SvxFontHeightItem>(240, 100, 
ATTR_CJK_FONT_HEIGHT);
-    m_aCJKWeight = std::make_unique<SvxWeightItem>(WEIGHT_NORMAL, 
ATTR_CJK_FONT_WEIGHT);
-    m_aCJKPosture = std::make_unique<SvxPostureItem>(ITALIC_NONE, 
ATTR_CJK_FONT_POSTURE);
-    m_aCTLFont = std::make_unique<SvxFontItem>(ATTR_CTL_FONT);
-    m_aCTLHeight = std::make_unique<SvxFontHeightItem>(240, 100, 
ATTR_CTL_FONT_HEIGHT);
-    m_aCTLWeight = std::make_unique<SvxWeightItem>(WEIGHT_NORMAL, 
ATTR_CTL_FONT_WEIGHT);
-    m_aCTLPosture = std::make_unique<SvxPostureItem>(ITALIC_NONE, 
ATTR_CTL_FONT_POSTURE);
-    m_aUnderline = std::make_unique<SvxUnderlineItem>(LINESTYLE_NONE, 
ATTR_FONT_UNDERLINE);
-    m_aOverline = std::make_unique<SvxOverlineItem>(LINESTYLE_NONE, 
ATTR_FONT_OVERLINE);
-    m_aCrossedOut = std::make_unique<SvxCrossedOutItem>(STRIKEOUT_NONE, 
ATTR_FONT_CROSSEDOUT);
-    m_aContour = std::make_unique<SvxContourItem>(false, ATTR_FONT_CONTOUR);
-    m_aShadowed = std::make_unique<SvxShadowedItem>(false, ATTR_FONT_SHADOWED);
-    m_aColor = std::make_unique<SvxColorItem>(ATTR_FONT_COLOR);
-    m_aBox = std::make_unique<SvxBoxItem>(ATTR_BORDER);
-    m_aTLBR = std::make_unique<SvxLineItem>(ATTR_BORDER_TLBR);
-    m_aBLTR = std::make_unique<SvxLineItem>(ATTR_BORDER_BLTR);
-    m_aBackground = std::make_unique<SvxBrushItem>(ATTR_BACKGROUND);
-    m_aAdjust = std::make_unique<SvxAdjustItem>(SvxAdjust::Left, 0);
-    m_aHorJustify
-        = std::make_unique<SvxHorJustifyItem>(SvxCellHorJustify::Standard, 
ATTR_HOR_JUSTIFY);
-    m_aVerJustify
-        = std::make_unique<SvxVerJustifyItem>(SvxCellVerJustify::Standard, 
ATTR_VER_JUSTIFY);
-    m_aStacked = std::make_unique<ScVerticalStackCell>(ATTR_STACKED);
-    m_aMargin = std::make_unique<SvxMarginItem>(ATTR_MARGIN);
-    m_aLinebreak = std::make_unique<ScLineBreakCell>(ATTR_LINEBREAK);
-    m_aRotateAngle = std::make_unique<ScRotateValueItem>(0_deg100);
-    m_aRotateMode = 
std::make_unique<SvxRotateModeItem>(SVX_ROTATE_MODE_STANDARD, ATTR_ROTATE_MODE);
 }
 
 ScAutoFormatDataField::ScAutoFormatDataField(const ScAutoFormatDataField& 
rCopy)
diff --git a/svx/source/items/autoformathelper.cxx 
b/svx/source/items/autoformathelper.cxx
index 071e1a87ee0e..50a3ec6b0143 100644
--- a/svx/source/items/autoformathelper.cxx
+++ b/svx/source/items/autoformathelper.cxx
@@ -68,7 +68,32 @@ void AutoFormatBase::SetAdjust( const SvxAdjustItem& rNew )  
       { m_aAdjust.
 void AutoFormatBase::SetHorJustify( const SvxHorJustifyItem& rNew ) { 
m_aHorJustify.reset(rNew.Clone()); }
 void AutoFormatBase::SetVerJustify( const SvxVerJustifyItem& rNew ) { 
m_aVerJustify.reset(rNew.Clone()); }
 
-AutoFormatBase::AutoFormatBase()
+AutoFormatBase::AutoFormatBase(const AutoFormatWhichIds& rIds)
+    : m_aFont(std::make_unique<SvxFontItem>(rIds.nFont))
+    , m_aHeight(std::make_unique<SvxFontHeightItem>(240, 100, rIds.nHeight))
+    , m_aWeight(std::make_unique<SvxWeightItem>(WEIGHT_NORMAL, rIds.nWeight))
+    , m_aPosture(std::make_unique<SvxPostureItem>(ITALIC_NONE, rIds.nPosture))
+    , m_aCJKFont(std::make_unique<SvxFontItem>(rIds.nCJKFont))
+    , m_aCJKHeight(std::make_unique<SvxFontHeightItem>(240, 100, 
rIds.nCJKHeight))
+    , m_aCJKWeight(std::make_unique<SvxWeightItem>(WEIGHT_NORMAL, 
rIds.nCJKWeight))
+    , m_aCJKPosture(std::make_unique<SvxPostureItem>(ITALIC_NONE, 
rIds.nCJKPosture))
+    , m_aCTLFont(std::make_unique<SvxFontItem>(rIds.nCTLFont))
+    , m_aCTLHeight(std::make_unique<SvxFontHeightItem>(240, 100, 
rIds.nCTLHeight))
+    , m_aCTLWeight(std::make_unique<SvxWeightItem>(WEIGHT_NORMAL, 
rIds.nCTLWeight))
+    , m_aCTLPosture(std::make_unique<SvxPostureItem>(ITALIC_NONE, 
rIds.nCTLPosture))
+    , m_aUnderline(std::make_unique<SvxUnderlineItem>(LINESTYLE_NONE, 
rIds.nUnderline))
+    , m_aOverline(std::make_unique<SvxOverlineItem>(LINESTYLE_NONE, 
rIds.nOverline))
+    , m_aCrossedOut(std::make_unique<SvxCrossedOutItem>(STRIKEOUT_NONE, 
rIds.nCrossedOut))
+    , m_aContour(std::make_unique<SvxContourItem>(false, rIds.nContour))
+    , m_aShadowed(std::make_unique<SvxShadowedItem>(false, rIds.nShadowed))
+    , m_aColor(std::make_unique<SvxColorItem>(rIds.nColor))
+    , m_aBox(std::make_unique<SvxBoxItem>(rIds.nBox))
+    , m_aTLBR(std::make_unique<SvxLineItem>(rIds.nTLBR))
+    , m_aBLTR(std::make_unique<SvxLineItem>(rIds.nBLTR))
+    , m_aBackground(std::make_unique<SvxBrushItem>(rIds.nBackground))
+    , m_aAdjust(std::make_unique<SvxAdjustItem>(SvxAdjust::Left, rIds.nAdjust))
+    , 
m_aHorJustify(std::make_unique<SvxHorJustifyItem>(SvxCellHorJustify::Standard, 
rIds.nHorJustify))
+    , 
m_aVerJustify(std::make_unique<SvxVerJustifyItem>(SvxCellVerJustify::Standard, 
rIds.nVerJustify))
 {
 }
 
diff --git a/svx/source/table/tableautofmt.cxx 
b/svx/source/table/tableautofmt.cxx
index 6c87827372ec..3e9903fc062d 100644
--- a/svx/source/table/tableautofmt.cxx
+++ b/svx/source/table/tableautofmt.cxx
@@ -146,6 +146,11 @@ const SfxItemPropertySet& 
SvxAutoFormat::GetTablePropertySet()
     return aSvxTablePropertySet;
 }
 
+SvxAutoFormatDataField::SvxAutoFormatDataField(const AutoFormatWhichIds& rIds)
+    : AutoFormatBase(rIds)
+{
+}
+
 SvxAutoFormatDataField::SvxAutoFormatDataField(const SvxAutoFormatDataField& 
rCopy)
     : AutoFormatBase(rCopy)
     , mSetProperties(rCopy.mSetProperties)
diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index fbeef32d0b30..e6d65ab7c8ed 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -61,40 +61,45 @@
 
 SwBoxAutoFormat* SwTableAutoFormat::s_pDefaultBoxAutoFormat = nullptr;
 
+constexpr AutoFormatWhichIds aSwWhichIds = {
+    RES_CHRATR_FONT,         // nFont
+    RES_CHRATR_FONTSIZE,     // nHeight
+    RES_CHRATR_WEIGHT,       // nWeight
+    RES_CHRATR_POSTURE,      // nPosture
+    RES_CHRATR_CJK_FONT,     // nCJKFont
+    RES_CHRATR_CJK_FONTSIZE, // nCJKHeight
+    RES_CHRATR_CJK_WEIGHT,   // nCJKWeight
+    RES_CHRATR_CJK_POSTURE,  // nCJKPosture
+    RES_CHRATR_CTL_FONT,     // nCTLFont
+    RES_CHRATR_CTL_FONTSIZE, // nCTLHeight
+    RES_CHRATR_CTL_WEIGHT,   // nCTLWeight
+    RES_CHRATR_CTL_POSTURE,  // nCTLPosture
+    RES_CHRATR_UNDERLINE,    // nUnderline
+    RES_CHRATR_OVERLINE,     // nOverline
+    RES_CHRATR_CROSSEDOUT,   // nCrossedOut
+    RES_CHRATR_CONTOUR,      // nContour
+    RES_CHRATR_SHADOWED,     // nShadowed
+    RES_CHRATR_COLOR,        // nColor
+    RES_BOX,                 // nBox
+    0,                       // nTLBR
+    0,                       // nBLTR
+    RES_BACKGROUND,          // nBackground
+    RES_PARATR_ADJUST,       // nAdjust
+    0,                       // nHorJustify
+    0,                       // nVerJustify
+};
+
 SwBoxAutoFormat::SwBoxAutoFormat()
+    : SvxAutoFormatDataField(aSwWhichIds)
+    , m_aTextOrientation(
+          
std::make_unique<SvxFrameDirectionItem>(SvxFrameDirection::Environment, 
RES_FRAMEDIR))
+    , m_aVerticalAlignment(std::make_unique<SwFormatVertOrient>(0, 
text::VertOrientation::TOP,
+                                                                
text::RelOrientation::FRAME))
 {
-    // need to set default instances for base class AutoFormatBase here
-    // due to resource defines (e.g. RES_CHRATR_FONT) which are not available
-    // in svx and different in the different usages of derivations
-    m_aFont = std::make_unique<SvxFontItem>(*GetDfltAttr(RES_CHRATR_FONT));
-    m_aHeight = std::make_unique<SvxFontHeightItem>(240, 100, 
RES_CHRATR_FONTSIZE);
-    m_aWeight = std::make_unique<SvxWeightItem>(WEIGHT_NORMAL, 
RES_CHRATR_WEIGHT);
-    m_aPosture = std::make_unique<SvxPostureItem>(ITALIC_NONE, 
RES_CHRATR_POSTURE);
-    m_aCJKFont = 
std::make_unique<SvxFontItem>(*GetDfltAttr(RES_CHRATR_CJK_FONT));
-    m_aCJKHeight = std::make_unique<SvxFontHeightItem>(240, 100, 
RES_CHRATR_CJK_FONTSIZE);
-    m_aCJKWeight = std::make_unique<SvxWeightItem>(WEIGHT_NORMAL, 
RES_CHRATR_CJK_WEIGHT);
-    m_aCJKPosture = std::make_unique<SvxPostureItem>(ITALIC_NONE, 
RES_CHRATR_CJK_POSTURE);
-    m_aCTLFont = 
std::make_unique<SvxFontItem>(*GetDfltAttr(RES_CHRATR_CTL_FONT));
-    m_aCTLHeight = std::make_unique<SvxFontHeightItem>(240, 100, 
RES_CHRATR_CTL_FONTSIZE);
-    m_aCTLWeight = std::make_unique<SvxWeightItem>(WEIGHT_NORMAL, 
RES_CHRATR_CTL_WEIGHT);
-    m_aCTLPosture = std::make_unique<SvxPostureItem>(ITALIC_NONE, 
RES_CHRATR_CTL_POSTURE);
-    m_aUnderline = std::make_unique<SvxUnderlineItem>(LINESTYLE_NONE, 
RES_CHRATR_UNDERLINE);
-    m_aOverline = std::make_unique<SvxOverlineItem>(LINESTYLE_NONE, 
RES_CHRATR_OVERLINE);
-    m_aCrossedOut = std::make_unique<SvxCrossedOutItem>(STRIKEOUT_NONE, 
RES_CHRATR_CROSSEDOUT);
-    m_aContour = std::make_unique<SvxContourItem>(false, RES_CHRATR_CONTOUR);
-    m_aShadowed = std::make_unique<SvxShadowedItem>(false, 
RES_CHRATR_SHADOWED);
-    m_aColor = std::make_unique<SvxColorItem>(COL_AUTO, RES_CHRATR_COLOR);
-    m_aBox = std::make_unique<SvxBoxItem>(RES_BOX);
-    m_aTLBR = std::make_unique<SvxLineItem>(0);
-    m_aBLTR = std::make_unique<SvxLineItem>(0);
-    m_aBackground = std::make_unique<SvxBrushItem>(RES_BACKGROUND);
-    m_aAdjust = std::make_unique<SvxAdjustItem>(SvxAdjust::Left, 
RES_PARATR_ADJUST);
-    m_aHorJustify = 
std::make_unique<SvxHorJustifyItem>(SvxCellHorJustify::Standard, 0);
-    m_aVerJustify = 
std::make_unique<SvxVerJustifyItem>(SvxCellVerJustify::Standard, 0);
-    m_aTextOrientation
-        = 
std::make_unique<SvxFrameDirectionItem>(SvxFrameDirection::Environment, 
RES_FRAMEDIR);
-    m_aVerticalAlignment = std::make_unique<SwFormatVertOrient>(0, 
text::VertOrientation::TOP,
-                                                                
text::RelOrientation::FRAME);
+    SetFont(*GetDfltAttr(RES_CHRATR_FONT));
+    SetCJKFont(*GetDfltAttr(RES_CHRATR_CJK_FONT));
+    SetCTLFont(*GetDfltAttr(RES_CHRATR_CTL_FONT));
+    SetColor(SvxColorItem(COL_AUTO, RES_CHRATR_COLOR));
     m_aVerticalAlignment->SetWhich(RES_VERT_ORIENT);
     SetSysLanguage(::GetAppLanguage());
     SetNumFormatLanguage(::GetAppLanguage());

Reply via email to