From 85bca0cb235b04c1299cf0598109728f7b61786c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 17 Aug 2022 20:33:25 +1000 Subject: [PATCH] Make stacktraces slightly smaller by avoiding 0x at start, also avoid redundantly logging Logger_Backtrace frame on macOS/iOS Also fix for commands that specify to split arguments, 'argsCount' was still 1 when command arguments was empty string --- src/Chat.c | 2 +- src/Formats.c | 3 +-- src/Logger.c | 11 +++++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Chat.c b/src/Chat.c index d5d538416..26f919e61 100644 --- a/src/Chat.c +++ b/src/Chat.c @@ -362,7 +362,7 @@ static void Commands_Execute(const cc_string* input) { cmd->Execute(&value, value.length != 0); } else { count = String_UNSAFE_Split(&value, ' ', args, Array_Elems(args)); - cmd->Execute(args, count); + cmd->Execute(args, value.length ? count : 0); } } diff --git a/src/Formats.c b/src/Formats.c index 9e04d3823..3b98efde0 100644 --- a/src/Formats.c +++ b/src/Formats.c @@ -624,8 +624,7 @@ static void Cw_Callback_1(struct NbtTag* tag) { static void Cw_Callback_2(struct NbtTag* tag) { struct LocalPlayer* p = &LocalPlayer_Instance; - if (IsTag(tag->parent, "MapGenerator")) - { + if (IsTag(tag->parent, "MapGenerator")) { if (IsTag(tag, "Seed")) { World.Seed = NbtTag_I32(tag); return; } return; } diff --git a/src/Logger.c b/src/Logger.c index 72715ac14..610b39914 100644 --- a/src/Logger.c +++ b/src/Logger.c @@ -169,7 +169,7 @@ static void PrintFrame(cc_string* str, cc_uintptr addr, cc_uintptr symAddr, cons module = String_FromReadonly(modName); Utils_UNSAFE_GetFilename(&module); - String_Format2(str, "0x%x - %s", &addr, &module); + String_Format2(str, "%x - %s", &addr, &module); if (symName && symName[0]) { offset = (int)(addr - symAddr); @@ -327,7 +327,10 @@ void Logger_Backtrace(cc_string* trace, void* ctx) { extern void thread_stack_pcs(void** buffer, unsigned max, unsigned* nb); thread_stack_pcs(addrs, MAX_BACKTRACE_FRAMES, &frames); - for (i = 1; i < frames; i++) { /* 1 to skip thread_stack_pcs frame */ + /* Skip frames don't want to include in backtrace */ + /* frame 0 = thread_stack_pcs */ + /* frame 1 = Logger_Backtrace */ + for (i = 2; i < frames; i++) { DumpFrame(trace, addrs[i]); } String_AppendConst(trace, _NL); @@ -800,7 +803,7 @@ static LONG WINAPI UnhandledFilter(struct _EXCEPTION_POINTERS* info) { addr = (cc_uintptr)info->ExceptionRecord->ExceptionAddress; String_InitArray_NT(msg, msgBuffer); - String_Format2(&msg, "Unhandled exception 0x%h at 0x%x", &code, &addr); + String_Format2(&msg, "Unhandled exception 0x%h at %x", &code, &addr); numArgs = info->ExceptionRecord->NumberParameters; if (numArgs) { @@ -885,7 +888,7 @@ static void SignalHandler(int sig, siginfo_t* info, void* ctx) { addr = (cc_uintptr)info->si_addr; String_InitArray_NT(msg, msgBuffer); - String_Format3(&msg, "Unhandled signal %i (code %i) at 0x%x", &type, &code, &addr); + String_Format3(&msg, "Unhandled signal %i (code %i) at %x", &type, &code, &addr); msg.buffer[msg.length] = '\0'; #if defined CC_BUILD_ANDROID