diff --git a/include/fctsys.h b/include/fctsys.h index f1cb2b6b58..148340bf45 100644 --- a/include/fctsys.h +++ b/include/fctsys.h @@ -1,8 +1,8 @@ /********************/ /* System includes. */ /********************/ -#ifndef FCTSYS_H -#define FCTSYS_H +#ifndef FCTSYS_H_ +#define FCTSYS_H_ // For compilers that support precompilation, includes "wx.h". #include @@ -46,6 +46,25 @@ #define D(x) // nothing #endif +/** + * Function Clamp + * limits @a value within the range @a lower <= @a value <= @a upper. It will work + * on temporary expressions, since they are evaluated only once, and it should work + * on most if not all numeric types. The arguments are accepted in this order so you + * can remember the expression as a memory aid: + *

+ * result is: lower <= value <= upper + */ +template inline const T& Clamp( const T& lower, const T& value, const T& upper ) +{ + wxASSERT( lower <= upper ); + if( value < lower ) + return lower; + else if( value > upper ) + return upper; + return value; +} + #define UNIX_STRING_DIR_SEP wxT( "/" ) #define WIN_STRING_DIR_SEP wxT( "\\" ) @@ -64,4 +83,4 @@ #include -#endif /* FCTSYS_H */ +#endif // FCTSYS_H__ diff --git a/kicad/files-io.cpp b/kicad/files-io.cpp index 75b61f4a20..9aec929a5d 100644 --- a/kicad/files-io.cpp +++ b/kicad/files-io.cpp @@ -171,7 +171,7 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event ) infile->GetStream()->GetSize(), zippedsize ); PrintMsg( msg ); delete infile; - } + } else { PrintMsg( _(" >>Error\n") ); diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp index 7333af9d12..b4cfcf6d73 100644 --- a/pcbnew/dialogs/dialog_pad_properties.cpp +++ b/pcbnew/dialogs/dialog_pad_properties.cpp @@ -438,7 +438,7 @@ void DIALOG_PAD_PROPERTIES::initValues() // Type of pad selection m_PadType->SetSelection( 0 ); - for( int ii = 0; ii < NBTYPES; ii++ ) + for( unsigned ii = 0; ii < NBTYPES; ii++ ) { if( CodeType[ii] == m_dummyPad->GetAttribute() ) { @@ -573,11 +573,10 @@ void DIALOG_PAD_PROPERTIES::PadOrientEvent( wxCommandEvent& event ) void DIALOG_PAD_PROPERTIES::PadTypeSelected( wxCommandEvent& event ) { - long layer_mask; - int ii; + long layer_mask; + unsigned ii = m_PadType->GetSelection(); - ii = m_PadType->GetSelection(); - if( ii < 0 || ii >= NBTYPES ) + if( ii >= NBTYPES ) // catches < 0 also ii = 0; layer_mask = Std_Pad_Layers[ii]; @@ -603,11 +602,11 @@ void DIALOG_PAD_PROPERTIES::PadTypeSelected( wxCommandEvent& event ) void DIALOG_PAD_PROPERTIES::SetPadLayersList( long layer_mask ) { - if( ( layer_mask & ALL_CU_LAYERS ) == LAYER_FRONT ) + if( ( layer_mask & ALL_CU_LAYERS ) == LAYER_FRONT ) m_rbCopperLayersSel->SetSelection(0); else if( ( layer_mask & ALL_CU_LAYERS ) == LAYER_BACK) m_rbCopperLayersSel->SetSelection(1); - else if( ( layer_mask & ALL_CU_LAYERS ) != 0 ) + else if( ( layer_mask & ALL_CU_LAYERS ) != 0 ) m_rbCopperLayersSel->SetSelection(2); else m_rbCopperLayersSel->SetSelection(3);