From c686105afca6d2ce9682d8cc3c359e673abc7dfb Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 24 Mar 2022 09:22:11 -0700 Subject: [PATCH] Correctly order swap test MapAngles() will modify parameters and C++ does not guarantee LTR evaluation, so we need to separate the calls into the proper order before comparing the returns Fixes https://gitlab.com/kicad/code/kicad/issues/11135 --- eeschema/lib_shape.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/eeschema/lib_shape.cpp b/eeschema/lib_shape.cpp index 56353b0466..0020df10aa 100644 --- a/eeschema/lib_shape.cpp +++ b/eeschema/lib_shape.cpp @@ -142,7 +142,12 @@ void LIB_SHAPE::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs CalcArcAngles( t1, t2 ); - if( aTransform.MapAngles( &t1, &t2 ) != ( ( t1 - t2 ).Normalize180() > ANGLE_0 ) ) + // N.B. The order of evaluation is critical here as MapAngles will modify t1, t2 + // and the Normalize routine depends on these modifications for the correct output + bool transformed = aTransform.MapAngles( &t1, &t2 ); + bool transformed2 = ( ( t1 - t2 ).Normalize180() > ANGLE_0 ); + + if( transformed != transformed2 ) std::swap( start, end ); }