From 4e7fcb3b677d67c096cf0af7b9c94a5c31a33825 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 18 Sep 2024 18:36:17 -0400 Subject: [PATCH] Temporary patches around LSET and negative layers Probably this should be replaced with a less error-prone approach. Right now the LSET -> BASE_SET system is risky because it is converting a signed enum (PCB_LAYER_ID) to a size_t in all the underlying operations. Fixes https://gitlab.com/kicad/code/kicad/-/issues/18738 --- common/lset.cpp | 17 +++++++++++++---- include/lset.h | 4 ++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/common/lset.cpp b/common/lset.cpp index ec82da8523..a6d0e937ae 100644 --- a/common/lset.cpp +++ b/common/lset.cpp @@ -45,7 +45,10 @@ LSET::LSET( std::initializer_list aList ) : LSET() { for( PCB_LAYER_ID layer : aList ) - set( layer ); + { + if( layer > 0 ) + set( layer ); + } } @@ -53,14 +56,20 @@ LSET::LSET( const LSEQ& aSeq ) : LSET() { for( PCB_LAYER_ID layer : aSeq ) - set( layer ); + { + if( layer > 0 ) + set( layer ); + } } LSET::LSET( const LAYER_RANGE& aRange ) { for( PCB_LAYER_ID layer : aRange ) - set( layer ); + { + if( layer > 0 ) + set( layer ); + } } @@ -966,4 +975,4 @@ LSET::non_copper_layers_iterator LSET::non_copper_layers_end() const } -#endif \ No newline at end of file +#endif diff --git a/include/lset.h b/include/lset.h index cc62b1a338..02f348e71b 100644 --- a/include/lset.h +++ b/include/lset.h @@ -59,6 +59,10 @@ public: */ bool Contains( PCB_LAYER_ID aLayer ) { + // At the moment, LSET cannot store negative layers, but PCB_LAYER_ID can contain them + if( aLayer < 0 ) + return false; + try { return test( aLayer );