sd/source/ui/app/optsitem.cxx |   25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

New commits:
commit 73b5a1e2af84a56304086f3a48298d11c75b35cf
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Fri Aug 15 11:13:10 2025 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri Aug 15 13:49:24 2025 +0200

    cid#1660019 silence Division or modulo by zero
    
    and
    
    cid#1659794 Division or modulo by zero
    
    Change-Id: I7e8289992e071994389caf8077b6c6e1d3ce5c1d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189673
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sd/source/ui/app/optsitem.cxx b/sd/source/ui/app/optsitem.cxx
index 894b41d5dc29..429227253bac 100644
--- a/sd/source/ui/app/optsitem.cxx
+++ b/sd/source/ui/app/optsitem.cxx
@@ -566,22 +566,27 @@ void SdOptionsGrid::GetPropNameArray( const char* const*& 
ppNames, sal_uLong& rC
     }
 }
 
+static sal_uInt32 getDivisor(const Any& rValue)
+{
+    if (rValue.hasValue())
+    {
+        sal_uInt32 nDiv = 
basegfx::fround<sal_uInt32>(*o3tl::doAccess<double>(rValue));
+        return nDiv + 1;
+    }
+    return 0;
+}
+
 bool SdOptionsGrid::ReadData( const Any* pValues )
 {
     if( pValues[0].hasValue() ) SetFieldDrawX( 
*o3tl::doAccess<sal_Int32>(pValues[ 0 ]) );
     if( pValues[1].hasValue() ) SetFieldDrawY( 
*o3tl::doAccess<sal_Int32>(pValues[ 1 ]) );
 
-    if( pValues[2].hasValue() )
-    {
-        const sal_uInt32 nDivX = 
basegfx::fround<sal_uInt32>(*o3tl::doAccess<double>(pValues[2]));
-        SetFieldDivisionX( SvxOptionsGrid::GetFieldDrawX() / ( nDivX + 1 ) );
-    }
+    if (const sal_uInt32 nDivX = getDivisor(pValues[2]))
+        SetFieldDivisionX(SvxOptionsGrid::GetFieldDrawX() / nDivX);
+
+    if (const sal_uInt32 nDivY = getDivisor(pValues[3]))
+        SetFieldDivisionY(SvxOptionsGrid::GetFieldDrawY() / nDivY);
 
-    if( pValues[3].hasValue() )
-    {
-        const sal_uInt32 nDivY = 
basegfx::fround<sal_uInt32>(*o3tl::doAccess<double>(pValues[3]));
-        SetFieldDivisionY( SvxOptionsGrid::GetFieldDrawY() / ( nDivY + 1 ) );
-    }
     if( pValues[4].hasValue() ) SetUseGridSnap( *o3tl::doAccess<bool>(pValues[ 
4 ]) );
     if( pValues[5].hasValue() ) SetSynchronize( *o3tl::doAccess<bool>(pValues[ 
5 ]) );
     if( pValues[6].hasValue() ) SetGridVisible( *o3tl::doAccess<bool>(pValues[ 
6 ]) );

Reply via email to