summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2018-08-15 16:16:31 +0200
committerSébastien Helleu <flashcode@flashtux.org>2018-08-15 16:16:31 +0200
commitf10578b18b5a6bbbba451286a1d4322b41adf237 (patch)
tree3e606c1b2db0a7aa7f41b7f857f560023715a8d9 /src
parentcfc491f7d1ee8a613405848d018773328600c7ec (diff)
downloadweechat-f10578b18b5a6bbbba451286a1d4322b41adf237.zip
core: remove use of pointer "buffer" once the line has been initialized
Diffstat (limited to 'src')
-rw-r--r--src/gui/gui-chat.c123
1 files changed, 60 insertions, 63 deletions
diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c
index 888b5b141..a720a45bb 100644
--- a/src/gui/gui-chat.c
+++ b/src/gui/gui-chat.c
@@ -737,77 +737,74 @@ gui_chat_printf_date_tags_internal (struct t_gui_buffer *buffer,
goto no_print;
/* call modifier for message printed ("weechat_print") */
- if (buffer)
+ length_data = strlen (gui_buffer_get_plugin_name (new_line->data->buffer)) +
+ 1 +
+ strlen (new_line->data->buffer->name) +
+ 1 +
+ ((tags) ? strlen (tags) : 0) +
+ 1;
+ modifier_data = malloc (length_data);
+ length_str = ((new_line->data->prefix) ? strlen (new_line->data->prefix) + 1 : 0) +
+ (new_line->data->message ? strlen (new_line->data->message) : 0) +
+ 1;
+ string = malloc (length_str);
+ if (modifier_data && string)
{
- length_data = strlen (gui_buffer_get_plugin_name (new_line->data->buffer)) +
- 1 +
- strlen (new_line->data->buffer->name) +
- 1 +
- ((tags) ? strlen (tags) : 0) +
- 1;
- modifier_data = malloc (length_data);
- length_str = ((new_line->data->prefix) ? strlen (new_line->data->prefix) + 1 : 0) +
- (new_line->data->message ? strlen (new_line->data->message) : 0) +
- 1;
- string = malloc (length_str);
- if (modifier_data && string)
+ snprintf (modifier_data, length_data,
+ "%s;%s;%s",
+ gui_buffer_get_plugin_name (new_line->data->buffer),
+ new_line->data->buffer->name,
+ (tags) ? tags : "");
+ snprintf (string, length_str,
+ "%s%s%s",
+ (new_line->data->prefix) ? new_line->data->prefix : "",
+ (new_line->data->prefix) ? "\t" : "",
+ (new_line->data->message) ? new_line->data->message : "");
+ new_string = hook_modifier_exec (NULL,
+ "weechat_print",
+ modifier_data,
+ string);
+ if (new_string)
{
- snprintf (modifier_data, length_data,
- "%s;%s;%s",
- gui_buffer_get_plugin_name (new_line->data->buffer),
- new_line->data->buffer->name,
- (tags) ? tags : "");
- snprintf (string, length_str,
- "%s%s%s",
- (new_line->data->prefix) ? new_line->data->prefix : "",
- (new_line->data->prefix) ? "\t" : "",
- (new_line->data->message) ? new_line->data->message : "");
- new_string = hook_modifier_exec (NULL,
- "weechat_print",
- modifier_data,
- string);
- if (new_string)
+ if (!new_string[0] && string[0])
{
- if (!new_string[0] && string[0])
+ /*
+ * modifier returned empty message, then we'll not
+ * print anything
+ */
+ goto no_print;
+ }
+ else if (strcmp (string, new_string) != 0)
+ {
+ /* use new message if there are changes */
+ pos_prefix = NULL;
+ ptr_msg = new_string;
+ pos_tab = strchr (new_string, '\t');
+ if (pos_tab)
{
- /*
- * modifier returned empty message, then we'll not
- * print anything
- */
- goto no_print;
+ pos_tab[0] = '\0';
+ pos_prefix = ptr_msg;
+ ptr_msg = pos_tab + 1;
}
- else if (strcmp (string, new_string) != 0)
+ if (pos_prefix)
{
- /* use new message if there are changes */
- pos_prefix = NULL;
- ptr_msg = new_string;
- pos_tab = strchr (new_string, '\t');
- if (pos_tab)
- {
- pos_tab[0] = '\0';
- pos_prefix = ptr_msg;
- ptr_msg = pos_tab + 1;
- }
- if (pos_prefix)
- {
- if (new_line->data->prefix)
- string_shared_free (new_line->data->prefix);
- new_line->data->prefix = (char *)string_shared_get (pos_prefix);
- new_line->data->prefix_length = gui_chat_strlen_screen (pos_prefix);
- }
- else
+ if (new_line->data->prefix)
+ string_shared_free (new_line->data->prefix);
+ new_line->data->prefix = (char *)string_shared_get (pos_prefix);
+ new_line->data->prefix_length = gui_chat_strlen_screen (pos_prefix);
+ }
+ else
+ {
+ if (new_line->data->prefix)
{
- if (new_line->data->prefix)
- {
- string_shared_free (new_line->data->prefix);
- new_line->data->prefix = NULL;
- }
- new_line->data->prefix_length = 0;
+ string_shared_free (new_line->data->prefix);
+ new_line->data->prefix = NULL;
}
- if (new_line->data->message)
- free (new_line->data->message);
- new_line->data->message = strdup (ptr_msg);
+ new_line->data->prefix_length = 0;
}
+ if (new_line->data->message)
+ free (new_line->data->message);
+ new_line->data->message = strdup (ptr_msg);
}
}
}
@@ -816,7 +813,7 @@ gui_chat_printf_date_tags_internal (struct t_gui_buffer *buffer,
gui_line_add (new_line);
/* run hook_print for the new line */
- if (new_line->data->buffer && buffer->print_hooks_enabled)
+ if (new_line->data->buffer && new_line->data->buffer->print_hooks_enabled)
hook_print_exec (new_line->data->buffer, new_line);
gui_buffer_ask_chat_refresh (new_line->data->buffer, 1);