Utils: Fix maximum size computation for backtraces on abort

Change-Id: Ia974343cdeb6d54d2e7331735c9cdd063f445af1
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2022-07-07 16:33:08 +02:00
parent 4faff875d8
commit d7fd254a79

View File

@@ -38,11 +38,12 @@ namespace Utils {
void dumpBacktrace(int maxdepth) void dumpBacktrace(int maxdepth)
{ {
if (maxdepth == -1) const int ArraySize = 1000;
maxdepth = 1000; if (maxdepth < 0 || maxdepth > ArraySize)
maxdepth = ArraySize;
#if defined(Q_OS_UNIX) #if defined(Q_OS_UNIX)
void *bt[1000] = {nullptr}; void *bt[ArraySize] = {nullptr};
int size = backtrace(bt, sizeof(bt) / sizeof(bt[0])); int size = backtrace(bt, maxdepth);
char **lines = backtrace_symbols(bt, size); char **lines = backtrace_symbols(bt, size);
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
qDebug() << "0x" + QByteArray::number(quintptr(bt[i]), 16) << lines[i]; qDebug() << "0x" + QByteArray::number(quintptr(bt[i]), 16) << lines[i];