1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 23:06:38 +02:00

core: check pointer returned by function localtime

This commit is contained in:
Sebastien Helleu
2011-11-27 11:48:35 +01:00
parent 8ba8e62580
commit 41b5ef1e4c
16 changed files with 133 additions and 43 deletions
+12 -4
View File
@@ -3752,16 +3752,24 @@ hook_print_log ()
log_printf (" interval. . . . . . . : %ld", HOOK_TIMER(ptr_hook, interval));
log_printf (" align_second. . . . . : %d", HOOK_TIMER(ptr_hook, align_second));
log_printf (" remaining_calls . . . : %d", HOOK_TIMER(ptr_hook, remaining_calls));
text_time[0] = '\0';
local_time = localtime (&HOOK_TIMER(ptr_hook, last_exec).tv_sec);
strftime (text_time, sizeof (text_time),
"%d/%m/%Y %H:%M:%S", local_time);
if (local_time)
{
strftime (text_time, sizeof (text_time),
"%d/%m/%Y %H:%M:%S", local_time);
}
log_printf (" last_exec.tv_sec. . . : %ld (%s)",
HOOK_TIMER(ptr_hook, last_exec.tv_sec),
text_time);
log_printf (" last_exec.tv_usec . . : %ld", HOOK_TIMER(ptr_hook, last_exec.tv_usec));
text_time[0] = '\0';
local_time = localtime (&HOOK_TIMER(ptr_hook, next_exec).tv_sec);
strftime (text_time, sizeof (text_time),
"%d/%m/%Y %H:%M:%S", local_time);
if (local_time)
{
strftime (text_time, sizeof (text_time),
"%d/%m/%Y %H:%M:%S", local_time);
}
log_printf (" next_exec.tv_sec. . . : %ld (%s)",
HOOK_TIMER(ptr_hook, next_exec.tv_sec),
text_time);
+2
View File
@@ -154,12 +154,14 @@ log_printf (const char *message, ...)
seconds = time (NULL);
date_tmp = localtime (&seconds);
if (date_tmp)
{
string_iconv_fprintf (weechat_log_file,
"[%04d-%02d-%02d %02d:%02d:%02d] %s\n",
date_tmp->tm_year + 1900, date_tmp->tm_mon + 1,
date_tmp->tm_mday, date_tmp->tm_hour,
date_tmp->tm_min, date_tmp->tm_sec,
vbuffer);
}
else
string_iconv_fprintf (weechat_log_file, "%s\n", vbuffer);
}
+1 -4
View File
@@ -116,16 +116,13 @@ util_get_time_string (const time_t *date)
struct tm *local_time;
static char text_time[128];
text_time[0] = '\0';
local_time = localtime (date);
if (local_time)
{
strftime (text_time, sizeof (text_time),
CONFIG_STRING(config_look_time_format), local_time);
}
else
{
text_time[0] = '\0';
}
return text_time;
}
+2
View File
@@ -337,6 +337,8 @@ gui_chat_get_time_string (time_t date)
return NULL;
local_time = localtime (&date);
if (!local_time)
return NULL;
if (strftime (text_time, sizeof (text_time),
CONFIG_STRING(config_look_buffer_time_format),
local_time) == 0)
+4 -2
View File
@@ -1113,7 +1113,8 @@ gui_window_scroll (struct t_gui_window *window, char *scroll)
{
old_date = ptr_line->data->date;
date_tmp = localtime (&old_date);
memcpy (&old_line_date, date_tmp, sizeof (struct tm));
if (date_tmp)
memcpy (&old_line_date, date_tmp, sizeof (struct tm));
}
while (ptr_line)
@@ -1134,7 +1135,8 @@ gui_window_scroll (struct t_gui_window *window, char *scroll)
else
{
date_tmp = localtime (&(ptr_line->data->date));
memcpy (&line_date, date_tmp, sizeof (struct tm));
if (date_tmp)
memcpy (&line_date, date_tmp, sizeof (struct tm));
if (old_date > ptr_line->data->date)
diff_date = old_date - ptr_line->data->date;
else
+3 -3
View File
@@ -564,9 +564,9 @@ logger_write_line (struct t_logger_buffer *logger_buffer,
if (weechat_config_boolean (logger_config_file_info_lines)
&& logger_buffer->write_start_info_line)
{
buf_time[0] = '\0';
seconds = time (NULL);
date_tmp = localtime (&seconds);
buf_time[0] = '\0';
if (date_tmp)
{
strftime (buf_time, sizeof (buf_time) - 1,
@@ -624,9 +624,9 @@ logger_stop (struct t_logger_buffer *logger_buffer, int write_info_line)
{
if (write_info_line && weechat_config_boolean (logger_config_file_info_lines))
{
buf_time[0] = '\0';
seconds = time (NULL);
date_tmp = localtime (&seconds);
buf_time[0] = '\0';
if (date_tmp)
{
strftime (buf_time, sizeof (buf_time) - 1,
@@ -1180,8 +1180,8 @@ logger_print_cb (void *data, struct t_gui_buffer *buffer, time_t date,
&& (date > 0)
&& (line_log_level <= ptr_logger_buffer->log_level))
{
date_tmp = localtime (&date);
buf_time[0] = '\0';
date_tmp = localtime (&date);
if (date_tmp)
{
strftime (buf_time, sizeof (buf_time) - 1,
+11 -4
View File
@@ -95,15 +95,22 @@ relay_buffer_refresh (const char *hotlist)
}
}
date_start[0] = '\0';
date_tmp = localtime (&(ptr_client->start_time));
strftime (date_start, sizeof (date_start),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (date_tmp)
{
strftime (date_start, sizeof (date_start),
"%a, %d %b %Y %H:%M:%S", date_tmp);
}
date_end[0] = '\0';
if (ptr_client->end_time > 0)
{
date_tmp = localtime (&(ptr_client->end_time));
strftime (date_end, sizeof (date_end),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (date_tmp)
{
strftime (date_end, sizeof (date_end),
"%a, %d %b %Y %H:%M:%S", date_tmp);
}
}
/* first line with status and start time */
+18 -6
View File
@@ -54,13 +54,21 @@ relay_command_client_list (int full)
for (ptr_client = relay_clients; ptr_client;
ptr_client = ptr_client->next_client)
{
date_start[0] = '\0';
date_tmp = localtime (&(ptr_client->start_time));
strftime (date_start, sizeof (date_start),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (date_tmp)
{
strftime (date_start, sizeof (date_start),
"%a, %d %b %Y %H:%M:%S", date_tmp);
}
date_activity[0] = '\0';
date_tmp = localtime (&(ptr_client->last_activity));
strftime (date_activity, sizeof (date_activity),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (date_tmp)
{
strftime (date_activity, sizeof (date_activity),
"%a, %d %b %Y %H:%M:%S", date_tmp);
}
if (full)
{
@@ -121,9 +129,13 @@ relay_command_server_list ()
for (ptr_server = relay_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
date_start[0] = '\0';
date_tmp = localtime (&(ptr_server->start_time));
strftime (date_start, sizeof (date_start),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (date_tmp)
{
strftime (date_start, sizeof (date_start),
"%a, %d %b %Y %H:%M:%S", date_tmp);
}
weechat_printf (NULL,
_(" port %s%d%s, relay: %s%s.%s%s, started on: %s"),
+10 -2
View File
@@ -4706,15 +4706,19 @@ weechat_guile_api_infolist_time (SCM infolist, SCM variable)
{
char timebuffer[64], *result;
time_t time;
struct tm *date_tmp;
SCM return_value;
API_FUNC(1, "infolist_time", API_RETURN_EMPTY);
if (!scm_is_string (infolist) || !scm_is_string (variable))
API_WRONG_ARGS(API_RETURN_EMPTY);
timebuffer[0] = '\0';
time = weechat_infolist_time (script_str2ptr (scm_i_string_chars (infolist)),
scm_i_string_chars (variable));
strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time));
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);
@@ -4976,16 +4980,20 @@ weechat_guile_api_hdata_time (SCM hdata, SCM pointer, SCM name)
{
char timebuffer[64], *result;
time_t time;
struct tm *date_tmp;
SCM return_value;
API_FUNC(1, "hdata_time", API_RETURN_EMPTY);
if (!scm_is_string (hdata) || !scm_is_string (pointer) || !scm_is_string (name))
API_WRONG_ARGS(API_RETURN_EMPTY);
timebuffer[0] = '\0';
time = weechat_hdata_time (script_str2ptr (scm_i_string_chars (hdata)),
script_str2ptr (scm_i_string_chars (pointer)),
scm_i_string_chars (name));
strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time));
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);
+10 -2
View File
@@ -5179,6 +5179,7 @@ weechat_lua_api_infolist_time (lua_State *L)
{
const char *infolist, *variable;
time_t time;
struct tm *date_tmp;
char timebuffer[64], *result;
API_FUNC(1, "infolist_time", API_RETURN_EMPTY);
@@ -5188,9 +5189,12 @@ weechat_lua_api_infolist_time (lua_State *L)
infolist = lua_tostring (lua_current_interpreter, -2);
variable = lua_tostring (lua_current_interpreter, -1);
timebuffer[0] = '\0';
time = weechat_infolist_time (script_str2ptr (infolist),
variable);
strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time));
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);
@@ -5490,6 +5494,7 @@ weechat_lua_api_hdata_time (lua_State *L)
{
const char *hdata, *pointer, *name;
time_t time;
struct tm *date_tmp;
char timebuffer[64], *result;
API_FUNC(1, "hdata_time", API_RETURN_EMPTY);
@@ -5500,10 +5505,13 @@ weechat_lua_api_hdata_time (lua_State *L)
pointer = lua_tostring (lua_current_interpreter, -2);
name = lua_tostring (lua_current_interpreter, -1);
timebuffer[0] = '\0';
time = weechat_hdata_time (script_str2ptr (hdata),
script_str2ptr (pointer),
name);
strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time));
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);
+11 -2
View File
@@ -4922,6 +4922,7 @@ XS (XS_weechat_api_infolist_pointer)
XS (XS_weechat_api_infolist_time)
{
time_t time;
struct tm *date_tmp;
char timebuffer[64], *result, *infolist, *variable;
dXSARGS;
@@ -4931,8 +4932,12 @@ XS (XS_weechat_api_infolist_time)
infolist = SvPV_nolen (ST (0));
variable = SvPV_nolen (ST (1));
timebuffer[0] = '\0';
time = weechat_infolist_time (script_str2ptr (infolist), variable);
strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time));
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);
@@ -5224,6 +5229,7 @@ XS (XS_weechat_api_hdata_pointer)
XS (XS_weechat_api_hdata_time)
{
time_t time;
struct tm *date_tmp;
char timebuffer[64], *result, *hdata, *pointer, *name;
dXSARGS;
@@ -5235,10 +5241,13 @@ XS (XS_weechat_api_hdata_time)
pointer = SvPV_nolen (ST (1));
name = SvPV_nolen (ST (2));
timebuffer[0] = '\0';
time = weechat_hdata_time (script_str2ptr (hdata),
script_str2ptr (pointer),
name);
strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time));
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);
@@ -5104,6 +5104,7 @@ weechat_python_api_infolist_time (PyObject *self, PyObject *args)
{
char *infolist, *variable, timebuffer[64], *result;
time_t time;
struct tm *date_tmp;
PyObject *return_value;
API_FUNC(1, "infolist_time", API_RETURN_EMPTY);
@@ -5112,9 +5113,12 @@ weechat_python_api_infolist_time (PyObject *self, PyObject *args)
if (!PyArg_ParseTuple (args, "ss", &infolist, &variable))
API_WRONG_ARGS(API_RETURN_EMPTY);
timebuffer[0] = '\0';
time = weechat_infolist_time (script_str2ptr (infolist),
variable);
strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time));
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);
@@ -5405,6 +5409,7 @@ weechat_python_api_hdata_time (PyObject *self, PyObject *args)
{
char *hdata, *pointer, *name, timebuffer[64], *result;
time_t time;
struct tm *date_tmp;
PyObject *return_value;
API_FUNC(1, "hdata_time", API_RETURN_EMPTY);
@@ -5414,10 +5419,13 @@ weechat_python_api_hdata_time (PyObject *self, PyObject *args)
if (!PyArg_ParseTuple (args, "sss", &hdata, &pointer, &name))
API_WRONG_ARGS(API_RETURN_EMPTY);
timebuffer[0] = '\0';
time = weechat_hdata_time (script_str2ptr (hdata),
script_str2ptr (pointer),
name);
strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time));
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);
+10 -2
View File
@@ -5857,6 +5857,7 @@ weechat_ruby_api_infolist_time (VALUE class, VALUE infolist, VALUE variable)
{
char *c_infolist, *c_variable, timebuffer[64], *result;
time_t time;
struct tm *date_tmp;
VALUE return_value;
API_FUNC(1, "infolist_time", API_RETURN_EMPTY);
@@ -5869,8 +5870,11 @@ weechat_ruby_api_infolist_time (VALUE class, VALUE infolist, VALUE variable)
c_infolist = StringValuePtr (infolist);
c_variable = StringValuePtr (variable);
timebuffer[0] = '\0';
time = weechat_infolist_time (script_str2ptr (c_infolist), c_variable);
strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time));
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);
@@ -6221,6 +6225,7 @@ weechat_ruby_api_hdata_time (VALUE class, VALUE hdata, VALUE pointer,
{
char *c_hdata, *c_pointer, *c_name, timebuffer[64], *result;
time_t time;
struct tm *date_tmp;
VALUE return_value;
API_FUNC(1, "hdata_time", API_RETURN_EMPTY);
@@ -6235,10 +6240,13 @@ weechat_ruby_api_hdata_time (VALUE class, VALUE hdata, VALUE pointer,
c_pointer = StringValuePtr (pointer);
c_name = StringValuePtr (name);
timebuffer[0] = '\0';
time = weechat_hdata_time (script_str2ptr (c_hdata),
script_str2ptr (c_pointer),
c_name);
strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time));
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);
+11 -4
View File
@@ -5607,6 +5607,7 @@ weechat_tcl_api_infolist_time (ClientData clientData, Tcl_Interp *interp,
{
Tcl_Obj *objp;
time_t time;
struct tm *date_tmp;
char timebuffer[64], *result, *infolist, *variable;
int i;
@@ -5616,9 +5617,12 @@ weechat_tcl_api_infolist_time (ClientData clientData, Tcl_Interp *interp,
infolist = Tcl_GetStringFromObj (objv[1], &i);
variable = Tcl_GetStringFromObj (objv[2], &i);
time = weechat_infolist_time (script_str2ptr (infolist), variable);
strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time));
timebuffer[0] = '\0';
time = weechat_infolist_time (script_str2ptr (infolist), variable);
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);
@@ -5921,6 +5925,7 @@ weechat_tcl_api_hdata_time (ClientData clientData, Tcl_Interp *interp,
{
Tcl_Obj *objp;
time_t time;
struct tm *date_tmp;
char timebuffer[64], *result, *hdata, *pointer, *name;
int i;
@@ -5932,11 +5937,13 @@ weechat_tcl_api_hdata_time (ClientData clientData, Tcl_Interp *interp,
pointer = Tcl_GetStringFromObj (objv[2], &i);
name = Tcl_GetStringFromObj (objv[3], &i);
timebuffer[0] = '\0';
time = weechat_hdata_time (script_str2ptr (hdata),
script_str2ptr (pointer),
name);
strftime (timebuffer, sizeof (timebuffer), "%F %T", localtime (&time));
date_tmp = localtime (&time);
if (date_tmp)
strftime (timebuffer, sizeof (timebuffer), "%F %T", date_tmp);
result = strdup (timebuffer);
API_RETURN_STRING_FREE(result);
+6 -2
View File
@@ -122,9 +122,13 @@ xfer_buffer_refresh (const char *hotlist)
if (XFER_IS_CHAT(ptr_xfer->type))
{
/* display second line for chat with status and date */
date[0] = '\0';
date_tmp = localtime (&(ptr_xfer->start_time));
strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (date_tmp)
{
strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp);
}
weechat_printf_y (xfer_buffer, (line * 2) + 3,
"%s%s%s %s%s%s%s%s",
weechat_color(str_color),
+12 -4
View File
@@ -129,9 +129,13 @@ xfer_command_xfer_list (int full)
}
else
{
date[0] = '\0';
date_tmp = localtime (&(ptr_xfer->start_time));
strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (date_tmp)
{
strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp);
}
weechat_printf (NULL,
/* TRANSLATORS: "%s" after "started on" is a date */
_("%3d. %s, chat with %s (local nick: %s), "
@@ -165,9 +169,13 @@ xfer_command_xfer_list (int full)
(ptr_xfer->address >> 8) & 0xff,
ptr_xfer->address & 0xff,
ptr_xfer->port);
date[0] = '\0';
date_tmp = localtime (&(ptr_xfer->start_transfer));
strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp);
if (date_tmp)
{
strftime (date, sizeof (date),
"%a, %d %b %Y %H:%M:%S", date_tmp);
}
weechat_printf (NULL,
/* TRANSLATORS: "%s" after "started on" is a date */
_(" fast_send: %s, blocksize: %d, "