From 8c921500e2c890fe2e9135a31a3293672c297faa Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Mon, 12 Aug 2024 20:01:44 +0800 Subject: [PATCH] Add a placeholder text for print_backtrace()... in case backtrace(3) returns a zero or negative "nptrs" value. --- CRT.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CRT.c b/CRT.c index a60857a17..9c8b841a2 100644 --- a/CRT.c +++ b/CRT.c @@ -1261,7 +1261,13 @@ static void print_backtrace(void) { void* backtraceArray[256]; int nptrs = backtrace(backtraceArray, ARRAYSIZE(backtraceArray)); - backtrace_symbols_fd(backtraceArray, nptrs, STDERR_FILENO); + if (nptrs > 0) { + backtrace_symbols_fd(backtraceArray, nptrs, STDERR_FILENO); + } else { + full_write_str(STDERR_FILENO, + "[No backtrace information available from libc]\n" + ); + } #else #error No implementation for print_backtrace()! #endif