comphelper/qa/unit/test_traceevent.cxx |    7 +++++++
 include/comphelper/profilezone.hxx     |   14 +++++++++++---
 include/sal/log-areas.dox              |    1 +
 3 files changed, 19 insertions(+), 3 deletions(-)

New commits:
commit 7e8960caa8b49c75e4f1d21ebffe2378359fee69
Author:     Tor Lillqvist <t...@collabora.com>
AuthorDate: Thu Apr 29 11:07:18 2021 +0300
Commit:     Tor Lillqvist <t...@collabora.com>
CommitDate: Thu Apr 29 11:26:52 2021 +0200

    Add SAL_WARN in case ProfileZones are overlapping and not hierarchical
    
    Change-Id: Id09904db762b6d931ab23cce16e55d5213079516
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114834
    Tested-by: Jenkins
    Reviewed-by: Tor Lillqvist <t...@collabora.com>

diff --git a/comphelper/qa/unit/test_traceevent.cxx 
b/comphelper/qa/unit/test_traceevent.cxx
index e170e8aaeb18..29094b14f01b 100644
--- a/comphelper/qa/unit/test_traceevent.cxx
+++ b/comphelper/qa/unit/test_traceevent.cxx
@@ -122,6 +122,13 @@ void trace_event_test()
         // object that has already had its 'e' event generated.
     }
 
+    // This incorrect use of overlapping (not nested) ProfileZones
+    // will generate a SAL_WARN but should not crash
+    auto p1 = new comphelper::ProfileZone("error1");
+    auto p2 = new comphelper::ProfileZone("error2");
+    delete p1;
+    delete p2;
+
     // Nothing is generated from this
     pAsync7Locked.reset();
 }
diff --git a/include/comphelper/profilezone.hxx 
b/include/comphelper/profilezone.hxx
index 40e2ee97e502..8eda2d773ac0 100644
--- a/include/comphelper/profilezone.hxx
+++ b/include/comphelper/profilezone.hxx
@@ -12,6 +12,8 @@
 
 #include <sal/config.h>
 
+#include <sal/log.hxx>
+
 #include <comphelper/traceevent.hxx>
 
 // implementation of XToolkitExperimental profiling API
@@ -70,10 +72,16 @@ public:
         if (m_nCreateTime > 0)
         {
             s_nNesting--;
-            assert(m_nNesting == s_nNesting);
 
-            if (s_bRecording)
-                addRecording();
+            if (m_nNesting != s_nNesting)
+            {
+                SAL_WARN("comphelper.traceevent", "Incorrect ProfileZone 
nesting for " << m_sName);
+            }
+            else
+            {
+                if (s_bRecording)
+                    addRecording();
+            }
 
             if (m_bConsole)
                 stopConsole();
diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox
index c3b1a80a20b1..edd2da37d9d8 100644
--- a/include/sal/log-areas.dox
+++ b/include/sal/log-areas.dox
@@ -97,6 +97,7 @@ certain functionality.
 @li @c comphelper.container - EmbeddedObjectContainer
 @li @c comphelper.crypto
 @li @c comphelper.lok
+@li @c comphelper.traceevent
 
 @section cppu
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to