Don't blindly deref an optional

Since the optional might not have a value (and the wxVariant seems to
equate 0 with an empty string), we should check for the valid optional
first and fallback to 0 if not set

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21081
This commit is contained in:
Seth Hillbrand 2025-06-06 13:51:17 -07:00
parent 10413f778c
commit a5896e231a

View File

@ -164,7 +164,19 @@ public:
* @return the zone's clearance in internal units.
*/
std::optional<int> GetLocalClearance() const override;
void SetLocalClearance( std::optional<int> aClearance ) { m_ZoneClearance = aClearance.value(); }
/**
* Set the local clearance for this zone.
*
* @param aClearance is the clearance in internal units, or std::nullopt to clear it.
*/
void SetLocalClearance( std::optional<int> aClearance )
{
if( aClearance )
m_ZoneClearance = aClearance.value();
else
m_ZoneClearance = 0;
}
/**
* Return any local clearances set in the "classic" (ie: pre-rule) system.