]> jfr.im git - irc/hexchat/hexchat.git/commitdiff
More minor scrollback loading improvements
authorPatrick Griffis <redacted>
Tue, 26 Apr 2016 16:05:57 +0000 (12:05 -0400)
committerPatrick Griffis <redacted>
Tue, 26 Apr 2016 16:06:28 +0000 (12:06 -0400)
src/common/text.c

index 2f20d17118d4e72523c0f16c49ca1c5ce701bc55..06f72cfbf0496ee7b12c4ed658d97c5814e7d155 100644 (file)
@@ -222,7 +222,7 @@ scrollback_load (session *sess)
        GDataInputStream *istream;
        gchar *buf, *text;
        gint lines = 0;
-       time_t stamp;
+       time_t stamp = 0;
 
        if (sess->text_scrollback == SET_DEFAULT)
        {
@@ -272,12 +272,19 @@ scrollback_load (session *sess)
                         * Some don't even have a timestamp
                         * Some don't have any text at all
                         */
-                       if (buf[0] == 'T')
+                       if (buf[0] == 'T' && buf[1] == ' ')
                        {
                                if (sizeof (time_t) == 4)
-                                       stamp = g_ascii_strtoull (buf + 2, NULL, 10);
+                                       stamp = strtoul (buf + 2, NULL, 10);
                                else
                                        stamp = g_ascii_strtoull (buf + 2, NULL, 10); /* in case time_t is 64 bits */
+
+                               if (G_UNLIKELY(stamp == 0))
+                               {
+                                       g_warning ("Invalid timestamp in scrollback file");
+                                       continue;
+                               }
+
                                text = strchr (buf + 3, ' ');
                                if (text && text[1])
                                {
@@ -314,7 +321,7 @@ scrollback_load (session *sess)
                        /* If its only an encoding error it may be specific to the line */
                        if (g_error_matches (err, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE))
                        {
-                               g_warning ("Invalid utf8 in scrollback file\n");
+                               g_warning ("Invalid utf8 in scrollback file");
                                g_clear_error (&err);
                                continue;
                        }
@@ -336,8 +343,7 @@ scrollback_load (session *sess)
        if (lines)
        {
                text = ctime (&stamp);
-               text[24] = 0;   /* get rid of the \n */
-               buf = g_strdup_printf ("\n*\t%s %s\n\n", _("Loaded log from"), text);
+               buf = g_strdup_printf ("\n*\t%s %s\n", _("Loaded log from"), text);
                fe_print_text (sess, buf, 0, TRUE);
                g_free (buf);
                /*EMIT_SIGNAL (XP_TE_GENMSG, sess, "*", buf, NULL, NULL, NULL, 0);*/