]> granicus.if.org Git - mutt/commitdiff
Fixing a string buffer problem noted by Todd Larason
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 6 Jul 1999 22:40:25 +0000 (22:40 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 6 Jul 1999 22:40:25 +0000 (22:40 +0000)
<jtl@molehill.org>.

color.c

diff --git a/color.c b/color.c
index 8cdb743f765c02565c42607f7c75040efb1c495a..61a4f0317410ee7e4e5d359e7047366133e4da15 100644 (file)
--- a/color.c
+++ b/color.c
@@ -153,7 +153,7 @@ void ci_start_color (void)
 #ifdef HAVE_COLOR
 
 #ifdef USE_SLANG_CURSES
-static char * get_color_name (int val)
+static char *get_color_name (char *dest, size_t destlen, int val)
 {
   static char * missing[3] = {"brown", "lightgray", ""};
   int i;
@@ -161,30 +161,33 @@ static char * get_color_name (int val)
   switch (val)
   {
     case COLOR_YELLOW:
-      return (missing[0]);
+      strfcpy (dest, missing[0], destlen);
+      return dest;
 
     case COLOR_WHITE:
-      return (missing[1]);
+      strfcpy (dest, missing[1], destlen);
+      return dest;
       
     case COLOR_DEFAULT:
-      return (missing[2]);
+      strfcpy (dest, missing[2], destlen);
+      return dest;
   }
 
   for (i = 0; Colors[i].name; i++)
   {
     if (Colors[i].value == val)
-      return (Colors[i].name);
+    {
+      strfcpy (dest, Colors[i].name, destlen);
+      return dest;
+    }
   }
 
   /* Sigh. If we got this far, the color is of the form 'colorN'
    * Slang can handle this itself, so just return 'colorN'
    */
-  {
-    static char color [SHORT_STRING];
 
-    snprintf (color, sizeof (color), "color%d", val);
-    return color;
-  }
+  snprintf (dest, destlen, "color%d", val);
+  return dest;
 }
 #endif
 
@@ -192,6 +195,10 @@ int mutt_alloc_color (int fg, int bg)
 {
   COLOR_LIST *p = ColorList;
   int i;
+  
+#if defined (USE_SLANG_CURSES)
+  char fgc[SHORT_STRING], bgc[SHORT_STRING];
+#endif
 
   /* check to see if this color is already allocated to save space */
   while (p)
@@ -232,7 +239,7 @@ int mutt_alloc_color (int fg, int bg)
 
 #if defined (USE_SLANG_CURSES)
   if (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT)
-    SLtt_set_color (i, NULL, get_color_name (fg), get_color_name (bg));
+    SLtt_set_color (i, NULL, get_color_name (fgc, sizeof (fgc), fg), get_color_name (bgc, sizeof (bgc), bg));
   else
 #elif defined (HAVE_USE_DEFAULT_COLORS)
   if (fg == COLOR_DEFAULT)