mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Check the return value of strftime() properly
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1113 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
aa447813d0
commit
d427f74143
@ -70,27 +70,31 @@ static void log_write_timestamp(int handle, const char *format,
|
|||||||
if (*format == '\0') return;
|
if (*format == '\0') return;
|
||||||
|
|
||||||
tm = localtime(&stamp);
|
tm = localtime(&stamp);
|
||||||
|
if (strftime(str, sizeof(str), format, tm) > 0) {
|
||||||
str[sizeof(str)-1] = '\0';
|
|
||||||
strftime(str, sizeof(str)-1, format, tm);
|
|
||||||
|
|
||||||
write(handle, str, strlen(str));
|
write(handle, str, strlen(str));
|
||||||
if (suffix != NULL) write(handle, suffix, strlen(suffix));
|
if (suffix != NULL) write(handle, suffix, strlen(suffix));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static char *log_filename(LOG_REC *log)
|
static char *log_filename(LOG_REC *log)
|
||||||
{
|
{
|
||||||
char *str, fname[1024];
|
char *str, fname[1024];
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
|
size_t ret;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
tm = localtime(&now);
|
tm = localtime(&now);
|
||||||
|
|
||||||
str = convert_home(log->fname);
|
str = convert_home(log->fname);
|
||||||
strftime(fname, sizeof(fname), str, tm);
|
ret = strftime(fname, sizeof(fname), str, tm);
|
||||||
g_free(str);
|
g_free(str);
|
||||||
|
|
||||||
|
if (ret <= 0) {
|
||||||
|
g_warning("log_filename() : strftime() failed");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return g_strdup(fname);
|
return g_strdup(fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +108,8 @@ int log_start_logging(LOG_REC *log)
|
|||||||
/* Append/create log file */
|
/* Append/create log file */
|
||||||
g_free_not_null(log->real_fname);
|
g_free_not_null(log->real_fname);
|
||||||
log->real_fname = log_filename(log);
|
log->real_fname = log_filename(log);
|
||||||
log->handle = open(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
|
log->handle = log->real_fname == NULL ? -1 :
|
||||||
|
open(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
|
||||||
log_file_create_mode);
|
log_file_create_mode);
|
||||||
if (log->handle == -1) {
|
if (log->handle == -1) {
|
||||||
signal_emit("log create failed", 1, log);
|
signal_emit("log create failed", 1, log);
|
||||||
|
@ -421,13 +421,14 @@ static void sig_server_disconnected(SERVER_REC *server)
|
|||||||
static void sig_print_text(void)
|
static void sig_print_text(void)
|
||||||
{
|
{
|
||||||
GSList *tmp;
|
GSList *tmp;
|
||||||
char month[10];
|
char month[100];
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
|
|
||||||
t = time(NULL);
|
t = time(NULL);
|
||||||
tm = localtime(&t);
|
tm = localtime(&t);
|
||||||
strftime(month, sizeof(month)-1, "%b", tm);
|
if (strftime(month, sizeof(month), "%b", tm) <= 0)
|
||||||
|
month[0] = '\0';
|
||||||
|
|
||||||
if (tm->tm_hour != 0 || tm->tm_min != 0)
|
if (tm->tm_hour != 0 || tm->tm_min != 0)
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user