core, plugins: check return code of strftime function

v2.8-utf8proc
Sébastien Helleu 2017-09-22 21:50:01 +02:00
parent ae66a4d8a5
commit 5aab494dd6
23 changed files with 130 additions and 72 deletions

View File

@ -35,6 +35,7 @@ Improvements::
Bug fixes::
* core, plugins: check return code of strftime function
* core: fix cast of time_t (to "long long" instead of "long") (issue #1051)
* core: call the config hook when options are renamed or removed
* api: change type of arguments status/gnutls_rc/sock in hook_connect() callback from string to integer (in scripts)

View File

@ -994,9 +994,10 @@ config_get_item_time (char *text_time, int max_length)
date = time (NULL);
local_time = localtime (&date);
strftime (text_time, max_length,
config_item_time_evaluated,
local_time);
if (strftime (text_time, max_length,
config_item_time_evaluated,
local_time) == 0)
text_time[0] = '\0';
}
/*
@ -1281,7 +1282,8 @@ config_day_change_timer_cb (const void *pointer, void *data,
}
/* send signal "day_changed" */
strftime (str_time, sizeof (str_time), "%Y-%m-%d", local_time);
if (strftime (str_time, sizeof (str_time), "%Y-%m-%d", local_time) == 0)
str_time[0] = '\0';
(void) hook_signal_send ("day_changed",
WEECHAT_HOOK_SIGNAL_STRING, str_time);
}

View File

@ -4804,8 +4804,9 @@ hook_print_log ()
local_time = localtime (&seconds);
if (local_time)
{
strftime (text_time, sizeof (text_time),
"%d/%m/%Y %H:%M:%S", local_time);
if (strftime (text_time, sizeof (text_time),
"%d/%m/%Y %H:%M:%S", local_time) == 0)
text_time[0] = '\0';
}
log_printf (" last_exec.tv_sec. . . : %lld (%s)",
(long long)(HOOK_TIMER(ptr_hook, last_exec.tv_sec)),
@ -4816,8 +4817,9 @@ hook_print_log ()
local_time = localtime (&seconds);
if (local_time)
{
strftime (text_time, sizeof (text_time),
"%d/%m/%Y %H:%M:%S", local_time);
if (strftime (text_time, sizeof (text_time),
"%d/%m/%Y %H:%M:%S", local_time) == 0)
text_time[0] = '\0';
}
log_printf (" next_exec.tv_sec. . . : %lld (%s)",
(long long)(HOOK_TIMER(ptr_hook, next_exec.tv_sec)),

View File

@ -316,8 +316,9 @@ util_get_time_string (const time_t *date)
local_time = localtime (date);
if (local_time)
{
strftime (text_time, sizeof (text_time),
CONFIG_STRING(config_look_time_format), local_time);
if (strftime (text_time, sizeof (text_time),
CONFIG_STRING(config_look_time_format), local_time) == 0)
text_time[0] = '\0';
}
return text_time;

View File

@ -649,14 +649,19 @@ gui_chat_display_day_changed (struct t_gui_window *window,
/* build the message to display */
if (date1)
{
strftime (temp_message, sizeof (temp_message),
CONFIG_STRING(config_look_day_change_message_2dates), date1);
strftime (message, sizeof (message), temp_message, date2);
if (strftime (temp_message, sizeof (temp_message),
CONFIG_STRING(config_look_day_change_message_2dates),
date1) == 0)
temp_message[0] = '\0';
if (strftime (message, sizeof (message), temp_message, date2) == 0)
message[0] = '\0';
}
else
{
strftime (message, sizeof (message),
CONFIG_STRING(config_look_day_change_message_1date), date2);
if (strftime (message, sizeof (message),
CONFIG_STRING(config_look_day_change_message_1date),
date2) == 0)
message[0] = '\0';
}
message_with_color = (strstr (message, "${")) ?
@ -1928,9 +1933,10 @@ gui_chat_get_bare_line (struct t_gui_line *line)
&& CONFIG_STRING(config_look_bare_display_time_format)[0])
{
local_time = localtime (&line->data->date);
strftime (str_time, sizeof (str_time),
CONFIG_STRING(config_look_bare_display_time_format),
local_time);
if (strftime (str_time, sizeof (str_time),
CONFIG_STRING(config_look_bare_display_time_format),
local_time) == 0)
str_time[0] = '\0';
}
tag_prefix_nick = gui_line_search_tag_starting_with (line, "prefix_nick_");

View File

@ -1016,9 +1016,10 @@ gui_chat_hsignal_quote_line_cb (const void *pointer, void *data,
local_time = localtime (&line_date);
if (local_time)
{
strftime (str_time, sizeof (str_time),
CONFIG_STRING(config_look_quote_time_format),
local_time);
if (strftime (str_time, sizeof (str_time),
CONFIG_STRING(config_look_quote_time_format),
local_time) == 0)
str_time[0] = '\0';
}
}
}

View File

@ -108,11 +108,13 @@ exec_command_list ()
{
/* process has ended */
local_time = localtime (&ptr_exec_cmd->start_time);
strftime (str_time1, sizeof (str_time1),
"%Y-%m-%d %H:%M:%S", local_time);
if (strftime (str_time1, sizeof (str_time1),
"%Y-%m-%d %H:%M:%S", local_time) == 0)
str_time1[0] = '\0';
local_time = localtime (&ptr_exec_cmd->end_time);
strftime (str_time2, sizeof (str_time2),
"%Y-%m-%d %H:%M:%S", local_time);
if (strftime (str_time2, sizeof (str_time2),
"%Y-%m-%d %H:%M:%S", local_time) == 0)
str_time2[0] = '\0';
weechat_printf (NULL,
" %s%s%s %d%s%s%s: %s\"%s%s%s\"%s (%s -> %s, %s)",
weechat_color (weechat_config_string (exec_config_color_flag_finished)),

View File

@ -4321,7 +4321,10 @@ weechat_guile_api_infolist_time (SCM infolist, SCM variable)
API_SCM_TO_STRING(variable));
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
{
if (strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp) == 0)
timebuffer[0] = '\0';
}
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);

View File

@ -452,9 +452,10 @@ irc_ctcp_replace_variables (struct t_irc_server *server, const char *format)
now = time (NULL);
local_time = localtime (&now);
setlocale (LC_ALL, "C");
strftime (buf, sizeof (buf),
weechat_config_string (irc_config_look_ctcp_time_format),
local_time);
if (strftime (buf, sizeof (buf),
weechat_config_string (irc_config_look_ctcp_time_format),
local_time) == 0)
buf[0] = '\0';
setlocale (LC_ALL, "");
temp = weechat_string_replace (res, "$time", buf);
free (res);

View File

@ -93,7 +93,8 @@ logger_get_file_path ()
seconds = time (NULL);
date_tmp = localtime (&seconds);
path2[0] = '\0';
strftime (path2, length - 1, path, date_tmp);
if (strftime (path2, length - 1, path, date_tmp) == 0)
path2[0] = '\0';
if (weechat_logger_plugin->debug)
{
@ -573,9 +574,10 @@ logger_write_line (struct t_logger_buffer *logger_buffer,
date_tmp = localtime (&seconds);
if (date_tmp)
{
strftime (buf_time, sizeof (buf_time) - 1,
weechat_config_string (logger_config_file_time_format),
date_tmp);
if (strftime (buf_time, sizeof (buf_time) - 1,
weechat_config_string (logger_config_file_time_format),
date_tmp) == 0)
buf_time[0] = '\0';
}
snprintf (buf_beginning, sizeof (buf_beginning),
_("%s\t**** Beginning of log ****"),
@ -633,9 +635,10 @@ logger_stop (struct t_logger_buffer *logger_buffer, int write_info_line)
date_tmp = localtime (&seconds);
if (date_tmp)
{
strftime (buf_time, sizeof (buf_time) - 1,
weechat_config_string (logger_config_file_time_format),
date_tmp);
if (strftime (buf_time, sizeof (buf_time) - 1,
weechat_config_string (logger_config_file_time_format),
date_tmp) == 0)
buf_time[0] = '\0';
}
logger_write_line (logger_buffer,
_("%s\t**** End of log ****"),
@ -1268,9 +1271,10 @@ logger_print_cb (const void *pointer, void *data,
date_tmp = localtime (&date);
if (date_tmp)
{
strftime (buf_time, sizeof (buf_time) - 1,
weechat_config_string (logger_config_file_time_format),
date_tmp);
if (strftime (buf_time, sizeof (buf_time) - 1,
weechat_config_string (logger_config_file_time_format),
date_tmp) == 0)
buf_time[0] = '\0';
}
logger_write_line (ptr_logger_buffer,

View File

@ -4580,7 +4580,10 @@ API_FUNC(infolist_time)
variable);
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
{
if (strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp) == 0)
timebuffer[0] = '\0';
}
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);

View File

@ -4493,7 +4493,10 @@ API_FUNC(infolist_time)
time = weechat_infolist_time (API_STR2PTR(infolist), variable);
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
{
if (strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp) == 0)
timebuffer[0] = '\0';
}
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);

View File

@ -4510,7 +4510,10 @@ API_FUNC(infolist_time)
variable);
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
{
if (strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp) == 0)
timebuffer[0] = '\0';
}
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);

View File

@ -726,7 +726,8 @@ relay_irc_get_line_info (struct t_relay_client *client,
&& time_format && time_format[0])
{
tm = localtime (&msg_date);
strftime (str_time, sizeof (str_time), time_format, tm);
if (strftime (str_time, sizeof (str_time), time_format, tm) == 0)
str_time[0] = '\0';
length = strlen (str_time) + strlen (pos) + 1;
*message = malloc (length);
if (*message)
@ -741,7 +742,8 @@ relay_irc_get_line_info (struct t_relay_client *client,
&& (RELAY_IRC_DATA(client, server_capabilities) & (1 << RELAY_IRC_CAPAB_SERVER_TIME)))
{
tm = gmtime (&msg_date);
strftime (str_time, sizeof (str_time), "%Y-%m-%dT%H:%M:%S", tm);
if (strftime (str_time, sizeof (str_time), "%Y-%m-%dT%H:%M:%S", tm) == 0)
str_time[0] = '\0';
snprintf (str_tag, sizeof (str_tag), "@time=%s.000Z ", str_time);
*tags = strdup (str_tag);
}

View File

@ -96,8 +96,9 @@ relay_buffer_refresh (const char *hotlist)
date_tmp = localtime (&(ptr_client->start_time));
if (date_tmp)
{
strftime (str_date_start, sizeof (str_date_start),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (strftime (str_date_start, sizeof (str_date_start),
"%a, %d %b %Y %H:%M:%S", date_tmp) == 0)
str_date_start[0] = '\0';
}
str_date_end[0] = '-';
str_date_end[1] = '\0';
@ -106,8 +107,9 @@ relay_buffer_refresh (const char *hotlist)
date_tmp = localtime (&(ptr_client->end_time));
if (date_tmp)
{
strftime (str_date_end, sizeof (str_date_end),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (strftime (str_date_end, sizeof (str_date_end),
"%a, %d %b %Y %H:%M:%S", date_tmp) == 0)
str_date_end[0] = '\0';
}
}

View File

@ -66,16 +66,18 @@ relay_command_client_list (int full)
date_tmp = localtime (&(ptr_client->start_time));
if (date_tmp)
{
strftime (date_start, sizeof (date_start),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (strftime (date_start, sizeof (date_start),
"%a, %d %b %Y %H:%M:%S", date_tmp) == 0)
date_start[0] = '\0';
}
date_activity[0] = '\0';
date_tmp = localtime (&(ptr_client->last_activity));
if (date_tmp)
{
strftime (date_activity, sizeof (date_activity),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (strftime (date_activity, sizeof (date_activity),
"%a, %d %b %Y %H:%M:%S", date_tmp) == 0)
date_activity[0] = '\0';
}
if (full)
@ -156,8 +158,9 @@ relay_command_server_list ()
date_tmp = localtime (&(ptr_server->start_time));
if (date_tmp)
{
strftime (date_start, sizeof (date_start),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (strftime (date_start, sizeof (date_start),
"%a, %d %b %Y %H:%M:%S", date_tmp) == 0)
date_start[0] = '\0';
}
weechat_printf (
NULL,

View File

@ -5462,7 +5462,10 @@ weechat_ruby_api_infolist_time (VALUE class, VALUE infolist, VALUE variable)
time = weechat_infolist_time (API_STR2PTR(c_infolist), c_variable);
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
{
if (strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp) == 0)
timebuffer[0] = '\0';
}
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);

View File

@ -117,8 +117,9 @@ script_buffer_display_line_script (int line, struct t_script_repo *script)
if (script->date_added > 0)
{
tm = localtime (&script->date_added);
strftime (str_date, sizeof (str_date),
"%Y-%m-%d", tm);
if (strftime (str_date, sizeof (str_date),
"%Y-%m-%d", tm) == 0)
str_date[0] = '\0';
snprintf (str_item, sizeof (str_item),
"%s%s",
weechat_color (
@ -232,8 +233,9 @@ script_buffer_display_line_script (int line, struct t_script_repo *script)
if (script->date_updated > 0)
{
tm = localtime (&script->date_updated);
strftime (str_date, sizeof (str_date),
"%Y-%m-%d", tm);
if (strftime (str_date, sizeof (str_date),
"%Y-%m-%d", tm) == 0)
str_date[0] = '\0';
snprintf (str_item, sizeof (str_item),
"%s%s",
weechat_color (
@ -672,14 +674,16 @@ script_buffer_display_detail_script (struct t_script_repo *script)
}
line++;
tm = localtime (&script->date_added);
strftime (str_time, sizeof (str_time), "%Y-%m-%d %H:%M:%S", tm);
if (strftime (str_time, sizeof (str_time), "%Y-%m-%d %H:%M:%S", tm) == 0)
str_time[0] = '\0';
weechat_printf_y (script_buffer, line + 1,
"%s: %s",
script_buffer_detail_label (_(labels[line]), max_length),
str_time);
line++;
tm = localtime (&script->date_updated);
strftime (str_time, sizeof (str_time), "%Y-%m-%d %H:%M:%S", tm);
if (strftime (str_time, sizeof (str_time), "%Y-%m-%d %H:%M:%S", tm) == 0)
str_time[0] = '\0';
weechat_printf_y (script_buffer, line + 1,
"%s: %s",
script_buffer_detail_label (_(labels[line]), max_length),

View File

@ -98,10 +98,12 @@ script_mouse_focus_chat_cb (const void *pointer, void *data,
weechat_hashtable_set (info, "script_md5sum", ptr_script->md5sum);
weechat_hashtable_set (info, "script_url", ptr_script->url);
tm = localtime (&ptr_script->date_added);
strftime (str_date, sizeof (str_date), "%Y-%m-%d %H:%M:%S", tm);
if (strftime (str_date, sizeof (str_date), "%Y-%m-%d %H:%M:%S", tm) == 0)
str_date[0] = '\0';
weechat_hashtable_set (info, "script_date_added", str_date);
tm = localtime (&ptr_script->date_updated);
strftime (str_date, sizeof (str_date), "%Y-%m-%d %H:%M:%S", tm);
if (strftime (str_date, sizeof (str_date), "%Y-%m-%d %H:%M:%S", tm) == 0)
str_date[0] = '\0';
weechat_hashtable_set (info, "script_date_updated", str_date);
weechat_hashtable_set (info, "script_version_loaded", ptr_script->version_loaded);

View File

@ -4839,7 +4839,10 @@ API_FUNC(infolist_time)
time = weechat_infolist_time (API_STR2PTR(infolist), variable);
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
{
if (strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp) == 0)
timebuffer[0] = '\0';
}
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);

View File

@ -798,7 +798,9 @@ trigger_callback_print_cb (const void *pointer, void *data,
date_tmp = localtime (&date);
if (date_tmp)
{
strftime (str_temp, sizeof (str_temp), "%Y-%m-%d %H:%M:%S", date_tmp);
if (strftime (str_temp, sizeof (str_temp),
"%Y-%m-%d %H:%M:%S", date_tmp) == 0)
str_temp[0] = '\0';
weechat_hashtable_set (extra_vars, "tg_date", str_temp);
}
snprintf (str_temp, sizeof (str_temp), "%d", displayed);
@ -940,7 +942,9 @@ trigger_callback_timer_cb (const void *pointer, void *data,
date_tmp = localtime (&date);
if (date_tmp)
{
strftime (str_temp, sizeof (str_temp), "%Y-%m-%d %H:%M:%S", date_tmp);
if (strftime (str_temp, sizeof (str_temp),
"%Y-%m-%d %H:%M:%S", date_tmp) == 0)
str_temp[0] = '\0';
weechat_hashtable_set (extra_vars, "tg_date", str_temp);
}

View File

@ -148,8 +148,9 @@ xfer_buffer_refresh (const char *hotlist)
date_tmp = localtime (&(ptr_xfer->start_time));
if (date_tmp)
{
strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp) == 0)
date[0] = '\0';
}
weechat_printf_y (xfer_buffer, (line * 2) + 3,
"%s%s%s %s%s%s%s%s",

View File

@ -134,8 +134,9 @@ xfer_command_xfer_list (int full)
date_tmp = localtime (&(ptr_xfer->start_time));
if (date_tmp)
{
strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp) == 0)
date[0] = '\0';
}
weechat_printf (NULL,
/* TRANSLATORS: "%s" after "started on" is a date */
@ -171,8 +172,9 @@ xfer_command_xfer_list (int full)
date_tmp = localtime (&(ptr_xfer->start_transfer));
if (date_tmp)
{
strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp) == 0)
date[0] = '\0';
}
weechat_printf (NULL,
/* TRANSLATORS: "%s" after "started on" is a date */