From 0f7a5e70b0c18806962030f9ffb15bdaaa18c495 Mon Sep 17 00:00:00 2001 From: pjrm Date: Mon, 13 Mar 2006 02:56:37 +0000 Subject: [PATCH] (sp_svg_write_color): Change 2nd arg (buflen) from signed to unsigned int. (sp_svg_write_color): Require buflen >= 8. (All existing callers already conform.) doc: Remove out-of-date (and incorrect: cannot have space in `rgb(' for CSS colors) todo comment. noop: SP_SVG_NUMCOLORS is used in only one place; replace it with inline G_N_ELEMENTS(...). --- src/svg/svg-color.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/svg/svg-color.cpp b/src/svg/svg-color.cpp index 5a7602e4f..613d97c0b 100644 --- a/src/svg/svg-color.cpp +++ b/src/svg/svg-color.cpp @@ -18,6 +18,7 @@ #endif #include +#include #include #include #include @@ -182,8 +183,6 @@ static SPSVGColor const sp_svg_color_named[] = { { 0x9ACD32, "yellowgreen" } }; -#define SP_SVG_NUMCOLORS (sizeof(sp_svg_color_named) / sizeof(sp_svg_color_named[0])) - static GHashTable *sp_svg_create_color_hash(); guint32 @@ -193,11 +192,6 @@ sp_svg_read_color(gchar const *str, guint32 def) gchar c[32]; guint32 val = 0; - /* - * todo: handle the rgb (r, g, b) and rgb ( r%, g%, b%), syntax - * defined in http://www.w3.org/TR/REC-CSS2/syndata.html#color-units - */ - if (str == NULL) return def; while ((*str <= ' ') && *str) str++; if (!*str) return def; @@ -306,9 +300,13 @@ sp_svg_read_color(gchar const *str, guint32 def) return (val << 8); } +/** + * \pre buflen \>= 8. + */ gint -sp_svg_write_color(gchar *buf, gint buflen, guint32 color) +sp_svg_write_color(gchar *buf, unsigned const buflen, guint32 const color) { + g_assert(8 <= buflen); return g_snprintf(buf, buflen, "#%06x", color >> 8); } @@ -317,7 +315,7 @@ sp_svg_create_color_hash() { GHashTable *colors = g_hash_table_new(g_str_hash, g_str_equal); - for (unsigned i = 0 ; i < SP_SVG_NUMCOLORS ; i++) { + for (unsigned i = 0 ; i < G_N_ELEMENTS(sp_svg_color_named) ; i++) { g_hash_table_insert(colors, (gpointer)(sp_svg_color_named[i].name), (gpointer)(&sp_svg_color_named[i].rgb)); -- 2.30.2