From 2a2effa4ff4838029a53f78ea181f262ff8380bd Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 1 Jun 2010 22:41:44 -0300 Subject: [PATCH] Fixed color_to_formalstring() for invalid colors. --- src/core/color.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/core/color.cpp b/src/core/color.cpp index f45a747df..6d6a4e6a2 100644 --- a/src/core/color.cpp +++ b/src/core/color.cpp @@ -755,17 +755,20 @@ void color_to_formalstring(int imgtype, color_t color, data); break; - case COLOR_TYPE_INDEX: { - ase_uint32 _c; + case COLOR_TYPE_INDEX: data = GET_COLOR_DATA_INDEX(color); - _c = get_current_palette()->getEntry(data & 0xff); - uszprintf(buf, size, "Index %d (RGB %d %d %d)", - data & 0xff, - _rgba_getr(_c), - _rgba_getg(_c), - _rgba_getb(_c)); + if (data >= 0 && data < (int)get_current_palette()->size()) { + ase_uint32 _c = get_current_palette()->getEntry(data); + uszprintf(buf, size, "Index %d (RGB %d %d %d)", + data, + _rgba_getr(_c), + _rgba_getg(_c), + _rgba_getb(_c)); + } + else { + uszprintf(buf, size, "Index %d (out of range)", data); + } break; - } default: assert(false);