From bdfa1bd51c7c3d0e9793edc338ceb9477c5bd08b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 22 Jun 2024 08:54:08 +0200 Subject: [PATCH] core, plugins: return "0x0" instead of "(nil)" for pointers formatted in strings This is a partial revert of the commit 965beb37dede0ac0f6e1be961acfbc15ee7e46cf. --- CHANGELOG.md | 1 + src/core/core-eval.c | 18 +++++----- src/core/core-hashtable.c | 3 +- src/core/core-hashtable.h | 3 +- src/core/core-input.c | 2 +- src/gui/gui-bar-item.c | 2 +- src/gui/gui-bar.c | 2 +- src/gui/gui-chat.c | 4 +-- src/gui/gui-history.c | 2 +- src/gui/gui-input.c | 3 +- src/gui/gui-nicklist.c | 4 +-- src/plugins/buflist/buflist-mouse.c | 2 +- src/plugins/fset/fset-mouse.c | 3 +- src/plugins/irc/irc-bar-item.c | 3 +- src/plugins/irc/irc-info.c | 2 +- src/plugins/irc/irc-typing.c | 4 +-- src/plugins/plugin-api-info.c | 2 +- src/plugins/plugin-script.c | 2 +- src/plugins/relay/irc/relay-irc.c | 6 ++-- .../relay/weechat/relay-weechat-protocol.c | 34 ++++++++++++------- src/plugins/trigger/trigger-callback.c | 5 ++- 21 files changed, 65 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ca768d68..f77ccd6db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ - irc: display an explicit message on /list buffer when the list of channels is empty ([#2133](https://github.com/weechat/weechat/issues/2133)) - xfer: fix send of data on the DCC chat buffer after `/upgrade` if the buffer was opened before the upgrade ([#2092](https://github.com/weechat/weechat/issues/2092)) - core: fix refresh of bar item "scroll" in root bar after `/buffer clear` ([#590](https://github.com/weechat/weechat/issues/590)) +- core, plugins: return "0x0" instead of "(nil)" for pointers formatted in strings - php: fix return value of function hdata_longlong - tcl: fix return value of function hdata_longlong ([#2119](https://github.com/weechat/weechat/issues/2119)) - relay: fix websocket permessage-deflate extension when the client doesn't send the max window bits parameters ([#1549](https://github.com/weechat/weechat/issues/1549)) diff --git a/src/core/core-eval.c b/src/core/core-eval.c index abb6514ba..680597448 100644 --- a/src/core/core-eval.c +++ b/src/core/core-eval.c @@ -1221,9 +1221,9 @@ eval_hdata_get_value (struct t_hdata *hdata, void *pointer, const char *path, int type, debug_id; struct t_hashtable *hashtable; - EVAL_DEBUG_MSG(1, "eval_hdata_get_value(\"%s\", %p, \"%s\")", + EVAL_DEBUG_MSG(1, "eval_hdata_get_value(\"%s\", 0x%lx, \"%s\")", (hdata) ? hdata->name : "(null)", - pointer, + (unsigned long)pointer, path); value = NULL; @@ -1239,7 +1239,7 @@ eval_hdata_get_value (struct t_hdata *hdata, void *pointer, const char *path, /* no path? just return current pointer as string */ if (!path || !path[0]) { - snprintf (str_value, sizeof (str_value), "%p", pointer); + snprintf (str_value, sizeof (str_value), "0x%lx", (unsigned long)pointer); value = strdup (str_value); goto end; } @@ -1296,7 +1296,8 @@ eval_hdata_get_value (struct t_hdata *hdata, void *pointer, const char *path, break; case WEECHAT_HDATA_POINTER: pointer = hdata_pointer (hdata, pointer, var_name); - snprintf (str_value, sizeof (str_value), "%p", pointer); + snprintf (str_value, sizeof (str_value), + "0x%lx", (unsigned long)pointer); value = strdup (str_value); break; case WEECHAT_HDATA_TIME: @@ -1345,7 +1346,7 @@ eval_hdata_get_value (struct t_hdata *hdata, void *pointer, const char *path, case HASHTABLE_POINTER: case HASHTABLE_BUFFER: snprintf (str_value, sizeof (str_value), - "%p", ptr_value); + "0x%lx", (unsigned long)ptr_value); value = strdup (str_value); break; case HASHTABLE_TIME: @@ -1365,7 +1366,8 @@ eval_hdata_get_value (struct t_hdata *hdata, void *pointer, const char *path, } else { - snprintf (str_value, sizeof (str_value), "%p", pointer); + snprintf (str_value, sizeof (str_value), + "0x%lx", (unsigned long)pointer); value = strdup (str_value); } break; @@ -2516,8 +2518,8 @@ eval_replace_regex (const char *string, regex_t *regex, const char *replace, result = NULL; - EVAL_DEBUG_MSG(1, "eval_replace_regex(\"%s\", %p, \"%s\")", - string, regex, replace); + EVAL_DEBUG_MSG(1, "eval_replace_regex(\"%s\", 0x%lx, \"%s\")", + string, (unsigned long)regex, replace); if (!string || !regex || !replace) goto end; diff --git a/src/core/core-hashtable.c b/src/core/core-hashtable.c index 448597adb..29ad2ca34 100644 --- a/src/core/core-hashtable.c +++ b/src/core/core-hashtable.c @@ -590,7 +590,8 @@ hashtable_to_string (enum t_hashtable_type type, const void *value) return (const char *)value; case HASHTABLE_POINTER: case HASHTABLE_BUFFER: - snprintf (str_value, sizeof (str_value), "%p", value); + snprintf (str_value, sizeof (str_value), "0x%lx", + (unsigned long)value); return str_value; case HASHTABLE_TIME: snprintf (str_value, sizeof (str_value), diff --git a/src/core/core-hashtable.h b/src/core/core-hashtable.h index 24cf6452a..1e8f04e62 100644 --- a/src/core/core-hashtable.h +++ b/src/core/core-hashtable.h @@ -43,7 +43,8 @@ struct t_infolist_item; #define HASHTABLE_SET_POINTER(__name, __pointer) \ if (__pointer) \ { \ - snprintf (str_value, sizeof (str_value), "%p", __pointer); \ + snprintf (str_value, sizeof (str_value), \ + "0x%lx", (unsigned long)__pointer); \ hashtable_set (hashtable, __name, str_value); \ } \ else \ diff --git a/src/core/core-input.c b/src/core/core-input.c index f3bddfa5b..22696f75d 100644 --- a/src/core/core-input.c +++ b/src/core/core-input.c @@ -265,7 +265,7 @@ input_data (struct t_gui_buffer *buffer, const char *data, } /* execute modifier "input_text_for_buffer" */ - snprintf (str_buffer, sizeof (str_buffer), "%p", buffer); + snprintf (str_buffer, sizeof (str_buffer), "0x%lx", (unsigned long)buffer); new_data = hook_modifier_exec (NULL, "input_text_for_buffer", str_buffer, diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index 6181a791d..74505398e 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -947,7 +947,7 @@ gui_bar_item_input_text_cb (const void *pointer, void *data, } /* for modifiers */ - snprintf (str_buffer, sizeof (str_buffer), "%p", buffer); + snprintf (str_buffer, sizeof (str_buffer), "0x%lx", (unsigned long)buffer); /* execute modifier with basic string (without cursor tag) */ ptr_input = NULL; diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c index e7fc5a5d4..b2688dbaf 100644 --- a/src/gui/gui-bar.c +++ b/src/gui/gui-bar.c @@ -434,7 +434,7 @@ gui_bar_check_conditions (struct t_gui_bar *bar, */ snprintf (str_modifier, sizeof (str_modifier), "bar_condition_%s", bar->name); - snprintf (str_window, sizeof (str_window), "%p", window); + snprintf (str_window, sizeof (str_window), "0x%lx", (unsigned long)window); str_displayed = hook_modifier_exec (NULL, str_modifier, str_window, diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index 57ed10cca..7a39c69b9 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -677,8 +677,8 @@ gui_chat_printf_datetime_tags_internal (struct t_gui_buffer *buffer, if (modifier_data && string) { snprintf (modifier_data, length_data, - "%p;%s", - buffer, + "0x%lx;%s", + (unsigned long)buffer, (tags) ? tags : ""); if (display_time) { diff --git a/src/gui/gui-history.c b/src/gui/gui-history.c index 8e1bca320..00d8694e7 100644 --- a/src/gui/gui-history.c +++ b/src/gui/gui-history.c @@ -192,7 +192,7 @@ gui_history_add (struct t_gui_buffer *buffer, const char *string) { char *string2, str_buffer[128]; - snprintf (str_buffer, sizeof (str_buffer), "%p", buffer); + snprintf (str_buffer, sizeof (str_buffer), "0x%lx", (unsigned long)buffer); string2 = hook_modifier_exec (NULL, "history_add", str_buffer, string); /* diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c index 442add09d..cce248c4c 100644 --- a/src/gui/gui-input.c +++ b/src/gui/gui-input.c @@ -158,7 +158,8 @@ gui_input_text_changed_modifier_and_signal (struct t_gui_buffer *buffer, gui_buffer_undo_add (buffer); /* send modifier, and change input if needed */ - snprintf (str_buffer, sizeof (str_buffer), "%p", buffer); + snprintf (str_buffer, sizeof (str_buffer), + "0x%lx", (unsigned long)buffer); new_input = hook_modifier_exec (NULL, "input_text_content", str_buffer, diff --git a/src/gui/gui-nicklist.c b/src/gui/gui-nicklist.c index 6d7f9e7fd..b79b3a107 100644 --- a/src/gui/gui-nicklist.c +++ b/src/gui/gui-nicklist.c @@ -69,8 +69,8 @@ gui_nicklist_send_signal (const char *signal, struct t_gui_buffer *buffer, if (str_args) { snprintf (str_args, length, - "%p,%s", - buffer, + "0x%lx,%s", + (unsigned long)buffer, (arguments) ? arguments : ""); (void) hook_signal_send (signal, WEECHAT_HOOK_SIGNAL_STRING, str_args); diff --git a/src/plugins/buflist/buflist-mouse.c b/src/plugins/buflist/buflist-mouse.c index f542d9c38..4369c8fc9 100644 --- a/src/plugins/buflist/buflist-mouse.c +++ b/src/plugins/buflist/buflist-mouse.c @@ -155,7 +155,7 @@ end: } /* add pointer and plugin name */ - snprintf (str_value, sizeof (str_value), "%p", ptr_buffer); + snprintf (str_value, sizeof (str_value), "0x%lx", (unsigned long)ptr_buffer); weechat_hashtable_set (info, "pointer", str_value); weechat_hashtable_set (info, "plugin", weechat_buffer_get_string (ptr_buffer, "plugin")); diff --git a/src/plugins/fset/fset-mouse.c b/src/plugins/fset/fset-mouse.c index 9e8d0d006..84ae12032 100644 --- a/src/plugins/fset/fset-mouse.c +++ b/src/plugins/fset/fset-mouse.c @@ -79,7 +79,8 @@ fset_mouse_focus_cb (const void *pointer, void *data, struct t_hashtable *info) if (!ptr_fset_option) return info; - snprintf (str_value, sizeof (str_value), "%p", ptr_fset_option); + snprintf (str_value, sizeof (str_value), + "0x%lx", (unsigned long)ptr_fset_option); weechat_hashtable_set (info, "fset_option", str_value); snprintf (str_value, sizeof (str_value), "%ld", option_index); weechat_hashtable_set (info, "fset_option_index", str_value); diff --git a/src/plugins/irc/irc-bar-item.c b/src/plugins/irc/irc-bar-item.c index ef7516c36..4e77f96a0 100644 --- a/src/plugins/irc/irc-bar-item.c +++ b/src/plugins/irc/irc-bar-item.c @@ -658,7 +658,8 @@ irc_bar_item_focus_buffer_nicklist (const void *pointer, void *data, ptr_nick = irc_nick_search (ptr_server, ptr_channel, nick); if (ptr_nick) { - snprintf (str_value, sizeof (str_value), "%p", ptr_nick); + snprintf (str_value, sizeof (str_value), + "0x%lx", (unsigned long)ptr_nick); weechat_hashtable_set (info, "irc_nick", str_value); if (ptr_nick->host) diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index f9bb60149..6cbd5b00e 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -57,7 +57,7 @@ irc_info_create_string_with_pointer (char **string, void *pointer) *string = malloc (64); if (*string) { - snprintf (*string, 64, "%p", pointer); + snprintf (*string, 64, "0x%lx", (unsigned long)pointer); } } } diff --git a/src/plugins/irc/irc-typing.c b/src/plugins/irc/irc-typing.c index 296fc31bc..fcc1cf9eb 100644 --- a/src/plugins/irc/irc-typing.c +++ b/src/plugins/irc/irc-typing.c @@ -143,8 +143,8 @@ irc_typing_channel_set_nick (struct t_irc_channel *channel, const char *nick, char signal_data[1024]; snprintf (signal_data, sizeof (signal_data), - "%p;%s;%s", - channel->buffer, + "0x%lx;%s;%s", + (unsigned long)channel->buffer, (state == IRC_CHANNEL_TYPING_STATE_ACTIVE) ? "typing" : ((state == IRC_CHANNEL_TYPING_STATE_PAUSED) ? "paused" : "off"), nick); diff --git a/src/plugins/plugin-api-info.c b/src/plugins/plugin-api-info.c index 4c1606264..3f3c1eb5c 100644 --- a/src/plugins/plugin-api-info.c +++ b/src/plugins/plugin-api-info.c @@ -512,7 +512,7 @@ plugin_api_info_buffer_cb (const void *pointer, void *data, if (!ptr_buffer) return NULL; - snprintf (value, sizeof (value), "%p", ptr_buffer); + snprintf (value, sizeof (value), "0x%lx", (unsigned long)ptr_buffer); return strdup (value); } diff --git a/src/plugins/plugin-script.c b/src/plugins/plugin-script.c index 624de161f..1854baca1 100644 --- a/src/plugins/plugin-script.c +++ b/src/plugins/plugin-script.c @@ -379,7 +379,7 @@ plugin_script_ptr2str (void *pointer) return str_pointer[index_pointer]; snprintf (str_pointer[index_pointer], sizeof (str_pointer[index_pointer]), - "%p", pointer); + "0x%lx", (unsigned long)pointer); return str_pointer[index_pointer]; } diff --git a/src/plugins/relay/irc/relay-irc.c b/src/plugins/relay/irc/relay-irc.c index 79847cd5a..9fb08cb66 100644 --- a/src/plugins/relay/irc/relay-irc.c +++ b/src/plugins/relay/irc/relay-irc.c @@ -215,7 +215,8 @@ relay_irc_sendf (struct t_relay_client *client, const char *format, ...) hashtable_in = NULL; hashtable_out = NULL; - snprintf (modifier_data, sizeof (modifier_data), "%p", client); + snprintf (modifier_data, sizeof (modifier_data), + "0x%lx", (unsigned long)client); new_msg1 = weechat_hook_modifier_exec ("relay_client_irc_out1", modifier_data, vbuffer); @@ -1641,7 +1642,8 @@ relay_irc_recv (struct t_relay_client *client, const char *data) data); } - snprintf (modifier_data, sizeof (modifier_data), "%p", client); + snprintf (modifier_data, sizeof (modifier_data), + "0x%lx", (unsigned long)client); new_data = weechat_hook_modifier_exec ("relay_client_irc_in", modifier_data, data); diff --git a/src/plugins/relay/weechat/relay-weechat-protocol.c b/src/plugins/relay/weechat/relay-weechat-protocol.c index 541f4b70d..a3668ac4d 100644 --- a/src/plugins/relay/weechat/relay-weechat-protocol.c +++ b/src/plugins/relay/weechat/relay-weechat-protocol.c @@ -872,7 +872,8 @@ relay_weechat_protocol_signal_buffer_cb (const void *pointer, void *data, msg = relay_weechat_msg_new (str_signal); if (msg) { - snprintf (cmd_hdata, sizeof (cmd_hdata), "buffer:%p", ptr_buffer); + snprintf (cmd_hdata, sizeof (cmd_hdata), + "buffer:0x%lx", (unsigned long)ptr_buffer); relay_weechat_msg_add_hdata (msg, cmd_hdata, "id,number,full_name,short_name," "nicklist,title,local_variables," @@ -896,7 +897,8 @@ relay_weechat_protocol_signal_buffer_cb (const void *pointer, void *data, msg = relay_weechat_msg_new (str_signal); if (msg) { - snprintf (cmd_hdata, sizeof (cmd_hdata), "buffer:%p", ptr_buffer); + snprintf (cmd_hdata, sizeof (cmd_hdata), + "buffer:0x%lx", (unsigned long)ptr_buffer); relay_weechat_msg_add_hdata (msg, cmd_hdata, "id,number,full_name,type"); relay_weechat_msg_send (ptr_client, msg); @@ -918,7 +920,8 @@ relay_weechat_protocol_signal_buffer_cb (const void *pointer, void *data, msg = relay_weechat_msg_new (str_signal); if (msg) { - snprintf (cmd_hdata, sizeof (cmd_hdata), "buffer:%p", ptr_buffer); + snprintf (cmd_hdata, sizeof (cmd_hdata), + "buffer:0x%lx", (unsigned long)ptr_buffer); relay_weechat_msg_add_hdata (msg, cmd_hdata, "id,number,full_name," "prev_buffer,next_buffer"); @@ -942,7 +945,8 @@ relay_weechat_protocol_signal_buffer_cb (const void *pointer, void *data, msg = relay_weechat_msg_new (str_signal); if (msg) { - snprintf (cmd_hdata, sizeof (cmd_hdata), "buffer:%p", ptr_buffer); + snprintf (cmd_hdata, sizeof (cmd_hdata), + "buffer:0x%lx", (unsigned long)ptr_buffer); relay_weechat_msg_add_hdata (msg, cmd_hdata, "id,number,full_name," "prev_buffer,next_buffer"); @@ -966,7 +970,8 @@ relay_weechat_protocol_signal_buffer_cb (const void *pointer, void *data, msg = relay_weechat_msg_new (str_signal); if (msg) { - snprintf (cmd_hdata, sizeof (cmd_hdata), "buffer:%p", ptr_buffer); + snprintf (cmd_hdata, sizeof (cmd_hdata), + "buffer:0x%lx", (unsigned long)ptr_buffer); relay_weechat_msg_add_hdata (msg, cmd_hdata, "id,number,full_name," "prev_buffer,next_buffer"); @@ -1010,7 +1015,8 @@ relay_weechat_protocol_signal_buffer_cb (const void *pointer, void *data, msg = relay_weechat_msg_new (str_signal); if (msg) { - snprintf (cmd_hdata, sizeof (cmd_hdata), "buffer:%p", ptr_buffer); + snprintf (cmd_hdata, sizeof (cmd_hdata), + "buffer:0x%lx", (unsigned long)ptr_buffer); relay_weechat_msg_add_hdata (msg, cmd_hdata, "id,number,full_name,short_name," "local_variables"); @@ -1033,7 +1039,8 @@ relay_weechat_protocol_signal_buffer_cb (const void *pointer, void *data, msg = relay_weechat_msg_new (str_signal); if (msg) { - snprintf (cmd_hdata, sizeof (cmd_hdata), "buffer:%p", ptr_buffer); + snprintf (cmd_hdata, sizeof (cmd_hdata), + "buffer:0x%lx", (unsigned long)ptr_buffer); relay_weechat_msg_add_hdata (msg, cmd_hdata, "id,number,full_name,title"); relay_weechat_msg_send (ptr_client, msg); @@ -1055,7 +1062,8 @@ relay_weechat_protocol_signal_buffer_cb (const void *pointer, void *data, msg = relay_weechat_msg_new (str_signal); if (msg) { - snprintf (cmd_hdata, sizeof (cmd_hdata), "buffer:%p", ptr_buffer); + snprintf (cmd_hdata, sizeof (cmd_hdata), + "buffer:0x%lx", (unsigned long)ptr_buffer); relay_weechat_msg_add_hdata (msg, cmd_hdata, "id,number,full_name,local_variables"); relay_weechat_msg_send (ptr_client, msg); @@ -1076,7 +1084,8 @@ relay_weechat_protocol_signal_buffer_cb (const void *pointer, void *data, msg = relay_weechat_msg_new (str_signal); if (msg) { - snprintf (cmd_hdata, sizeof (cmd_hdata), "buffer:%p", ptr_buffer); + snprintf (cmd_hdata, sizeof (cmd_hdata), + "buffer:0x%lx", (unsigned long)ptr_buffer); relay_weechat_msg_add_hdata (msg, cmd_hdata, "id,number,full_name"); relay_weechat_msg_send (ptr_client, msg); @@ -1107,8 +1116,8 @@ relay_weechat_protocol_signal_buffer_cb (const void *pointer, void *data, if (msg) { snprintf (cmd_hdata, sizeof (cmd_hdata), - "line_data:%p", - ptr_line_data); + "line_data:0x%lx", + (unsigned long)ptr_line_data); relay_weechat_msg_add_hdata ( msg, cmd_hdata, "buffer,date,date_usec,date_printed,date_usec_printed," @@ -1133,7 +1142,8 @@ relay_weechat_protocol_signal_buffer_cb (const void *pointer, void *data, msg = relay_weechat_msg_new (str_signal); if (msg) { - snprintf (cmd_hdata, sizeof (cmd_hdata), "buffer:%p", ptr_buffer); + snprintf (cmd_hdata, sizeof (cmd_hdata), + "buffer:0x%lx", (unsigned long)ptr_buffer); relay_weechat_msg_add_hdata (msg, cmd_hdata, "id,number,full_name"); relay_weechat_msg_send (ptr_client, msg); diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c index 40f18486d..a6c52628f 100644 --- a/src/plugins/trigger/trigger-callback.c +++ b/src/plugins/trigger/trigger-callback.c @@ -733,7 +733,10 @@ trigger_callback_signal_cb (const void *pointer, void *data, { str_data[0] = '\0'; if (signal_data) - snprintf (str_data, sizeof (str_data), "%p", signal_data); + { + snprintf (str_data, sizeof (str_data), + "0x%lx", (unsigned long)signal_data); + } ptr_signal_data = str_data; } weechat_hashtable_set (ctx.extra_vars, "tg_signal_data", ptr_signal_data);