Changeset 1096:94b40cc4ac2e for color.c

Show
Ignore:
Timestamp:
1999-07-06 15:40:25 (9 years ago)
Author:
Thomas Roessler <roessler@…>
Branch:
HEAD
Message:

Fixing a string buffer problem noted by Todd Larason
<jtl@…>.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • color.c

    r948 r1096  
    154154 
    155155#ifdef USE_SLANG_CURSES 
    156 static char * get_color_name (int val) 
     156static char *get_color_name (char *dest, size_t destlen, int val) 
    157157{ 
    158158  static char * missing[3] = {"brown", "lightgray", ""}; 
     
    162162  { 
    163163    case COLOR_YELLOW: 
    164       return (missing[0]); 
     164      strfcpy (dest, missing[0], destlen); 
     165      return dest; 
    165166 
    166167    case COLOR_WHITE: 
    167       return (missing[1]); 
     168      strfcpy (dest, missing[1], destlen); 
     169      return dest; 
    168170       
    169171    case COLOR_DEFAULT: 
    170       return (missing[2]); 
     172      strfcpy (dest, missing[2], destlen); 
     173      return dest; 
    171174  } 
    172175 
     
    174177  { 
    175178    if (Colors[i].value == val) 
    176       return (Colors[i].name); 
     179    { 
     180      strfcpy (dest, Colors[i].name, destlen); 
     181      return dest; 
     182    } 
    177183  } 
    178184 
     
    180186   * Slang can handle this itself, so just return 'colorN' 
    181187   */ 
    182   { 
    183     static char color [SHORT_STRING]; 
    184  
    185     snprintf (color, sizeof (color), "color%d", val); 
    186     return color; 
    187   } 
     188 
     189  snprintf (dest, destlen, "color%d", val); 
     190  return dest; 
    188191} 
    189192#endif 
     
    193196  COLOR_LIST *p = ColorList; 
    194197  int i; 
     198   
     199#if defined (USE_SLANG_CURSES) 
     200  char fgc[SHORT_STRING], bgc[SHORT_STRING]; 
     201#endif 
    195202 
    196203  /* check to see if this color is already allocated to save space */ 
     
    233240#if defined (USE_SLANG_CURSES) 
    234241  if (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT) 
    235     SLtt_set_color (i, NULL, get_color_name (fg), get_color_name (bg)); 
     242    SLtt_set_color (i, NULL, get_color_name (fgc, sizeof (fgc), fg), get_color_name (bgc, sizeof (bgc), bg)); 
    236243  else 
    237244#elif defined (HAVE_USE_DEFAULT_COLORS)