Permalink
Browse files

Compile-time error fix

  • Loading branch information...
1 parent 8168804 commit 1ecf0ab394dd09f973c74be6326953a9d70255ba @saleyn committed Jul 17, 2014
Showing with 19 additions and 8 deletions.
  1. +8 −8 include/utxx/nchar.hpp
  2. +11 −0 test/test_convert.cpp
View
@@ -98,16 +98,16 @@ namespace detail {
char& operator[] (size_t n) { return m_data[n]; }
- const char* data() const { return m_data; }
- char* data() { return m_data; }
- size_t size() const { return N; }
- const char* end() const { return m_data + N; }
+ const char* data() const { return m_data; }
+ char* data() { return m_data; }
+ size_t size() const { return N; }
+ const char* end() const { return m_data + N; }
- operator uint8_t* () const { return reinterpret_cast<uint8_t*>(m_data); }
- operator uint8_t* () { return reinterpret_cast<uint8_t*>(m_data); }
+ operator uint8_t* () const { return reinterpret_cast<uint8_t*>(m_data); }
+ operator uint8_t* () { return reinterpret_cast<uint8_t*>(m_data); }
- operator char* () const { return m_data; }
- operator char* () { return m_data; }
+ operator const char*() const { return m_data; }
+ operator char*() { return m_data; }
std::string to_string(char rtrim = '\0') const {
const char* end = m_data+N;
View
@@ -240,6 +240,16 @@ BOOST_AUTO_TEST_CASE( test_convert )
BOOST_REQUIRE_EQUAL(-1, rp-buf);
}
{
+ char buf[] = {'-',' ',' ','1','0','5'};
+ long n, m;
+ const char* lp = atoi_left(buf, n);
+ const char* rp = atoi_right(buf, m);
+ BOOST_REQUIRE_EQUAL(0, n); // This is really invalid input
+ BOOST_REQUIRE_EQUAL(105, m); // Invalid input
+ BOOST_REQUIRE_EQUAL(1, lp-buf);
+ BOOST_REQUIRE_EQUAL(2, rp-buf);
+ }
+ {
char buf[19];
int64_t n = std::numeric_limits<int64_t>::max();
std::stringstream s; s << n;
@@ -333,6 +343,7 @@ BOOST_AUTO_TEST_CASE( test_convert_unsafe_fixed_atol )
{ "-123 ", -123000, false, 7 }, // 7
{ "-\0\0\000123", -123, false, 7 }, // 8
{ "\0\0\000-123", 0, false, 7 }, // 8
+ { "- 123", -123, true, 7 }, // 9
};
typedef const char* (*fun_u)(const char*, uint64_t&);

0 comments on commit 1ecf0ab

Please sign in to comment.