mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 00:52:02 +00:00
clang-tidy, part 5
This commit is contained in:
parent
44cb1b8305
commit
3f13464e3d
36
.clang-tidy
36
.clang-tidy
@ -123,6 +123,42 @@ Checks: '-*,
|
|||||||
|
|
||||||
hicpp-exception-baseclass,
|
hicpp-exception-baseclass,
|
||||||
|
|
||||||
|
clang-analyzer-core.CallAndMessage,
|
||||||
|
clang-analyzer-core.DivideZero,
|
||||||
|
clang-analyzer-core.NonNullParamChecker,
|
||||||
|
clang-analyzer-core.NullDereference,
|
||||||
|
clang-analyzer-core.StackAddressEscape,
|
||||||
|
clang-analyzer-core.UndefinedBinaryOperatorResult,
|
||||||
|
clang-analyzer-core.VLASize,
|
||||||
|
clang-analyzer-core.uninitialized.ArraySubscript,
|
||||||
|
clang-analyzer-core.uninitialized.Assign,
|
||||||
|
clang-analyzer-core.uninitialized.Branch,
|
||||||
|
clang-analyzer-core.uninitialized.CapturedBlockVariable,
|
||||||
|
clang-analyzer-core.uninitialized.UndefReturn,
|
||||||
|
clang-analyzer-cplusplus.InnerPointer,
|
||||||
|
clang-analyzer-cplusplus.NewDelete,
|
||||||
|
clang-analyzer-cplusplus.NewDeleteLeaks,
|
||||||
|
clang-analyzer-cplusplus.PlacementNewChecker,
|
||||||
|
clang-analyzer-cplusplus.SelfAssignment,
|
||||||
|
clang-analyzer-deadcode.DeadStores,
|
||||||
|
clang-analyzer-optin.cplusplus.VirtualCall,
|
||||||
|
clang-analyzer-security.insecureAPI.UncheckedReturn,
|
||||||
|
clang-analyzer-security.insecureAPI.bcmp,
|
||||||
|
clang-analyzer-security.insecureAPI.bcopy,
|
||||||
|
clang-analyzer-security.insecureAPI.bzero,
|
||||||
|
clang-analyzer-security.insecureAPI.getpw,
|
||||||
|
clang-analyzer-security.insecureAPI.gets,
|
||||||
|
clang-analyzer-security.insecureAPI.mkstemp,
|
||||||
|
clang-analyzer-security.insecureAPI.mktemp,
|
||||||
|
clang-analyzer-security.insecureAPI.rand,
|
||||||
|
clang-analyzer-security.insecureAPI.strcpy,
|
||||||
|
clang-analyzer-unix.Malloc,
|
||||||
|
clang-analyzer-unix.MallocSizeof,
|
||||||
|
clang-analyzer-unix.MismatchedDeallocator,
|
||||||
|
clang-analyzer-unix.Vfork,
|
||||||
|
clang-analyzer-unix.cstring.BadSizeArg,
|
||||||
|
clang-analyzer-unix.cstring.NullArg,
|
||||||
|
|
||||||
boost-use-to-string,
|
boost-use-to-string,
|
||||||
'
|
'
|
||||||
WarningsAsErrors: '*'
|
WarningsAsErrors: '*'
|
||||||
|
@ -215,7 +215,7 @@ JSON::ElementType JSON::getType() const
|
|||||||
|
|
||||||
void JSON::checkPos(Pos pos) const
|
void JSON::checkPos(Pos pos) const
|
||||||
{
|
{
|
||||||
if (pos >= ptr_end)
|
if (pos >= ptr_end || ptr_begin == nullptr)
|
||||||
throw JSONException("JSON: unexpected end of data.");
|
throw JSONException("JSON: unexpected end of data.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ void trim(String & s)
|
|||||||
bool hasInputData()
|
bool hasInputData()
|
||||||
{
|
{
|
||||||
timeval timeout = {0, 0};
|
timeval timeout = {0, 0};
|
||||||
fd_set fds;
|
fd_set fds{};
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(STDIN_FILENO, &fds);
|
FD_SET(STDIN_FILENO, &fds);
|
||||||
return select(1, &fds, nullptr, nullptr, &timeout) == 1;
|
return select(1, &fds, nullptr, nullptr, &timeout) == 1;
|
||||||
|
@ -93,7 +93,7 @@ void MemoryTracker::alloc(Int64 size)
|
|||||||
free(size);
|
free(size);
|
||||||
|
|
||||||
/// Prevent recursion. Exception::ctor -> std::string -> new[] -> MemoryTracker::alloc
|
/// Prevent recursion. Exception::ctor -> std::string -> new[] -> MemoryTracker::alloc
|
||||||
auto untrack_lock = blocker.cancel();
|
auto untrack_lock = blocker.cancel(); // NOLINT
|
||||||
|
|
||||||
std::stringstream message;
|
std::stringstream message;
|
||||||
message << "Memory tracker";
|
message << "Memory tracker";
|
||||||
@ -118,7 +118,7 @@ void MemoryTracker::alloc(Int64 size)
|
|||||||
free(size);
|
free(size);
|
||||||
|
|
||||||
/// Prevent recursion. Exception::ctor -> std::string -> new[] -> MemoryTracker::alloc
|
/// Prevent recursion. Exception::ctor -> std::string -> new[] -> MemoryTracker::alloc
|
||||||
auto untrack_lock = blocker.cancel();
|
auto untrack_lock = blocker.cancel(); // NOLINT
|
||||||
|
|
||||||
std::stringstream message;
|
std::stringstream message;
|
||||||
message << "Memory limit";
|
message << "Memory limit";
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Core/Types.h>
|
#include <Core/Types.h>
|
||||||
|
#include <Common/PODArray.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
@ -32,15 +33,7 @@ private:
|
|||||||
size_t m = lhs.size();
|
size_t m = lhs.size();
|
||||||
size_t n = rhs.size();
|
size_t n = rhs.size();
|
||||||
|
|
||||||
static constexpr size_t small_buffer_size = 64;
|
PODArrayWithStackMemory<size_t, 64> row(n + 1);
|
||||||
size_t small_buffer[small_buffer_size];
|
|
||||||
std::unique_ptr<size_t[]> alloc_buffer;
|
|
||||||
size_t * row = small_buffer;
|
|
||||||
if (n + 1 > small_buffer_size)
|
|
||||||
{
|
|
||||||
row = new size_t[n + 1];
|
|
||||||
alloc_buffer.reset(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= n; ++i)
|
for (size_t i = 1; i <= n; ++i)
|
||||||
row[i] = i;
|
row[i] = i;
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <boost/algorithm/string.hpp>
|
|
||||||
|
|
||||||
#include <common/logger_useful.h>
|
#include <common/logger_useful.h>
|
||||||
|
#include <common/find_symbols.h>
|
||||||
#include <Common/StringUtils/StringUtils.h>
|
#include <Common/StringUtils/StringUtils.h>
|
||||||
#include <Common/PODArray.h>
|
#include <Common/PODArray.h>
|
||||||
#include <Common/thread_local_rng.h>
|
#include <Common/thread_local_rng.h>
|
||||||
@ -61,7 +61,21 @@ void ZooKeeper::init(const std::string & implementation, const std::string & hos
|
|||||||
throw KeeperException("No addresses passed to ZooKeeper constructor.", Coordination::ZBADARGUMENTS);
|
throw KeeperException("No addresses passed to ZooKeeper constructor.", Coordination::ZBADARGUMENTS);
|
||||||
|
|
||||||
std::vector<std::string> addresses_strings;
|
std::vector<std::string> addresses_strings;
|
||||||
boost::split(addresses_strings, hosts, boost::is_any_of(","));
|
|
||||||
|
const char * pos = hosts.data();
|
||||||
|
const char * end = pos + hosts.size();
|
||||||
|
while (pos < end)
|
||||||
|
{
|
||||||
|
const char * comma_or_end = find_first_symbols<','>(pos, end);
|
||||||
|
|
||||||
|
addresses_strings.emplace_back(pos, comma_or_end);
|
||||||
|
|
||||||
|
if (comma_or_end < end)
|
||||||
|
pos = comma_or_end + 1;
|
||||||
|
else
|
||||||
|
pos = comma_or_end;
|
||||||
|
}
|
||||||
|
|
||||||
Coordination::ZooKeeper::Addresses addresses;
|
Coordination::ZooKeeper::Addresses addresses;
|
||||||
addresses.reserve(addresses_strings.size());
|
addresses.reserve(addresses_strings.size());
|
||||||
|
|
||||||
|
@ -30,15 +30,15 @@ static void dummyFunctionForInterposing() __attribute__((used));
|
|||||||
static void dummyFunctionForInterposing()
|
static void dummyFunctionForInterposing()
|
||||||
{
|
{
|
||||||
void* dummy;
|
void* dummy;
|
||||||
/// Suppression for PVS-Studio.
|
/// Suppression for PVS-Studio and clang-tidy.
|
||||||
free(nullptr); // -V575
|
free(nullptr); // -V575 NOLINT
|
||||||
ignore(malloc(0)); // -V575
|
ignore(malloc(0)); // -V575 NOLINT
|
||||||
ignore(calloc(0, 0)); // -V575
|
ignore(calloc(0, 0)); // -V575 NOLINT
|
||||||
ignore(realloc(nullptr, 0)); // -V575
|
ignore(realloc(nullptr, 0)); // -V575 NOLINT
|
||||||
ignore(posix_memalign(&dummy, 0, 0)); // -V575
|
ignore(posix_memalign(&dummy, 0, 0)); // -V575 NOLINT
|
||||||
ignore(aligned_alloc(0, 0)); // -V575
|
ignore(aligned_alloc(0, 0)); // -V575 NOLINT
|
||||||
ignore(valloc(0)); // -V575
|
ignore(valloc(0)); // -V575 NOLINT
|
||||||
ignore(memalign(0, 0)); // -V575
|
ignore(memalign(0, 0)); // -V575 NOLINT
|
||||||
ignore(pvalloc(0)); // -V575
|
ignore(pvalloc(0)); // -V575 NOLINT
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,7 +19,7 @@ std::pair<std::string, UInt16> parseAddress(const std::string & str, UInt16 defa
|
|||||||
|
|
||||||
const char * begin = str.data();
|
const char * begin = str.data();
|
||||||
const char * end = begin + str.size();
|
const char * end = begin + str.size();
|
||||||
const char * port = end;
|
const char * port = end; // NOLINT
|
||||||
|
|
||||||
if (begin[0] == '[')
|
if (begin[0] == '[')
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#include "CompressedReadBufferBase.h"
|
#include "CompressedReadBufferBase.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
|
#include <cassert>
|
||||||
#include <city.h>
|
#include <city.h>
|
||||||
#include <Common/PODArray.h>
|
#include <Common/PODArray.h>
|
||||||
#include <Common/ProfileEvents.h>
|
#include <Common/ProfileEvents.h>
|
||||||
@ -118,6 +119,8 @@ size_t CompressedReadBufferBase::readCompressedData(size_t & size_decompressed,
|
|||||||
size_compressed_without_checksum = ICompressionCodec::readCompressedBlockSize(own_compressed_buffer.data());
|
size_compressed_without_checksum = ICompressionCodec::readCompressedBlockSize(own_compressed_buffer.data());
|
||||||
size_decompressed = ICompressionCodec::readDecompressedBlockSize(own_compressed_buffer.data());
|
size_decompressed = ICompressionCodec::readDecompressedBlockSize(own_compressed_buffer.data());
|
||||||
|
|
||||||
|
assert(size_decompressed > 0);
|
||||||
|
|
||||||
if (size_compressed_without_checksum > DBMS_MAX_COMPRESSED_SIZE)
|
if (size_compressed_without_checksum > DBMS_MAX_COMPRESSED_SIZE)
|
||||||
throw Exception("Too large size_compressed_without_checksum: "
|
throw Exception("Too large size_compressed_without_checksum: "
|
||||||
+ toString(size_compressed_without_checksum)
|
+ toString(size_compressed_without_checksum)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include "CompressedReadBufferFromFile.h"
|
#include "CompressedReadBufferFromFile.h"
|
||||||
|
|
||||||
#include <Compression/CompressionInfo.h>
|
#include <Compression/CompressionInfo.h>
|
||||||
@ -16,12 +18,14 @@ namespace ErrorCodes
|
|||||||
|
|
||||||
bool CompressedReadBufferFromFile::nextImpl()
|
bool CompressedReadBufferFromFile::nextImpl()
|
||||||
{
|
{
|
||||||
size_t size_decompressed;
|
size_t size_decompressed = 0;
|
||||||
size_t size_compressed_without_checksum;
|
size_t size_compressed_without_checksum;
|
||||||
size_compressed = readCompressedData(size_decompressed, size_compressed_without_checksum);
|
size_compressed = readCompressedData(size_decompressed, size_compressed_without_checksum);
|
||||||
if (!size_compressed)
|
if (!size_compressed)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
assert(size_decompressed > 0);
|
||||||
|
|
||||||
memory.resize(size_decompressed + codec->getAdditionalSizeAtTheEndOfBuffer());
|
memory.resize(size_decompressed + codec->getAdditionalSizeAtTheEndOfBuffer());
|
||||||
working_buffer = Buffer(memory.data(), &memory[size_decompressed]);
|
working_buffer = Buffer(memory.data(), &memory[size_decompressed]);
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include <Columns/ColumnsNumber.h>
|
#include <Columns/ColumnsNumber.h>
|
||||||
#include <Common/typeid_cast.h>
|
#include <Common/typeid_cast.h>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
@ -115,6 +117,8 @@ private:
|
|||||||
|
|
||||||
MergingBlockPtr & operator=(const MergingBlockPtr & rhs)
|
MergingBlockPtr & operator=(const MergingBlockPtr & rhs)
|
||||||
{
|
{
|
||||||
|
assert(ptr != rhs.ptr);
|
||||||
|
|
||||||
destroy();
|
destroy();
|
||||||
ptr = rhs.ptr;
|
ptr = rhs.ptr;
|
||||||
if (ptr)
|
if (ptr)
|
||||||
|
@ -444,7 +444,7 @@ void HashedDictionary::addAttributeSize(const Attribute & attribute)
|
|||||||
bucket_count = map_ref->bucket_count();
|
bucket_count = map_ref->bucket_count();
|
||||||
|
|
||||||
/** TODO: more accurate calculation */
|
/** TODO: more accurate calculation */
|
||||||
bytes_allocated += sizeof(CollectionType<T>);
|
bytes_allocated += sizeof(SparseCollectionType<T>);
|
||||||
bytes_allocated += bucket_count;
|
bytes_allocated += bucket_count;
|
||||||
bytes_allocated += map_ref->size() * (sizeof(Key) + sizeof(T));
|
bytes_allocated += map_ref->size() * (sizeof(Key) + sizeof(T));
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
#include <Common/BitHelpers.h>
|
#include <Common/BitHelpers.h>
|
||||||
#include <Common/Exception.h>
|
#include <Common/Exception.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#if defined(__OpenBSD__) || defined(__FreeBSD__)
|
#if defined(__OpenBSD__) || defined(__FreeBSD__)
|
||||||
# include <sys/endian.h>
|
# include <sys/endian.h>
|
||||||
@ -115,6 +116,8 @@ private:
|
|||||||
template <GetBitsMode mode>
|
template <GetBitsMode mode>
|
||||||
inline UInt64 getBitsFromBitBuffer(UInt8 bits_to_read)
|
inline UInt64 getBitsFromBitBuffer(UInt8 bits_to_read)
|
||||||
{
|
{
|
||||||
|
assert(bits_to_read > 0);
|
||||||
|
|
||||||
// push down the high-bits
|
// push down the high-bits
|
||||||
const UInt64 result = static_cast<UInt64>(bits_buffer >> (sizeof(bits_buffer) * 8 - bits_to_read));
|
const UInt64 result = static_cast<UInt64>(bits_buffer >> (sizeof(bits_buffer) * 8 - bits_to_read));
|
||||||
|
|
||||||
@ -186,6 +189,8 @@ public:
|
|||||||
// write `bits_to_write` low-bits of `value` to the buffer
|
// write `bits_to_write` low-bits of `value` to the buffer
|
||||||
inline void writeBits(UInt8 bits_to_write, UInt64 value)
|
inline void writeBits(UInt8 bits_to_write, UInt64 value)
|
||||||
{
|
{
|
||||||
|
assert(bits_to_write > 0);
|
||||||
|
|
||||||
UInt32 capacity = BIT_BUFFER_SIZE - bits_count;
|
UInt32 capacity = BIT_BUFFER_SIZE - bits_count;
|
||||||
if (capacity < bits_to_write)
|
if (capacity < bits_to_write)
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,7 @@ namespace DB
|
|||||||
|
|
||||||
/** Class for asynchronous data reading.
|
/** Class for asynchronous data reading.
|
||||||
*/
|
*/
|
||||||
class ReadBufferAIO : public ReadBufferFromFileBase
|
class ReadBufferAIO final : public ReadBufferFromFileBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ReadBufferAIO(const std::string & filename_, size_t buffer_size_ = DBMS_DEFAULT_BUFFER_SIZE, int flags_ = -1,
|
ReadBufferAIO(const std::string & filename_, size_t buffer_size_ = DBMS_DEFAULT_BUFFER_SIZE, int flags_ = -1,
|
||||||
|
@ -24,7 +24,7 @@ namespace DB
|
|||||||
|
|
||||||
/** Class for asynchronous data writing.
|
/** Class for asynchronous data writing.
|
||||||
*/
|
*/
|
||||||
class WriteBufferAIO : public WriteBufferFromFileBase
|
class WriteBufferAIO final : public WriteBufferFromFileBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WriteBufferAIO(const std::string & filename_, size_t buffer_size_ = DBMS_DEFAULT_BUFFER_SIZE, int flags_ = -1, mode_t mode_ = 0666,
|
WriteBufferAIO(const std::string & filename_, size_t buffer_size_ = DBMS_DEFAULT_BUFFER_SIZE, int flags_ = -1, mode_t mode_ = 0666,
|
||||||
|
@ -41,7 +41,7 @@ namespace DB
|
|||||||
/// Also this class write and flush special X-ClickHouse-Progress HTTP headers
|
/// Also this class write and flush special X-ClickHouse-Progress HTTP headers
|
||||||
/// if no data was sent at the time of progress notification.
|
/// if no data was sent at the time of progress notification.
|
||||||
/// This allows to implement progress bar in HTTP clients.
|
/// This allows to implement progress bar in HTTP clients.
|
||||||
class WriteBufferFromHTTPServerResponse : public BufferWithOwnMemory<WriteBuffer>
|
class WriteBufferFromHTTPServerResponse final : public BufferWithOwnMemory<WriteBuffer>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Poco::Net::HTTPServerRequest & request;
|
Poco::Net::HTTPServerRequest & request;
|
||||||
|
@ -65,7 +65,7 @@ public:
|
|||||||
set(reinterpret_cast<Position>(vector.data() + old_size), (size - old_size) * sizeof(typename VectorType::value_type));
|
set(reinterpret_cast<Position>(vector.data() + old_size), (size - old_size) * sizeof(typename VectorType::value_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
void finalize() override
|
void finalize() override final
|
||||||
{
|
{
|
||||||
if (is_finished)
|
if (is_finished)
|
||||||
return;
|
return;
|
||||||
|
@ -11,7 +11,7 @@ namespace DB
|
|||||||
* If the valid UTF-8 is already written, it works faster.
|
* If the valid UTF-8 is already written, it works faster.
|
||||||
* Note: before using the resulting string, destroy this object.
|
* Note: before using the resulting string, destroy this object.
|
||||||
*/
|
*/
|
||||||
class WriteBufferValidUTF8 : public BufferWithOwnMemory<WriteBuffer>
|
class WriteBufferValidUTF8 final : public BufferWithOwnMemory<WriteBuffer>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
WriteBuffer & output_buffer;
|
WriteBuffer & output_buffer;
|
||||||
|
@ -37,7 +37,7 @@ TEST_P(DateTime64StringParseTest, readDateTime64Text)
|
|||||||
const auto & param = GetParam();
|
const auto & param = GetParam();
|
||||||
ReadBufferFromMemory read_buffer(param.string.data(), param.string.size());
|
ReadBufferFromMemory read_buffer(param.string.data(), param.string.size());
|
||||||
|
|
||||||
DateTime64 actual;
|
DateTime64 actual{};
|
||||||
EXPECT_TRUE(tryReadDateTime64Text(actual, param.scale, read_buffer, param.timezone));
|
EXPECT_TRUE(tryReadDateTime64Text(actual, param.scale, read_buffer, param.timezone));
|
||||||
|
|
||||||
EXPECT_EQ(param.dt64, actual);
|
EXPECT_EQ(param.dt64, actual);
|
||||||
|
Loading…
Reference in New Issue
Block a user