From f0a52644ea038f06f1a50e91f9e0166e4c9c057e Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 23 Jan 2015 12:24:32 +0100 Subject: [PATCH] Pcbnew: fix Bug #1413701 (Segfault on highlight "unconnected" net 0 in Pcbnew ). Also, remove now useless code and other very minor fixes. --- 3d-viewer/vrml_v2_modelparser.cpp | 4 +--- bitmap2component/bitmap2component.cpp | 5 ++--- common/grid_tricks.cpp | 2 +- gerbview/gerbview_frame.cpp | 5 ----- pcbnew/basepcbframe.cpp | 5 ----- pcbnew/class_board.cpp | 6 ++++-- pcbnew/class_netinfo_item.cpp | 18 ++++++++++-------- pcbnew/pcbframe.cpp | 5 ----- pcbnew/specctra_test.cpp | 4 +--- 9 files changed, 19 insertions(+), 35 deletions(-) diff --git a/3d-viewer/vrml_v2_modelparser.cpp b/3d-viewer/vrml_v2_modelparser.cpp index f1eb4772ef..7748f9a134 100644 --- a/3d-viewer/vrml_v2_modelparser.cpp +++ b/3d-viewer/vrml_v2_modelparser.cpp @@ -88,8 +88,7 @@ void VRML2_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3 glScalef( matScale.x, matScale.y, matScale.z ); - // Switch the locale to standard C (needed to print floating point numbers like 1.3) - SetLocaleTo_C_standard(); + LOCALE_IO toggle; // Temporary switch the locale to standard C to r/w floats childs.clear(); @@ -117,7 +116,6 @@ void VRML2_MODEL_PARSER::Load( const wxString& aFilename, double aVrmlunits_to_3 } fclose( m_file ); - SetLocaleTo_Default(); // revert to the current locale // DBG( printf( "chils size:%lu\n", childs.size() ) ); diff --git a/bitmap2component/bitmap2component.cpp b/bitmap2component/bitmap2component.cpp index a8799aceef..db115853ab 100644 --- a/bitmap2component/bitmap2component.cpp +++ b/bitmap2component/bitmap2component.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -437,7 +438,7 @@ void BITMAPCONV_INFO::CreateOutputFile( BMP2CMP_MOD_LAYER aModLayer ) potrace_dpoint_t( *c )[3]; - setlocale( LC_NUMERIC, "C" ); // Switch the locale to standard C + LOCALE_IO toggle; // Temporary switch the locale to standard C to r/w floats // The layer name has meaning only for .kicad_mod files. // For these files the header creates 2 invisible texts: value and ref @@ -530,8 +531,6 @@ void BITMAPCONV_INFO::CreateOutputFile( BMP2CMP_MOD_LAYER aModLayer ) } OuputFileEnd(); - - setlocale( LC_NUMERIC, "" ); // revert to the current locale } diff --git a/common/grid_tricks.cpp b/common/grid_tricks.cpp index 83f412e05c..40801671e0 100644 --- a/common/grid_tricks.cpp +++ b/common/grid_tricks.cpp @@ -65,7 +65,7 @@ void GRID_TRICKS::getSelectedArea() wxArrayInt cols = m_grid->GetSelectedCols(); wxArrayInt rows = m_grid->GetSelectedRows(); - DBG(printf("topLeft.Count():%zd botRight:Count():%zd\n", topLeft.Count(), botRight.Count() );) + DBG(printf("topLeft.Count():%d botRight:Count():%d\n", int( topLeft.Count() ), int( botRight.Count() ) );) if( topLeft.Count() && botRight.Count() ) { diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index a391fe714e..29b61c6ca8 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -269,11 +269,6 @@ void GERBVIEW_FRAME::LoadSettings( wxConfigBase* aCfg ) aCfg->SetPath( wxT( "drl_files" ) ); m_drillFileHistory.Load( *aCfg ); aCfg->SetPath( wxT( ".." ) ); - - // WxWidgets 2.9.1 seems call setlocale( LC_NUMERIC, "" ) - // when reading doubles in config, - // but forget to back to current locale. So we call SetLocaleTo_Default - SetLocaleTo_Default(); } diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 6c18bef2d2..c52463846b 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -767,11 +767,6 @@ void PCB_BASE_FRAME::LoadSettings( wxConfigBase* aCfg ) if( m_DisplayOptions.m_DisplayModText < LINE || m_DisplayOptions.m_DisplayModText > SKETCH ) m_DisplayOptions.m_DisplayModText = FILLED; - - // WxWidgets 2.9.1 seems call setlocale( LC_NUMERIC, "" ) - // when reading doubles in config, - // but forget to back to current locale. So we call SetLocaleTo_Default - SetLocaleTo_Default( ); } diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index d6ec4d4197..2f93772d39 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -1212,10 +1212,12 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR* inspector, const void* testData, NETINFO_ITEM* BOARD::FindNet( int aNetcode ) const { // the first valid netcode is 1 and the last is m_NetInfo.GetCount()-1. - // zero is reserved for "no connection" and is not used. + // zero is reserved for "no connection" and is not actually a net. // NULL is returned for non valid netcodes - if( aNetcode == NETINFO_LIST::UNCONNECTED ) + wxASSERT( m_NetInfo.GetNetCount() > 0 ); // net zero should exist + + if( aNetcode == NETINFO_LIST::UNCONNECTED && m_NetInfo.GetNetCount() == 0 ) return &NETINFO_LIST::ORPHANED; else return m_NetInfo.GetNetItem( aNetcode ); diff --git a/pcbnew/class_netinfo_item.cpp b/pcbnew/class_netinfo_item.cpp index 627fe0451e..1f1f2672e3 100644 --- a/pcbnew/class_netinfo_item.cpp +++ b/pcbnew/class_netinfo_item.cpp @@ -80,10 +80,7 @@ void NETINFO_ITEM::Draw( EDA_DRAW_PANEL* panel, void NETINFO_ITEM::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) { - int count; wxString txt; - MODULE* module; - D_PAD* pad; double lengthnet = 0.0; // This is the lenght of tracks on pcb double lengthPadToDie = 0.0; // this is the lenght of internal ICs connections @@ -92,12 +89,17 @@ void NETINFO_ITEM::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) txt.Printf( wxT( "%d" ), GetNet() ); aList.push_back( MSG_PANEL_ITEM( _( "Net Code" ), txt, RED ) ); - count = 0; - module = m_parent->GetBoard()->m_Modules; + // Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board + // can be NULL + BOARD * board = m_parent ? m_parent->GetBoard() : NULL; - for( ; module != 0; module = module->Next() ) + if( board == NULL ) + return; + + int count = 0; + for( MODULE* module = board->m_Modules; module != NULL; module = module->Next() ) { - for( pad = module->Pads(); pad != 0; pad = pad->Next() ) + for( D_PAD* pad = module->Pads(); pad != 0; pad = pad->Next() ) { if( pad->GetNetCode() == GetNet() ) { @@ -112,7 +114,7 @@ void NETINFO_ITEM::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) count = 0; - for( const TRACK *track = m_parent->GetBoard()->m_Track; track != NULL; track = track->Next() ) + for( const TRACK *track = board->m_Track; track != NULL; track = track->Next() ) { if( track->Type() == PCB_VIA_T ) { diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 1acb59a136..0438e84b34 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -754,11 +754,6 @@ void PCB_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg ) aCfg->Read( PCB_MAGNETIC_TRACKS_OPT, &g_MagneticTrackOption ); aCfg->Read( SHOW_MICROWAVE_TOOLS, &m_show_microwave_tools ); aCfg->Read( SHOW_LAYER_MANAGER_TOOLS, &m_show_layer_manager_tools ); - - // WxWidgets 2.9.1 seems call setlocale( LC_NUMERIC, "" ) - // when reading doubles in cfg, - // but forget to back to current locale. So we call SetLocaleTo_Default - SetLocaleTo_Default( ); } diff --git a/pcbnew/specctra_test.cpp b/pcbnew/specctra_test.cpp index ab11895393..3a6cc0b47a 100644 --- a/pcbnew/specctra_test.cpp +++ b/pcbnew/specctra_test.cpp @@ -51,7 +51,7 @@ int main( int argc, char** argv ) SPECCTRA_DB db; bool failed = false; - SetLocaleTo_C_standard( ); // Switch the locale to standard C + LOCALE_IO toggle; // Temporary switch the locale to standard C to r/w floats if( argc == 2 ) { @@ -87,8 +87,6 @@ int main( int argc, char** argv ) DSN::SESSION* ses = db.GetSESSION(); ses->Format( &db, 0 ); #endif - - SetLocaleTo_Default( ); // revert to the current locale } //--------------------------------------------------------