aboutsummaryrefslogtreecommitdiff
path: root/libsylph
diff options
context:
space:
mode:
authorHiro <Hiro@ee746299-78ed-0310-b773-934348b2243d>2005-10-10 08:38:30 +0000
committerHiro <Hiro@ee746299-78ed-0310-b773-934348b2243d>2005-10-10 08:38:30 +0000
commit57940797b47f21c2a5f54b6d12abad9553e0e0f9 (patch)
tree191d890f991b4748202375f47ce8115744bde2de /libsylph
parentd19d2c5d8874b947abc80b7aa29c7b19909006f7 (diff)
fixed crashes on abnormal date.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@628 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph')
-rw-r--r--libsylph/procheader.c11
-rw-r--r--libsylph/utils.c14
2 files changed, 21 insertions, 4 deletions
diff --git a/libsylph/procheader.c b/libsylph/procheader.c
index 9267ead1..82a1d615 100644
--- a/libsylph/procheader.c
+++ b/libsylph/procheader.c
@@ -768,6 +768,12 @@ time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
t.tm_isdst = -1;
timer = mktime(&t);
+ if (timer == -1) {
+ if (dest)
+ dest[0] = '\0';
+ return 0;
+ }
+
tz_offset = remote_tzoffset_sec(zone);
if (tz_offset != -1)
timer += tzoffset_sec(&timer) - tz_offset;
@@ -787,6 +793,11 @@ void procheader_date_get_localtime(gchar *dest, gint len, const time_t timer)
Xalloca(tmp, len + 1, dest[0] = '\0'; return;);
lt = localtime(&timer);
+ if (!lt) {
+ g_warning("can't get localtime of %d\n", timer);
+ dest[0] = '\0';
+ return;
+ }
if (prefs_common.date_format)
strftime(tmp, len, prefs_common.date_format, lt);
diff --git a/libsylph/utils.c b/libsylph/utils.c
index f9ebba5a..0ddae386 100644
--- a/libsylph/utils.c
+++ b/libsylph/utils.c
@@ -3175,11 +3175,14 @@ time_t remote_tzoffset_sec(const gchar *zone)
time_t tzoffset_sec(time_t *now)
{
- struct tm gmt, *lt;
+ struct tm gmt, *tmp, *lt;
gint off;
- gmt = *gmtime(now);
+ tmp = gmtime(now);
+ g_return_val_if_fail(tmp != NULL, -1);
+ gmt = *tmp;
lt = localtime(now);
+ g_return_val_if_fail(lt != NULL, -1);
off = (lt->tm_hour - gmt.tm_hour) * 60 + lt->tm_min - gmt.tm_min;
@@ -3204,12 +3207,15 @@ time_t tzoffset_sec(time_t *now)
gchar *tzoffset(time_t *now)
{
static gchar offset_string[6];
- struct tm gmt, *lt;
+ struct tm gmt, *tmp, *lt;
gint off;
gchar sign = '+';
- gmt = *gmtime(now);
+ tmp = gmtime(now);
+ g_return_val_if_fail(tmp != NULL, NULL);
+ gmt = *tmp;
lt = localtime(now);
+ g_return_val_if_fail(lt != NULL, NULL);
off = (lt->tm_hour - gmt.tm_hour) * 60 + lt->tm_min - gmt.tm_min;