Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions clickhouse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ SET ( clickhouse-cpp-lib-src
query.cpp
)

if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_compile_options(/W4)
# remove in 3.0
add_compile_options(/wd4996)
else()
set(cxx_extra_wall "-Wempty-body -Wconversion -Wreturn-type -Wparentheses -Wuninitialized -Wunreachable-code -Wunused-function -Wunused-value -Wunused-variable")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${cxx_extra_wall}")

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# a little abnormal when clang check conversion
Comment thread
1261385937 marked this conversation as resolved.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${cxx_extra_wall} -Wno-conversion")
endif()
endif()

IF (WITH_OPENSSL)
LIST(APPEND clickhouse-cpp-lib-src base/sslsocket.cpp)
ENDIF ()
Expand Down
4 changes: 2 additions & 2 deletions clickhouse/base/compressed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool CompressedInput::Decompress() {

data_ = Buffer(original);

if (LZ4_decompress_safe((const char*)tmp.data() + HEADER_SIZE, (char*)data_.data(), compressed - HEADER_SIZE, original) < 0) {
if (LZ4_decompress_safe((const char*)tmp.data() + HEADER_SIZE, (char*)data_.data(), static_cast<int>(compressed - HEADER_SIZE), original) < 0) {
throw LZ4Error("can't decompress data");
} else {
mem_.Reset(data_.data(), original);
Expand Down Expand Up @@ -141,7 +141,7 @@ void CompressedOutput::Compress(const void * data, size_t len) {
const auto compressed_size = LZ4_compress_default(
(const char*)data,
(char*)compressed_buffer_.data() + HEADER_SIZE,
len,
static_cast<int>(len),
static_cast<int>(compressed_buffer_.size() - HEADER_SIZE));
if (compressed_size <= 0)
throw LZ4Error("Failed to compress chunk of " + std::to_string(len) + " bytes, "
Expand Down
2 changes: 1 addition & 1 deletion clickhouse/base/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ SOCKET SocketConnect(const NetworkAddress& addr, const SocketTimeoutParams& time
fd.fd = *s;
fd.events = POLLOUT;
fd.revents = 0;
ssize_t rval = Poll(&fd, 1, timeout_params.connect_timeout.count());
ssize_t rval = Poll(&fd, 1, static_cast<int>(timeout_params.connect_timeout.count()));

if (rval == -1) {
throw std::system_error(getSocketErrorCode(), getErrorCategory(), "fail to connect");
Expand Down
12 changes: 8 additions & 4 deletions clickhouse/base/sslsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ SSL_CTX * prepareSSLContext(const clickhouse::SSLParams & context_params) {

#define HANDLE_SSL_CTX_ERROR(statement) do { \
if (const auto ret_code = (statement); !ret_code) \
throwSSLError(nullptr, ERR_peek_error(), LOCATION, #statement); \
throwSSLError(nullptr, static_cast<int>(ERR_peek_error()), LOCATION, #statement); \
} while(false);

if (context_params.use_default_ca_locations)
Expand Down Expand Up @@ -185,7 +185,7 @@ SSL_CTX * SSLContext::getContext() {
// Allows caller to use returned value of `statement` if there was no error, throws exception otherwise.
#define HANDLE_SSL_ERROR(SSL_PTR, statement) [&] { \
if (const auto ret_code = (statement); ret_code <= 0) { \
throwSSLError(SSL_PTR, SSL_get_error(SSL_PTR, ret_code), LOCATION, #statement); \
throwSSLError(SSL_PTR, SSL_get_error(SSL_PTR, static_cast<int>(ret_code)), LOCATION, #statement); \
Comment thread
1261385937 marked this conversation as resolved.
return static_cast<std::decay_t<decltype(ret_code)>>(0); \
} \
else \
Expand All @@ -209,7 +209,7 @@ SSLSocket::SSLSocket(const NetworkAddress& addr, const SocketTimeoutParams& time

std::unique_ptr<ASN1_OCTET_STRING, decltype(&ASN1_OCTET_STRING_free)> ip_addr(a2i_IPADDRESS(addr.Host().c_str()), &ASN1_OCTET_STRING_free);

HANDLE_SSL_ERROR(ssl, SSL_set_fd(ssl, handle_));
HANDLE_SSL_ERROR(ssl, SSL_set_fd(ssl, static_cast<int>(handle_)));
if (ssl_params.use_SNI)
HANDLE_SSL_ERROR(ssl, SSL_set_tlsext_host_name(ssl, addr.Host().c_str()));

Expand Down Expand Up @@ -295,7 +295,11 @@ SSLSocketOutput::SSLSocketOutput(SSL *ssl)
{}

size_t SSLSocketOutput::DoWrite(const void* data, size_t len) {
return static_cast<size_t>(HANDLE_SSL_ERROR(ssl_, SSL_write(ssl_, data, len)));
if (len > std::numeric_limits<int>::max())
// FIXME(vnemkov): We should do multiple `SSL_write`s in this case.
throw AssertionError("Failed to write too big chunk at once "
+ std::to_string(len) + " > " + std::to_string(std::numeric_limits<int>::max()));
return static_cast<size_t>(HANDLE_SSL_ERROR(ssl_, SSL_write(ssl_, data, static_cast<int>(len))));
Comment thread
1261385937 marked this conversation as resolved.
}

#undef HANDLE_SSL_ERROR
Expand Down
10 changes: 4 additions & 6 deletions clickhouse/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,12 @@ bool Client::Impl::ReceivePacket(uint64_t* server_packet) {
if (!WireFormat::ReadUInt64(*input_, &info.bytes)) {
return false;
}
if (REVISION >= DBMS_MIN_REVISION_WITH_TOTAL_ROWS_IN_PROGRESS) {
if constexpr(REVISION >= DBMS_MIN_REVISION_WITH_TOTAL_ROWS_IN_PROGRESS) {
if (!WireFormat::ReadUInt64(*input_, &info.total_rows)) {
return false;
}
}
if (REVISION >= DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO)
if constexpr (REVISION >= DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO)
{
if (!WireFormat::ReadUInt64(*input_, &info.written_rows)) {
return false;
Expand Down Expand Up @@ -499,13 +499,11 @@ bool Client::Impl::ReceivePacket(uint64_t* server_packet) {
throw UnimplementedError("unimplemented " + std::to_string((int)packet_type));
break;
}

return false;
}

bool Client::Impl::ReadBlock(InputStream& input, Block* block) {
// Additional information about block.
if (REVISION >= DBMS_MIN_REVISION_WITH_BLOCK_INFO) {
if constexpr (REVISION >= DBMS_MIN_REVISION_WITH_BLOCK_INFO) {
uint64_t num;
BlockInfo info;

Expand Down Expand Up @@ -569,7 +567,7 @@ bool Client::Impl::ReadBlock(InputStream& input, Block* block) {
bool Client::Impl::ReceiveData() {
Block block;

if (REVISION >= DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES) {
if constexpr (REVISION >= DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES) {
if (!WireFormat::SkipString(*input_)) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions clickhouse/columns/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void ColumnEnum<T>::Append(const T& value, bool checkValue) {

template <typename T>
void ColumnEnum<T>::Append(const std::string& name) {
data_.push_back(type_->As<EnumType>()->GetEnumValue(name));
data_.push_back(static_cast<T>(type_->As<EnumType>()->GetEnumValue(name)));
}

template <typename T>
Expand Down Expand Up @@ -63,7 +63,7 @@ void ColumnEnum<T>::SetAt(size_t n, const T& value, bool checkValue) {

template <typename T>
void ColumnEnum<T>::SetNameAt(size_t n, const std::string& name) {
data_.at(n) = type_->As<EnumType>()->GetEnumValue(name);
data_.at(n) = static_cast<T>(type_->As<EnumType>()->GetEnumValue(name));
}

template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion clickhouse/columns/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const auto& GetASTChildElement(const TypeAst & ast, int position) {
throw ValidationError("AST child element index out of bounds: " + std::to_string(position));

if (position < 0)
position = ast.elements.size() + position;
position = static_cast<int>(ast.elements.size() + position);

return ast.elements[static_cast<size_t>(position)];
}
Expand Down
2 changes: 1 addition & 1 deletion clickhouse/columns/lowcardinality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ std::uint64_t ColumnLowCardinality::getDictionaryIndex(std::uint64_t item_index)
void ColumnLowCardinality::appendIndex(std::uint64_t item_index) {
// TODO (nemkov): handle case when index should go from UInt8 to UInt16, etc.
VisitIndexColumn([item_index](auto & arg) {
arg.Append(item_index);
arg.Append(static_cast<typename std::decay_t<decltype(arg)>::DataType>(item_index));
}, *index_column_);
}

Expand Down