diff --git a/.travis.yml b/.travis.yml index 11b155d..8fae22a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ language: cpp matrix: include: - os: linux - dist: trusty + dist: bionic sudo: required compiler: gcc addons: @@ -17,22 +17,17 @@ matrix: - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" - os: linux - dist: trusty + dist: bionic sudo: required compiler: clang addons: apt: - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-trusty-6.0 - - sourceline: 'ppa:ubuntu-toolchain-r/test' packages: - g++-7 - - llvm-6.0 - - clang-6.0 + - clang-7 - libstdc++6 env: - - MATRIX_EVAL="CC=clang-6.0 && CXX=clang++-6.0" + - MATRIX_EVAL="CC=clang-7 && CXX=clang++-7" - os: osx osx_image: xcode8.2 diff --git a/clickhouse/base/coded.cpp b/clickhouse/base/coded.cpp index 9e638ca..fbd29a2 100644 --- a/clickhouse/base/coded.cpp +++ b/clickhouse/base/coded.cpp @@ -45,13 +45,13 @@ bool CodedInputStream::Skip(size_t count) { bool CodedInputStream::ReadVarint64(uint64_t* value) { *value = 0; - for (size_t i = 0; i < 9; ++i) { + for (size_t i = 0; i < MAX_VARINT_BYTES; ++i) { uint8_t byte; if (!input_->ReadByte(&byte)) { return false; } else { - *value |= (byte & 0x7F) << (7 * i); + *value |= uint64_t(byte & 0x7F) << (7 * i); if (!(byte & 0x80)) { return true; @@ -81,7 +81,7 @@ void CodedOutputStream::WriteVarint64(uint64_t value) { uint8_t bytes[MAX_VARINT_BYTES]; int size = 0; - for (size_t i = 0; i < 9; ++i) { + for (size_t i = 0; i < MAX_VARINT_BYTES; ++i) { uint8_t byte = value & 0x7F; if (value > 0x7F) byte |= 0x80; diff --git a/ut/CMakeLists.txt b/ut/CMakeLists.txt index 8267098..1fa66f1 100644 --- a/ut/CMakeLists.txt +++ b/ut/CMakeLists.txt @@ -1,12 +1,13 @@ ADD_EXECUTABLE (clickhouse-cpp-ut main.cpp - columns_ut.cpp - types_ut.cpp - type_parser_ut.cpp client_ut.cpp + columns_ut.cpp socket_ut.cpp + stream_ut.cpp tcp_server.cpp + type_parser_ut.cpp + types_ut.cpp ) TARGET_LINK_LIBRARIES (clickhouse-cpp-ut diff --git a/ut/stream_ut.cpp b/ut/stream_ut.cpp new file mode 100644 index 0000000..b27efb2 --- /dev/null +++ b/ut/stream_ut.cpp @@ -0,0 +1,23 @@ +#include +#include + +using namespace clickhouse; + +TEST(CodedStreamCase, Varint64) { + Buffer buf; + + { + BufferOutput output(&buf); + CodedOutputStream coded(&output); + coded.WriteVarint64(18446744071965638648ULL); + } + + + { + ArrayInput input(buf.data(), buf.size()); + CodedInputStream coded(&input); + uint64_t value; + ASSERT_TRUE(coded.ReadVarint64(&value)); + ASSERT_EQ(value, 18446744071965638648ULL); + } +}