From 652d6c81815a056606193b236e64221ebb6533fa Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 2 Nov 2022 22:13:56 +0000 Subject: [PATCH] Crashlog: Windows: Handle negative address offsets from BFD symbol --- src/os/windows/crashlog_win.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/os/windows/crashlog_win.cpp b/src/os/windows/crashlog_win.cpp index 374741621e..24f7d3a2da 100644 --- a/src/os/windows/crashlog_win.cpp +++ b/src/os/windows/crashlog_win.cpp @@ -544,7 +544,11 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c free(demangled); #endif if (symbol_ok && bfd_info.function_addr) { - buffer += seprintf(buffer, last, " + " OTTD_PRINTF64U, frame.AddrPC.Offset - static_cast(bfd_info.function_addr)); + if (bfd_info.function_addr < frame.AddrPC.Offset) { + buffer += seprintf(buffer, last, " - " OTTD_PRINTF64U, static_cast(bfd_info.function_addr) - frame.AddrPC.Offset); + } else { + buffer += seprintf(buffer, last, " + " OTTD_PRINTF64U, frame.AddrPC.Offset - static_cast(bfd_info.function_addr)); + } } } if (bfd_info.file_name != nullptr) {