From 08d50dc725ab630fccdb8f0a1e01bce512a31c42 Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 13 Nov 2015 19:38:46 +0100 Subject: [PATCH] Changed: Don't try to convert string to CRGBA if less than 3 integers --HG-- branch : develop --- code/nel/src/misc/rgba.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/code/nel/src/misc/rgba.cpp b/code/nel/src/misc/rgba.cpp index 944ca50d3..822ee1006 100644 --- a/code/nel/src/misc/rgba.cpp +++ b/code/nel/src/misc/rgba.cpp @@ -734,17 +734,23 @@ void CRGBA::buildFromHLS(float h, float l, float s) CRGBA CRGBA::stringToRGBA( const char *ptr ) { - if (!ptr) - return NLMISC::CRGBA::White; + if (ptr) + { + int r = 255, g = 255, b = 255, a = 255; + + // we need at least 3 integer values to consider string is valid + if (sscanf( ptr, "%d %d %d %d", &r, &g, &b, &a ) >= 3) + { + clamp( r, 0, 255 ); + clamp( g, 0, 255 ); + clamp( b, 0, 255 ); + clamp( a, 0, 255 ); - int r = 255, g = 255, b = 255, a = 255; - sscanf( ptr, "%d %d %d %d", &r, &g, &b, &a ); - clamp( r, 0, 255 ); - clamp( g, 0, 255 ); - clamp( b, 0, 255 ); - clamp( a, 0, 255 ); - - return CRGBA( r,g,b,a ); + return CRGBA( r,g,b,a ); + } + } + + return NLMISC::CRGBA::White; } std::string CRGBA::toString() const