Browse Source

Fixed <number> handling in hsl/hsla color parser.

parseNumber() was erroring out on numbers with long fractional parts.
v1.x
motiz88 10 years ago
parent
commit
3951221166
  1. 29
      src/color.cc

29
src/color.cc

@ -8,6 +8,7 @@
#include "color.h" #include "color.h"
#include <stdlib.h> #include <stdlib.h>
#include <cmath> #include <cmath>
#include <limits>
/* /*
* Consume whitespace. * Consume whitespace.
@ -72,6 +73,7 @@ static bool parseNumber(const char** pStr, parsed_t *pParsed)
int divisorForFraction = 1; int divisorForFraction = 1;
int sign = 1; int sign = 1;
int exponent = 0; int exponent = 0;
int digits = 0;
bool inFraction = false; bool inFraction = false;
if (*str == '-') if (*str == '-')
@ -87,15 +89,24 @@ static bool parseNumber(const char** pStr, parsed_t *pParsed)
{ {
if (*str >= '0' && *str <= '9') if (*str >= '0' && *str <= '9')
{ {
if (inFraction) if (digits>=std::numeric_limits<parsed_t>::digits10)
{ {
fractionPart = fractionPart*10 + (*str - '0'); if (!inFraction)
divisorForFraction *= 10; return false;
} }
else else {
{ ++digits;
integerPart = integerPart*10 + (*str - '0');
} if (inFraction)
{
fractionPart = fractionPart*10 + (*str - '0');
divisorForFraction *= 10;
}
else
{
integerPart = integerPart*10 + (*str - '0');
}
}
} }
else if (*str == '.') else if (*str == '.')
{ {

Loading…
Cancel
Save