From 948a61711d5760b2752210f0aaeb000c79ba5de7 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Tue, 2 Apr 2019 19:53:06 -0400 Subject: [PATCH] Add thread-safety to SCH_FIELD::IsVoid() Fixes: lp:1822678 * https://bugs.launchpad.net/kicad/+bug/1822678 --- eeschema/sch_field.cpp | 12 ++++++++++++ eeschema/sch_field.h | 9 +++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 0c4ee8352f..852925c5e2 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -312,6 +312,18 @@ bool SCH_FIELD::IsHorizJustifyFlipped() const } +bool SCH_FIELD::IsVoid() const +{ + // When in UTF-8 mode, wxString puts string iterators in a linked list, and + // that linked list is not thread-safe. + std::lock_guard guard( m_mutex ); + + size_t len = m_Text.Len(); + + return len == 0 || ( len == 1 && m_Text[0] == wxChar( '~' ) ); +} + + void SCH_FIELD::Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { frame->GetCanvas()->SetMouseCapture( NULL, NULL ); diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index dcccc910e6..8adf7526ff 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -59,6 +59,8 @@ class SCH_FIELD : public SCH_ITEM, public EDA_TEXT wxString m_name; + mutable UNIQUE_MUTEX m_mutex; + public: SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_COMPONENT* aParent, const wxString& aName = wxEmptyString ); @@ -113,12 +115,7 @@ public: * Function IsVoid * returns true if the field is either empty or holds "~". */ - bool IsVoid() const - { - size_t len = m_Text.Len(); - - return len == 0 || ( len == 1 && m_Text[0] == wxChar( '~' ) ); - } + bool IsVoid() const; void SwapData( SCH_ITEM* aItem ) override;