From 1f44d29a0fc71e8f34aa8d221d34883624c1e26a Mon Sep 17 00:00:00 2001 From: abv Date: Wed, 18 Sep 2019 03:48:35 +0300 Subject: [PATCH] 0030978: Visualization - stack-use-after-scope reported by Clang address sanitizer in OpenGl_Text.cxx Implementation of auxiliary class in OpenGl_Text.cxx is corrected to avoid storing reference to temporary object. Off-topic: test parse rules are corrected to recognize situation when test is killed by elapsed time, and report it as such. --- src/OpenGl/OpenGl_Text.cxx | 20 ++++++++++---------- tests/parse.rules | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/OpenGl/OpenGl_Text.cxx b/src/OpenGl/OpenGl_Text.cxx index e1d5ea8207..2f88a720da 100644 --- a/src/OpenGl/OpenGl_Text.cxx +++ b/src/OpenGl/OpenGl_Text.cxx @@ -38,12 +38,12 @@ namespace //! Auxiliary tool for setting polygon offset temporarily. struct BackPolygonOffsetSentry { - BackPolygonOffsetSentry (const Handle(OpenGl_Context)& theCtx) - : myCtx (theCtx), - myOffsetBack (!theCtx.IsNull() ? theCtx->PolygonOffset() : Graphic3d_PolygonOffset()) + BackPolygonOffsetSentry (OpenGl_Context* theCtx) + : myCtx (theCtx) { - if (!theCtx.IsNull()) + if (theCtx != NULL) { + myOffsetBack = theCtx->PolygonOffset(); Graphic3d_PolygonOffset aPolyOffset = myOffsetBack; aPolyOffset.Mode = Aspect_POM_Fill; aPolyOffset.Units += 1.0f; @@ -53,7 +53,7 @@ namespace ~BackPolygonOffsetSentry() { - if (!myCtx.IsNull()) + if (myCtx != NULL) { myCtx->SetPolygonOffset (myOffsetBack); } @@ -63,8 +63,8 @@ namespace BackPolygonOffsetSentry (const BackPolygonOffsetSentry& ); BackPolygonOffsetSentry& operator= (const BackPolygonOffsetSentry& ); private: - const Handle(OpenGl_Context)& myCtx; - const Graphic3d_PolygonOffset myOffsetBack; + OpenGl_Context* myCtx; + Graphic3d_PolygonOffset myOffsetBack; }; } // anonymous namespace @@ -744,13 +744,13 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx, } case Aspect_TODT_SUBTITLE: { - BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx : Handle(OpenGl_Context)()); + BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx.get() : NULL); drawRect (theCtx, theTextAspect, theColorSubs); break; } case Aspect_TODT_DEKALE: { - BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx : Handle(OpenGl_Context)()); + BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx.get() : NULL); theCtx->SetColor4fv (theColorSubs); setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, +1.0f, 0.0f)); drawText (theCtx, theTextAspect); @@ -764,7 +764,7 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx, } case Aspect_TODT_SHADOW: { - BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx : Handle(OpenGl_Context)()); + BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx.get() : NULL); theCtx->SetColor4fv (theColorSubs); setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.0f)); drawText (theCtx, theTextAspect); diff --git a/tests/parse.rules b/tests/parse.rules index 32b0a5c2d9..f52909e7b7 100644 --- a/tests/parse.rules +++ b/tests/parse.rules @@ -7,3 +7,4 @@ FAILED /\b[Ff][Aa][Ii][Ll][0-9]\b/ error FAILED /\b[Ff][Aa][Ii][Ll][Ee][Dd]\b/ error FAILED /\b[Ff][Aa][Ii][Ll][Uu][Rr][Ee]\b/ error FAILED /Process killed by CPU limit/ Killed by CPU limit +FAILED /Process killed by elapsed limit/ Killed by elapsed time limit -- 2.20.1