From 5bfda7f1f00b8f922fe3a2b085a845e6b1758026 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 14 Apr 2021 09:54:29 +0200 Subject: [PATCH] spice netlist generation: use utf8 format. Using basic conversion from unicode to 8bits strings can break non ASCII7 strings Fixes #8192 https://gitlab.com/kicad/code/kicad/issues/8192 --- .../netlist_exporter_pspice.cpp | 12 ++++++------ eeschema/sim/netlist_exporter_pspice_sim.cpp | 16 +++++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/eeschema/netlist_exporters/netlist_exporter_pspice.cpp b/eeschema/netlist_exporters/netlist_exporter_pspice.cpp index 094264c2ae..15b44b2eb3 100644 --- a/eeschema/netlist_exporters/netlist_exporter_pspice.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_pspice.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 1992-2013 jp.charras at wanadoo.fr * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -87,7 +87,7 @@ bool NETLIST_EXPORTER_PSPICE::Format( OUTPUTFORMATTER* aFormatter, unsigned aCtl if( !ProcessNetlist( aCtl ) ) return false; - aFormatter->Print( 0, ".title %s\n", (const char*) m_title.c_str() ); + aFormatter->Print( 0, ".title %s\n", TO_UTF8( m_title ) ); // Write .include directives for( const auto& lib : m_libraries ) @@ -108,7 +108,7 @@ bool NETLIST_EXPORTER_PSPICE::Format( OUTPUTFORMATTER* aFormatter, unsigned aCtl else full_path = lib; // just use the unaltered path - aFormatter->Print( 0, ".include \"%s\"\n", (const char*) full_path.c_str() ); + aFormatter->Print( 0, ".include \"%s\"\n", TO_UTF8( full_path ) ); } unsigned int NC_counter = 1; @@ -119,7 +119,7 @@ bool NETLIST_EXPORTER_PSPICE::Format( OUTPUTFORMATTER* aFormatter, unsigned aCtl continue; wxString device = GetSpiceDevice( item.m_refName ); - aFormatter->Print( 0, "%s ", (const char*) device.c_str() ); + aFormatter->Print( 0, "%s ", TO_UTF8( device ) ); size_t pspiceNodes = item.m_pinSequence.empty() ? item.m_pins.size() : item.m_pinSequence.size(); @@ -159,7 +159,7 @@ bool NETLIST_EXPORTER_PSPICE::Format( OUTPUTFORMATTER* aFormatter, unsigned aCtl } } - aFormatter->Print( 0, "%s\n", (const char*) item.m_model.c_str() ); + aFormatter->Print( 0, "%s\n", TO_UTF8( item.m_model ) ); } // Print out all directives found in the text fields on the schematics @@ -464,7 +464,7 @@ void NETLIST_EXPORTER_PSPICE::writeDirectives( OUTPUTFORMATTER* aFormatter, unsi { for( auto& dir : m_directives ) { - aFormatter->Print( 0, "%s\n", (const char*) dir.c_str() ); + aFormatter->Print( 0, "%s\n", TO_UTF8( dir ) ); } } diff --git a/eeschema/sim/netlist_exporter_pspice_sim.cpp b/eeschema/sim/netlist_exporter_pspice_sim.cpp index 8cb35167a0..3ebb73dc11 100644 --- a/eeschema/sim/netlist_exporter_pspice_sim.cpp +++ b/eeschema/sim/netlist_exporter_pspice_sim.cpp @@ -4,6 +4,8 @@ * Copyright (C) 2016 CERN * @author Maciej Suminski * + * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.TXT for contributors. + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 3 @@ -24,6 +26,7 @@ #include "netlist_exporter_pspice_sim.h" #include +#include // for TO_UTF8 def #include #include @@ -33,8 +36,8 @@ wxString NETLIST_EXPORTER_PSPICE_SIM::ComponentToVector( wxString res; // Some of the flags should exclude mutually - assert( ( ( aType & SPT_VOLTAGE ) == 0 ) != ( ( aType & SPT_CURRENT ) == 0 ) ); - assert( ( ( aType & SPT_AC_PHASE ) == 0 ) || ( ( aType & SPT_AC_MAG ) == 0 ) ); + wxASSERT( ( ( aType & SPT_VOLTAGE ) == 0 ) != ( ( aType & SPT_CURRENT ) == 0 ) ); + wxASSERT( ( ( aType & SPT_AC_PHASE ) == 0 ) || ( ( aType & SPT_AC_MAG ) == 0 ) ); if( aType & SPT_VOLTAGE ) { @@ -237,8 +240,7 @@ void NETLIST_EXPORTER_PSPICE_SIM::writeDirectives( OUTPUTFORMATTER* aFormatter, /// @todo is it required to switch to lowercase aFormatter->Print( 0, ".save %s\n", - (const char*) ComponentToVector( item.m_refName, SPT_CURRENT, current ) - .c_str() ); + TO_UTF8( ComponentToVector( item.m_refName, SPT_CURRENT, current ) ) ); } } @@ -252,7 +254,7 @@ void NETLIST_EXPORTER_PSPICE_SIM::writeDirectives( OUTPUTFORMATTER* aFormatter, if( netname == "V(0)" || netname == "V(GND)" ) continue; - aFormatter->Print( 0, ".save %s\n", (const char*) netname.c_str() ); + aFormatter->Print( 0, ".save %s\n", TO_UTF8( netname ) ); } if( m_simCommand.IsEmpty() ) @@ -266,10 +268,10 @@ void NETLIST_EXPORTER_PSPICE_SIM::writeDirectives( OUTPUTFORMATTER* aFormatter, for( const auto& dir : GetDirectives() ) { if( !IsSimCommand( dir ) ) - aFormatter->Print( 0, "%s\n", (const char*) dir.c_str() ); + aFormatter->Print( 0, "%s\n", TO_UTF8( dir ) ); } // Finish with our custom simulation command - aFormatter->Print( 0, "%s\n", (const char*) m_simCommand.c_str() ); + aFormatter->Print( 0, "%s\n", TO_UTF8( m_simCommand ) ); } }