summaryrefslogtreecommitdiff
path: root/sal/osl/w32/backtrace.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sal/osl/w32/backtrace.cxx')
-rw-r--r--sal/osl/w32/backtrace.cxx23
1 files changed, 18 insertions, 5 deletions
diff --git a/sal/osl/w32/backtrace.cxx b/sal/osl/w32/backtrace.cxx
index 78d9e0aed9e5..b559c5e87fc0 100644
--- a/sal/osl/w32/backtrace.cxx
+++ b/sal/osl/w32/backtrace.cxx
@@ -9,7 +9,8 @@
#include <sal/config.h>
-#include "backtraceasstring.hxx"
+#include <limits>
+#include <memory>
#include <windows.h>
#include <process.h>
@@ -18,17 +19,29 @@
#include <DbgHelp.h>
#include <rtl/ustrbuf.hxx>
-#include <memory>
-OUString osl::detail::backtraceAsString(int maxNoStackFramesToDisplay)
+#include "backtraceasstring.hxx"
+
+OUString osl::detail::backtraceAsString(sal_uInt32 maxDepth)
{
+ assert(maxDepth != 0);
+ auto const maxUlong = std::numeric_limits<ULONG>::max();
+ if (maxDepth > maxUlong) {
+ maxDepth = static_cast<sal_uInt32>(maxUlong);
+ }
+
OUStringBuffer aBuf;
HANDLE hProcess = GetCurrentProcess();
SymInitialize( hProcess, nullptr, true );
- std::unique_ptr<void*[]> aStack(new void*[ maxNoStackFramesToDisplay ]);
- sal_uInt32 nFrames = CaptureStackBackTrace( 0, maxNoStackFramesToDisplay, aStack.get(), nullptr );
+ std::unique_ptr<void*[]> aStack(new void*[ maxDepth ]);
+ // <https://msdn.microsoft.com/en-us/library/windows/desktop/
+ // bb204633(v=vs.85).aspx> "CaptureStackBackTrace function" claims that you
+ // "can capture up to MAXUSHORT frames", and on Windows Server 2003 and
+ // Windows XP it even "must be less than 63", but assume that a too large
+ // input value is clamped internally, instead of resulting in an error:
+ sal_uInt32 nFrames = CaptureStackBackTrace( 0, static_cast<ULONG>(maxDepth), aStack.get(), nullptr );
SYMBOL_INFO * pSymbol;
pSymbol = static_cast<SYMBOL_INFO *>(calloc( sizeof( SYMBOL_INFO ) + 1024 * sizeof( char ), 1 ));