From c6683d1e1bec99fed42d8a6534cfb717c1fec805 Mon Sep 17 00:00:00 2001 From: stefanocasazza Date: Fri, 14 Oct 2016 17:55:51 +0200 Subject: [PATCH] fix --- include/ulib/base/utility.h | 6 +++- src/ulib/base/utility.c | 7 ++--- src/ulib/json/value.cpp | 17 ++++++----- src/ulib/string.cpp | 10 ++++--- src/ulib/tokenizer.cpp | 44 +++++++++++++++++----------- tests/ulib/plugin/.deps/product1.Plo | 4 +-- tests/ulib/plugin/.deps/product2.Plo | 4 +-- tests/ulib/ssl_client_server.test | 2 +- 8 files changed, 56 insertions(+), 38 deletions(-) diff --git a/include/ulib/base/utility.h b/include/ulib/base/utility.h index d9ba231d..306b001e 100644 --- a/include/ulib/base/utility.h +++ b/include/ulib/base/utility.h @@ -523,6 +523,7 @@ static inline unsigned long u_strtoul(const char* restrict s, const char* restri U_INTERNAL_ASSERT_POINTER(s) U_INTERNAL_ASSERT_POINTER(e) +#ifndef U_COVERITY_FALSE_POSITIVE /* Control flow issues (MISSING_BREAK) */ switch (len) { case 10: val += (s[len-10] - '0') * 1000000000UL; @@ -536,6 +537,7 @@ static inline unsigned long u_strtoul(const char* restrict s, const char* restri case 2: val += (s[len- 2] - '0') * 10UL; case 1: val += (s[len- 1] - '0'); } +#endif U_INTERNAL_PRINT("val = %lu", val) @@ -552,6 +554,7 @@ static inline uint64_t u_strtoull(const char* restrict s, const char* restrict e U_INTERNAL_ASSERT_POINTER(s) U_INTERNAL_ASSERT_POINTER(e) +#ifndef U_COVERITY_FALSE_POSITIVE /* Control flow issues (MISSING_BREAK) */ switch (len) { case 20: val += (s[len-20] - '0') * 10000000000000000000ULL; @@ -575,6 +578,7 @@ static inline uint64_t u_strtoull(const char* restrict s, const char* restrict e case 2: val += (s[len- 2] - '0') * 10ULL; case 1: val += (s[len- 1] - '0'); } +#endif U_INTERNAL_PRINT("val = %llu", val) @@ -583,7 +587,7 @@ static inline uint64_t u_strtoull(const char* restrict s, const char* restrict e extern U_EXPORT long u_strtol( const char* restrict s, const char* restrict e) __pure; extern U_EXPORT int64_t u_strtoll(const char* restrict s, const char* restrict e) __pure; -extern U_EXPORT double u_strtod( const char* restrict s, const char* restrict e, int point_pos) __pure; +extern U_EXPORT double u_strtod( const char* restrict s, const char* restrict e, int pos) __pure; static inline unsigned u__octc2int(unsigned char c) { return ((c - '0') & 07); } diff --git a/src/ulib/base/utility.c b/src/ulib/base/utility.c index 465e9e93..e17b43d2 100644 --- a/src/ulib/base/utility.c +++ b/src/ulib/base/utility.c @@ -135,7 +135,7 @@ __pure int64_t u_strtoll(const char* restrict s, const char* restrict e) return (neg ? -val : val); } -__pure double u_strtod(const char* restrict s, const char* restrict e, int point_pos) +__pure double u_strtod(const char* restrict s, const char* restrict e, int pos) { static const double pow10[] = { 1e+0, @@ -146,11 +146,10 @@ __pure double u_strtod(const char* restrict s, const char* restrict e, int point const char* restrict p; uint64_t integerPart, fractionPart; - U_INTERNAL_TRACE("u_strtod(%p,%p,%d)", s, e, -point_pos) + U_INTERNAL_TRACE("u_strtod(%p,%p,%d)", s, e, pos) U_INTERNAL_ASSERT_POINTER(s) U_INTERNAL_ASSERT_POINTER(e) - U_INTERNAL_ASSERT_MINOR(point_pos, 0) // while (u__isspace(*s)) ++s; @@ -164,7 +163,7 @@ __pure double u_strtod(const char* restrict s, const char* restrict e, int point p = s; - integerPart = u_strtoull(p, (point_pos != (INT_MIN+1) ? (s += -point_pos) : ++s)); + integerPart = u_strtoull(p, (s += ((unsigned char*)&pos)[1])); U_INTERNAL_ASSERT_EQUALS(*s, '.') diff --git a/src/ulib/json/value.cpp b/src/ulib/json/value.cpp index 74b74f50..4ed96193 100644 --- a/src/ulib/json/value.cpp +++ b/src/ulib/json/value.cpp @@ -41,15 +41,16 @@ char* UValue::pstringify; UTokenizer* UValue::ptok; -UValue::UValue(const UString& _key, const UString& value_) +UValue::UValue(const UString& _key, const UString& _value) { - U_TRACE_REGISTER_OBJECT(0, UValue, "%V,%V", _key.rep, value_.rep) + U_TRACE_REGISTER_OBJECT(0, UValue, "%V,%V", _key.rep, _value.rep) parent = prev = next = 0; key = 0; value.ptr_ = 0; + size = _key.size() + _value.size() + U_CONSTANT_SIZE("{\"\": \"\"}"); type_ = OBJECT_VALUE; UValue* child; @@ -60,7 +61,7 @@ UValue::UValue(const UString& _key, const UString& value_) children.tail = child; U_NEW(UString, child->key, UString(_key)); - U_NEW(UString, child->value.ptr_, UString(value_)); + U_NEW(UString, child->value.ptr_, UString(_value)); U_INTERNAL_DUMP("this = %p", this) } @@ -1249,12 +1250,14 @@ case_number: if (type_num != 0) { - if (type_num < 0) + unsigned char* ptr = (unsigned char*)&type_num; + + if (ptr[0] == '-') { type_ = REAL_VALUE; - value.real_ = (type_num == INT_MIN // scientific notation (Ex: 1.45e10) - ? strtod(start, 0) - : u_strtod(start, ptok->getPointer(), type_num)); + value.real_ = (ptr[2] != 0 // scientific notation (Ex: 1.45e10) + ? strtod(start, 0) + : u_strtod(start, ptok->getPointer(), type_num)); U_INTERNAL_DUMP("value.real_ = %g", value.real_) diff --git a/src/ulib/string.cpp b/src/ulib/string.cpp index 220e935e..66f71239 100644 --- a/src/ulib/string.cpp +++ b/src/ulib/string.cpp @@ -2149,11 +2149,13 @@ double UString::strtod() const if (type_num != 0) { - if (type_num < 0) + unsigned char* ptr = (unsigned char*)&type_num; + + if (ptr[0] == '-') { - double real = (type_num == INT_MIN // scientific notation (Ex: 1.45e10) - ? ::strtod(start, 0) - : u_strtod(start, t.getPointer(), type_num)); + double real = (ptr[2] != 0 // scientific notation (Ex: 1.45e10) + ? ::strtod(start, 0) + : u_strtod(start, t.getPointer(), type_num)); U_INTERNAL_DUMP("real = %g", real) diff --git a/src/ulib/tokenizer.cpp b/src/ulib/tokenizer.cpp index 765a0da7..6a374340 100644 --- a/src/ulib/tokenizer.cpp +++ b/src/ulib/tokenizer.cpp @@ -260,9 +260,10 @@ int UTokenizer::getTypeNumber() int type_num = u__isdigit(*(s-1)); - for (const char* start = s; s < end; ++s) + if (s < end) { - char c = *s; + const char* start = s; + char c = *s; U_INTERNAL_DUMP("c = %C type_num = %d", c, type_num) @@ -289,13 +290,13 @@ int UTokenizer::getTypeNumber() { int pos = (s-start); - if (pos == 0) type_num = INT_MIN+1; // -2147483647 - else - { - if (u__isdigit(*(start-1))) ++pos; + U_INTERNAL_DUMP("pos = %u s = %.4S", (s-start), s) - type_num = -pos; - } + unsigned char* ptr = (unsigned char*)&type_num; + + ptr[0] = (unsigned char)'-'; + ptr[1] = (pos == 0 ? 1 : (unsigned char)(u__isdigit(*(start-1)) + ? pos+1 : pos)); while (u__isdigit(*++s)) {} @@ -307,19 +308,30 @@ int UTokenizer::getTypeNumber() } c = *s; - } - U_INTERNAL_DUMP("c = %C type_num = %d", c, type_num) + U_INTERNAL_DUMP("c = %C type_num = [%u:%u:%u:%u]", c, ptr[0], ptr[1], ptr[2], ptr[3]) + } if (u__toupper(c) == 'E') // scientific notation (Ex: 1.45e-10) { - // int pos = (s-start); + int pos = (s-start); U_INTERNAL_DUMP("pos = %u s = %.4S", (s-start), s) + unsigned char* ptr = (unsigned char*)&type_num; + + ptr[0] = (unsigned char)'-'; + ptr[2] = (pos == 0 ? 1 : (unsigned char)(u__isdigit(*(start-1)) + ? pos+1 : pos)); + c = *++s; - if (u__issign(c)) c = *++s; + if (u__issign(c)) + { + ptr[3] = (unsigned char)c; + + c = *++s; + } if (u__isdigit(c)) { @@ -327,15 +339,13 @@ int UTokenizer::getTypeNumber() if (s >= end) s = end; - U_RETURN(INT_MIN); // -2147483648 + U_INTERNAL_DUMP("type_num = [%u:%u:%u:%u]", ptr[0], ptr[1], ptr[2], ptr[3]) + + U_RETURN(type_num); } U_RETURN(0); } - - U_INTERNAL_DUMP("c = %C type_num = %d", c, type_num) - - break; } U_RETURN(type_num); diff --git a/tests/ulib/plugin/.deps/product1.Plo b/tests/ulib/plugin/.deps/product1.Plo index a9ca62ac..c4e1a2cd 100644 --- a/tests/ulib/plugin/.deps/product1.Plo +++ b/tests/ulib/plugin/.deps/product1.Plo @@ -42,7 +42,7 @@ plugin/product1.lo: plugin/product1.cpp /usr/include/stdc-predef.h \ /usr/include/bits/stdlib-bsearch.h /usr/include/bits/stdlib-float.h \ /usr/include/ctype.h ../../include/ulib/base/replace/replace.h \ /usr/src/linux/include/generated/uapi/linux/version.h \ - /opt/openssl/include/openssl/opensslv.h /usr/include/string.h \ + /usr/include/openssl/opensslv.h /usr/include/string.h \ /usr/include/fcntl.h /usr/include/bits/fcntl.h \ /usr/include/bits/fcntl-linux.h /usr/include/errno.h \ /usr/include/bits/errno.h /usr/include/linux/errno.h \ @@ -313,7 +313,7 @@ plugin/product.h: /usr/src/linux/include/generated/uapi/linux/version.h: -/opt/openssl/include/openssl/opensslv.h: +/usr/include/openssl/opensslv.h: /usr/include/string.h: diff --git a/tests/ulib/plugin/.deps/product2.Plo b/tests/ulib/plugin/.deps/product2.Plo index cb1ac687..d2251453 100644 --- a/tests/ulib/plugin/.deps/product2.Plo +++ b/tests/ulib/plugin/.deps/product2.Plo @@ -42,7 +42,7 @@ plugin/product2.lo: plugin/product2.cpp /usr/include/stdc-predef.h \ /usr/include/bits/stdlib-bsearch.h /usr/include/bits/stdlib-float.h \ /usr/include/ctype.h ../../include/ulib/base/replace/replace.h \ /usr/src/linux/include/generated/uapi/linux/version.h \ - /opt/openssl/include/openssl/opensslv.h /usr/include/string.h \ + /usr/include/openssl/opensslv.h /usr/include/string.h \ /usr/include/fcntl.h /usr/include/bits/fcntl.h \ /usr/include/bits/fcntl-linux.h /usr/include/errno.h \ /usr/include/bits/errno.h /usr/include/linux/errno.h \ @@ -313,7 +313,7 @@ plugin/product.h: /usr/src/linux/include/generated/uapi/linux/version.h: -/opt/openssl/include/openssl/opensslv.h: +/usr/include/openssl/opensslv.h: /usr/include/string.h: diff --git a/tests/ulib/ssl_client_server.test b/tests/ulib/ssl_client_server.test index 81816f4b..8e0554a8 100755 --- a/tests/ulib/ssl_client_server.test +++ b/tests/ulib/ssl_client_server.test @@ -9,7 +9,7 @@ rm -rf /tmp/ssl_session.txt start_msg ssl_server start_msg ssl_client - UTRACE="0 5M 0" +#UTRACE="0 5M 0" #UOBJDUMP="0 100k 10" #USIMERR="error.sim" export UTRACE UOBJDUMP USIMERR