PROPER FIX: Add recursion protection to nick column formatting

Previous fix only avoided the symptom by using printf() instead of printtext().

Real problem: format_get_text_theme_charargs() was applying nick formatting
to ALL formats including timestamps, causing recursion when timestamp
formatting called back into format_get_text_theme_charargs().

Proper solution:
1. Restrict nick formatting to actual message formats only
2. Add formatting_depth counter to prevent recursion
3. Only apply formatting when formatting_depth == 0

This prevents the root cause of recursion rather than just avoiding
the debug output symptom.

Timestamp: 2025-01-25 01:25
This commit is contained in:
kofany 2025-08-25 02:21:38 +02:00
commit 716384cf62

View file

@ -832,6 +832,7 @@ char *format_get_text_theme_args(THEME_REC *theme, const char *module,
/* Check if format number is a message format that needs nick column */
static gboolean is_message_format(int formatnum)
{
/* Only apply to actual message formats, NOT timestamps or other formats */
return (formatnum == TXT_OWN_MSG || formatnum == TXT_OWN_MSG_CHANNEL ||
formatnum == TXT_PUBMSG || formatnum == TXT_PUBMSG_CHANNEL ||
formatnum == TXT_PUBMSG_ME || formatnum == TXT_PUBMSG_ME_CHANNEL ||
@ -907,11 +908,19 @@ char *format_get_text_theme_charargs(THEME_REC *theme, const char *module,
text = module_theme->expanded_formats[formatnum];
/* 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)) {
is_message_format(formatnum) &&
formatting_depth == 0) { /* Prevent recursion */
formatting_depth++;
modified_text = apply_nick_column_formatting(text, formatnum);
text = modified_text;
formatting_depth--;
/* Debug output - use printf to avoid recursion */
if (settings_get_bool("debug_nick_column")) {
@ -919,6 +928,7 @@ char *format_get_text_theme_charargs(THEME_REC *theme, const char *module,
printf("DEBUG format_auto: modified='%s'\n", text);
}
}
}
result = format_get_text_args(dest, text, args);