From d387bfacb27147970cb2c11a26fa340888c66893 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Tue, 6 Jul 1999 22:40:25 +0000 Subject: Fixing a string buffer problem noted by Todd Larason . --- color.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'color.c') diff --git a/color.c b/color.c index 8cdb743f..61a4f031 100644 --- 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) -- cgit v1.2.3