From 5a8392f9d8cd3d4f15329fd40e39303634ae799a Mon Sep 17 00:00:00 2001 From: kofany Date: Mon, 25 Aug 2025 02:33:00 +0200 Subject: [PATCH] Fix debug output target: Send to current window not status Problem: Debug printtext(NULL, NULL, ...) was sending debug messages to status window, which caused crashes when status window tried to format timestamps for debug messages. Root cause: Status window environment/context different from chat windows, causing crashes in expando_time() -> getenv() during timestamp formatting. Solution: Use printtext_window() to send debug to current dest->window or active_win instead of status window. This prevents crashes when debugging nick formatting while focus is on status window or when sending debug to inappropriate window contexts. Timestamp: 2025-01-25 02:32 --- src/fe-common/core/formats.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/fe-common/core/formats.c b/src/fe-common/core/formats.c index 135ecdd8..1bb68595 100644 --- a/src/fe-common/core/formats.c +++ b/src/fe-common/core/formats.c @@ -45,6 +45,9 @@ static const char *ext_color_al = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; static int signal_gui_print_text; static int hide_text_style, hide_server_tags, hide_colors; +/* Global recursion protection for nick column formatting */ +static int nick_formatting_depth = 0; + static int timestamp_level; static int timestamp_timeout; @@ -909,26 +912,25 @@ char *format_get_text_theme_charargs(THEME_REC *theme, const char *module, /* Apply nick column formatting if enabled and this is a message format */ /* Additional protection: avoid recursion during timestamp formatting */ - { - static int formatting_depth = 0; - if (settings_get_bool("nick_column_enabled") && g_strcmp0(module, "fe-common/core") == 0 && is_message_format(formatnum) && - formatting_depth == 0) { /* Prevent recursion */ + nick_formatting_depth == 0) { /* Prevent recursion */ - formatting_depth++; + nick_formatting_depth++; modified_text = apply_nick_column_formatting(text, formatnum); text = modified_text; - formatting_depth--; + nick_formatting_depth--; - /* Debug output - use printf to avoid recursion */ + /* Debug output - send to current window, not status */ if (settings_get_bool("debug_nick_column")) { - printf("DEBUG format_auto: formatnum=%d, original='%s'\n", formatnum, module_theme->expanded_formats[formatnum]); - printf("DEBUG format_auto: modified='%s'\n", text); + WINDOW_REC *window = dest && dest->window ? dest->window : active_win; + printtext_window(window, MSGLEVEL_CLIENTCRAP, + "DEBUG format_auto: formatnum=%d, original='%s'", formatnum, module_theme->expanded_formats[formatnum]); + printtext_window(window, MSGLEVEL_CLIENTCRAP, + "DEBUG format_auto: modified='%s'", text); } } - } result = format_get_text_args(dest, text, args);