--- parser3/src/main/pa_string.C 2015/05/30 22:55:29 1.248 +++ parser3/src/main/pa_string.C 2015/10/09 16:03:28 1.252 @@ -12,14 +12,18 @@ #include "pa_charset.h" #include "pa_vregex.h" -volatile const char * IDENT_PA_STRING_C="$Id: pa_string.C,v 1.248 2015/05/30 22:55:29 moko Exp $" IDENT_PA_STRING_H; +#ifndef ULLONG_MAX +#define ULLONG_MAX 18446744073709551615ULL +#endif + +volatile const char * IDENT_PA_STRING_C="$Id: pa_string.C,v 1.252 2015/10/09 16:03:28 moko Exp $" IDENT_PA_STRING_H; const String String::Empty; // pa_atoui is based on Manuel Novoa III _strto_l for uClibc -unsigned int pa_atoui(const char *str, int base, const String* problem_source){ - unsigned int result = 0; +template inline T pa_ato_any(const char *str, int base, const String* problem_source,const T max){ + T result = 0; const char *pos = str; while (isspace(*pos)) /* skip leading whitespace */ @@ -47,8 +51,8 @@ unsigned int pa_atoui(const char *str, i throw Exception(PARSER_RUNTIME, 0, "base to must be an integer from 2 to 16"); } - unsigned int cutoff = UINT_MAX / base; - int cutoff_digit = UINT_MAX - cutoff * base; + T cutoff = max / base; + int cutoff_digit = (int)(max - cutoff * base); while(true) { int digit; @@ -82,6 +86,14 @@ unsigned int pa_atoui(const char *str, i return result; } +unsigned int pa_atoui(const char *str, int base, const String* problem_source){ + return pa_ato_any(str, base, problem_source, UINT_MAX); +} + +unsigned long long pa_atoul(const char *str, int base, const String* problem_source){ + return pa_ato_any(str, base, problem_source, ULLONG_MAX); +} + int pa_atoi(const char* str, const String* problem_source) { if(!str) return 0; @@ -133,7 +145,7 @@ double pa_atod(const char* str, const St if(str[0]=='0') { if(str[1]=='x' || str[1]=='X') { // 0xABC - result=(double)pa_atoui(str, 0, problem_source); + result=(double)pa_atoul(str, 0, problem_source); return negative ? -result : result; } else { // skip leading 0000, to disable octal interpretation @@ -359,7 +371,7 @@ uint String::Body::get_hash_code() const uint hash_code=0; #endif if (body && CORD_IS_STRING(body)){ - generic_hash_code(hash_code, body); + generic_hash_code(hash_code, (const char *)body); } else { CORD_iter5(body, 0, CORD_batched_iter_fn_generic_hash_code, @@ -902,10 +914,7 @@ bool String::deserialize(size_t prolog_s if(cur[body_length] != 0) // in place? return false; // 3: letters - body=String::Body(*cur?cur:0); -#ifdef STRING_LENGTH_CACHING - body.set_length(body_length); -#endif + body=String::Body(String::C(cur, body_length)); cur+=body_length+1; in_buf-=body_length+1;