X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fcolor_name.h;h=0dadd2a16c1c15cff41e45c970798fd2ebb84a09;hp=ff82d4647d2bc87e06e13128a8154c33e6e35c94;hb=3e91848cbe3dad23fdb60962fa9b678592591c34;hpb=950eed9ace2ceff30b88c20de1ef8a0ba05ac567 diff --git a/test/color_name.h b/test/color_name.h index ff82d464..0dadd2a1 100644 --- a/test/color_name.h +++ b/test/color_name.h @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 2011 Free Software Foundation, Inc. * + * Copyright 2018,2020 Thomas E. Dickey * + * Copyright 2011-2012,2016 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -26,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: color_name.h,v 1.2 2011/04/23 17:15:01 tom Exp $ + * $Id: color_name.h,v 1.7 2020/02/02 23:34:34 tom Exp $ */ #ifndef __COLORNAME_H @@ -64,7 +65,7 @@ color_code(const char *color) char *endp = 0; size_t n; - if ((result = strtol(color, &endp, 0)) >= 0 + if ((result = (int) strtol(color, &endp, 0)) >= 0 && (endp == 0 || *endp == 0)) { ; } else if (!strcmp(color, "default")) { @@ -79,7 +80,7 @@ color_code(const char *color) } return result; } -#endif /* NEED_COLOR_NAME */ +#endif /* NEED_COLOR_CODE */ #ifdef NEED_COLOR_NAME static const char * @@ -88,8 +89,8 @@ color_name(int color) static char temp[20]; const char *result = 0; - if (color > (int) SIZEOF(the_color_names)) { - sprintf(temp, "%d", color); + if (color >= (int) SIZEOF(the_color_names)) { + _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(result)) "%d", color); result = temp; } else if (color < 0) { result = "default";