changeset 1376:a0deb5124ebf

Check time_prefix value before using it
author Mikael Berthe <mikael@lilotux.net>
date Fri, 23 Nov 2007 21:56:58 +0100
parents 6fd893fe0908
children cd9182f0b5c7
files mcabber/src/screen.c
diffstat 1 files changed, 17 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/screen.c	Mon Nov 19 22:36:40 2007 +0100
+++ b/mcabber/src/screen.c	Fri Nov 23 21:56:58 2007 +0100
@@ -794,6 +794,7 @@
 };
 
 static int timepreflengths[] = {
+  // (length of the corresponding timeprefix + 5)
   17,
   11,
   6
@@ -801,17 +802,20 @@
 
 static const char *gettprefix()
 {
-  return timeprefixes[settings_opt_get_int("time_prefix")];
+  guint n = settings_opt_get_int("time_prefix");
+  return timeprefixes[(n < 3 ? n : 0)];
 }
 
 static const char *getspectprefix()
 {
-  return spectimeprefixes[settings_opt_get_int("time_prefix")];
+  guint n = settings_opt_get_int("time_prefix");
+  return spectimeprefixes[(n < 3 ? n : 0)];
 }
 
 static unsigned getprefixwidth()
 {
-  return timepreflengths[settings_opt_get_int("time_prefix")];
+  guint n = settings_opt_get_int("time_prefix");
+  return timepreflengths[(n < 3 ? n : 0)];
 }
 
 //  scr_LogPrint(...)
@@ -960,13 +964,14 @@
 static void scr_UpdateWindow(winbuf *win_entry)
 {
   int n;
-  int width;
+  int width, prefixwidth;
   hbb_line **lines, *line;
   GList *hbuf_head;
   char date[64];
   int color;
 
   width = getmaxx(win_entry->win);
+  prefixwidth = getprefixwidth();
 
   // Should the window be empty?
   if (win_entry->bd->cleared) {
@@ -1055,14 +1060,14 @@
       }
 
       // Make sure we are at the right position
-      wmove(win_entry->win, n, getprefixwidth()-1);
-
-      //The MUC nick - overwrite with propper color
+      wmove(win_entry->win, n, prefixwidth-1);
+
+      // The MUC nick - overwrite with proper color
       if (line->mucnicklen) {
-        //Store the char after the nick
+        // Store the char after the nick
         char tmp = line->text[line->mucnicklen];
         muccoltype type = glob_muccol, *typetmp;
-        //Terminate the string after the nick
+        // Terminate the string after the nick
         line->text[line->mucnicklen] = '\0';
         char *mucjid = g_utf8_strdown(CURRENT_JID, -1);
         if (muccolors) {
@@ -1084,7 +1089,7 @@
           snick[strlen(snick)-1] = '>';
           *mnick = '*';
           mnick[strlen(mnick)-1] = ' ';
-          //Insert them
+          // Insert them
           g_hash_table_insert(nickcolors, snick, nc);
           g_hash_table_insert(nickcolors, mnick, nc);
         }
@@ -1095,9 +1100,9 @@
            (!(line->flags & HBB_PREFIX_HLIGHT_OUT)))
           wattrset(win_entry->win, get_color(actual->color));
         wprintw(win_entry->win, "%s", line->text);
-        //Return the char
+        // Return the char
         line->text[line->mucnicklen] = tmp;
-        //Return the color back
+        // Return the color back
         wattrset(win_entry->win, get_color(color));
       }