Merge branch 'dylan-fix-wrong-coverity-annotations' into 'cnch-ce-merge'

fix(BYT-0000): fix wrong annotations with :FALSE suffix

See merge request dp/ClickHouse!11406
This commit is contained in:
benyucong 2023-06-05 14:08:10 +08:00
parent b77d70bd19
commit 3036317d04
55 changed files with 241 additions and 127 deletions

View File

@ -21,7 +21,8 @@ bool func_wrapper(Func && func, Arg && arg)
template <typename T, T Begin, typename Func, T... Is>
constexpr bool static_for_impl(Func && f, std::integer_sequence<T, Is...>)
{
// coverity[use_after_move:FALSE]
// forward is used on f to do conditional cast on f to the correct value type
// coverity[use_after_move]
return (func_wrapper(std::forward<Func>(f), std::integral_constant<T, Begin + Is>{}) || ...);
}

View File

@ -19,7 +19,8 @@ auto map(const Collection<Params...> & collection, Mapper && mapper)
using value_type = unqualified_t<decltype(mapper(*std::begin(collection)))>;
return Collection<value_type>(
// coverity[use_after_move:FALSE]
// forward is used on f to do conditional cast on f to the correct value type
// coverity[use_after_move]
boost::make_transform_iterator(std::begin(collection), std::forward<Mapper>(mapper)),
boost::make_transform_iterator(std::end(collection), std::forward<Mapper>(mapper)));
}
@ -46,7 +47,8 @@ template <typename ResultCollection, typename Collection, typename Mapper>
auto map(const Collection & collection, Mapper && mapper)
{
return ResultCollection(
// coverity[use_after_move:FALSE]
// forward is used on f to do conditional cast on f to the correct value type
// coverity[use_after_move]
boost::make_transform_iterator(std::begin(collection), std::forward<Mapper>(mapper)),
boost::make_transform_iterator(std::end(collection), std::forward<Mapper>(mapper)));
}

View File

@ -137,7 +137,8 @@ void ODBCBlockInputStream::insertValue(
readDateTimeText(time, in, assert_cast<const DataTypeDateTime *>(data_type.get())->getTimeZone());
if (time < 0)
time = 0;
// coverity[store_truncates_time_t:FALSE]
// readDateTimeText function above will not assign a value greater than UInt32
// coverity[store_truncates_time_t]
assert_cast<ColumnUInt32 &>(column).insertValue(time);
break;
}

View File

@ -396,7 +396,8 @@ void DiskAccessStorage::clear()
{
entries_by_id.clear();
for (auto type : collections::range(EntityType::MAX))
// coverity[overrun-local:FALSE]
// collections::range(MAX_CONDITION_TYPE) give us a range of [0, MAX_CONDITION_TYPE)
// coverity[overrun-local]
entries_by_name_and_type[static_cast<size_t>(type)].clear();
}

View File

@ -147,9 +147,11 @@ EnabledQuota::Interval::Interval()
{
for (auto resource_type : collections::range(MAX_RESOURCE_TYPE))
{
// coverity[overrun-local:FALSE]
// collections::range(MAX_REOURCE_TYPE) should give us a range of [0, MAX_RESOURCE_TYPE)
// coverity[overrun-local]
used[resource_type].store(0);
// coverity[overrun-local:FALSE]
// collections::range(MAX_REOURCE_TYPE) should give us a range of [0, MAX_RESOURCE_TYPE)
// coverity[overrun-local]
max[resource_type] = 0;
}
}
@ -165,9 +167,11 @@ EnabledQuota::Interval & EnabledQuota::Interval::operator =(const Interval & src
end_of_interval.store(src.end_of_interval.load());
for (auto resource_type : collections::range(MAX_RESOURCE_TYPE))
{
// coverity[overrun-local:FALSE]
// collections::range(MAX_REOURCE_TYPE) should give us a range of [0, MAX_RESOURCE_TYPE)
// coverity[overrun-local]
max[resource_type] = src.max[resource_type];
// coverity[overrun-local:FALSE]
// collections::range(MAX_REOURCE_TYPE) should give us a range of [0, MAX_RESOURCE_TYPE)
// coverity[overrun-local]
used[resource_type].store(src.used[resource_type].load());
}
return *this;
@ -193,11 +197,14 @@ std::optional<QuotaUsage> EnabledQuota::Intervals::getUsage(std::chrono::system_
out.end_of_interval = Impl::getEndOfInterval(in, current_time, counters_were_reset);
for (auto resource_type : collections::range(MAX_RESOURCE_TYPE))
{
// coverity[overrun-local:FALSE]
// collections::range(MAX_REOURCE_TYPE) should give us a range of [0, MAX_RESOURCE_TYPE)
// coverity[overrun-local]
if (in.max[resource_type])
// coverity[overrun-local:FALSE]
// collections::range(MAX_REOURCE_TYPE) should give us a range of [0, MAX_RESOURCE_TYPE)
// coverity[overrun-local]
out.max[resource_type] = in.max[resource_type];
// coverity[overrun-local:FALSE]
// collections::range(MAX_REOURCE_TYPE) should give us a range of [0, MAX_RESOURCE_TYPE)
// coverity[overrun-local]
out.used[resource_type] = in.used[resource_type];
}
}

View File

@ -376,7 +376,8 @@ void MultipleAccessStorage::updateSubscriptionsToNestedStorages(std::unique_lock
for (const auto & handler : handlers_by_type[static_cast<size_t>(type)])
notifications.push_back({handler, id, entity});
};
// coverity[overrun-local:FALSE]
// uses boost_count_range in the underlying implementation, which is end exclusive
// coverity[overrun-local]
for (auto & [storage, subscription] : added_subscriptions[static_cast<size_t>(type)])
subscription = storage->subscribeForChanges(type, on_changed);
}

View File

@ -127,9 +127,11 @@ boost::shared_ptr<const EnabledQuota::Intervals> QuotaCache::QuotaInfo::rebuildI
for (auto resource_type : collections::range(MAX_RESOURCE_TYPE))
{
if (limits.max[resource_type])
// coverity[overrun-local:FALSE]
// collections::range(MAX_REOURCE_TYPE) give us a range of [0, MAX_RESOURCE_TYPE)
// coverity[overrun-local]
interval.max[resource_type] = *limits.max[resource_type];
// coverity[overrun-local:FALSE]
// collections::range(MAX_REOURCE_TYPE) give us a range of [0, MAX_RESOURCE_TYPE)
// coverity[overrun-local]
interval.used[resource_type] = 0;
}
}
@ -163,7 +165,8 @@ boost::shared_ptr<const EnabledQuota::Intervals> QuotaCache::QuotaInfo::rebuildI
const auto & current_interval = *lower_bound;
for (auto resource_type : collections::range(MAX_RESOURCE_TYPE))
{
// coverity[overrun-local:FALSE]
// collections::range(MAX_REOURCE_TYPE) give us a range of [0, MAX_RESOURCE_TYPE)
// coverity[overrun-local]
new_interval.used[resource_type].store(current_interval.used[resource_type].load());
new_interval.end_of_interval.store(current_interval.end_of_interval.load());
}

View File

@ -148,7 +148,8 @@ RolePtr RoleCache::getRole(const UUID & role_id)
{
auto cache_value = Poco::SharedPtr<std::pair<RolePtr, scope_guard>>(
new std::pair<RolePtr, scope_guard>{role, std::move(subscription)});
// coverity[double_free:FALSE]
// checked the underlying Poco SharedPtr implementation, it calls the copy constructor and increments count by 1
// coverity[double_free]
cache.add(role_id, cache_value);
return role;
}
@ -167,9 +168,11 @@ void RoleCache::roleChanged(const UUID & role_id, const RolePtr & changed_role)
if (!role_from_cache)
return;
role_from_cache->first = changed_role;
// coverity[double_free:FALSE]
// checked the underlying Poco SharedPtr implementation, it calls the copy constructor and increments count by 1
// coverity[double_free]
cache.update(role_id, role_from_cache);
// coverity[double_free:FALSE]
// checked the underlying Poco SharedPtr implementation, it calls the copy constructor and increments count by 1
// coverity[double_free]
collectEnabledRoles(notifications);
}

View File

@ -374,7 +374,8 @@ void calculateFunnel(std::function<UInt32(UInt32)> && getGroup, EventLists<Param
{
extra_group_index.push_back(i);
}
// coverity[use_after_move:FALSE]
// explained by developer yuanyiwen that this is intentional to reuse the funnel when the condition is fulfilled
// coverity[use_after_move]
else if (funnel_index.size() > m_user_pro_idx && reuse_funnel_index.empty())
{
// here need reuse the fronts event

View File

@ -39,7 +39,8 @@ inline AggregateFunctionPtr createAggregateFunctionGroupArrayImpl(const DataType
if (which.idx == TypeIndex::String)
return std::make_shared<GroupArrayGeneralImpl<GroupArrayNodeString, Trait>>(argument_type, parameters, std::forward<TArgs>(args)...);
// coverity[use_after_move:FALSE]
// args here is scalar type (int), std::forward has no effect on it
// coverity[use_after_move]
return std::make_shared<GroupArrayGeneralImpl<GroupArrayNodeGeneral, Trait>>(argument_type, parameters, std::forward<TArgs>(args)...);
// Link list implementation doesn't show noticeable performance improvement

View File

@ -62,7 +62,8 @@ inline AggregateFunctionPtr createAggregateFunctionGroupUniqArrayImpl(const std:
AggregateFunctionPtr res(createWithNumericType<AggregateFunctionGroupUniqArray, HasLimit, const DataTypePtr &, TArgs...>(*argument_type, argument_type, std::forward<TArgs>(args)...));
if (!res)
// coverity[use_after_move:FALSE]
// args here is scalar type (int), std::forward has no effect on it
// coverity[use_after_move]
res = AggregateFunctionPtr(createWithExtraTypes<HasLimit>(argument_type, std::forward<TArgs>(args)...));
if (!res)

View File

@ -127,7 +127,8 @@ private:
std::fill(active, active + size, true);
active[size] = false;
// coverity[uninit_use:FALSE]
// variables are initialized in the body of the lambda
// coverity[uninit_use]
auto delete_node = [&](UInt32 i)
{
previous[next[i]] = previous[i];

View File

@ -39,7 +39,8 @@ public:
throw Exception("Incorrect number of parameters for aggregate function with "
+ getName() + " suffix",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
// coverity[mismatched_iterator:FALSE]
// valid call to vector constructor
// coverity[mismatched_iterator]
return Array(params.begin(), params.end() - 3);
}

View File

@ -115,7 +115,8 @@ void ColumnMap::insertData(const char *, size_t)
void ColumnMap::insert(const Field & x)
{
const auto & map = DB::get<const Map &>(x);
// coverity[mismatched_iterator:FALSE]
// Iterators all inherit from FieldVector
// coverity[mismatched_iterator]
nested->insert(Array(map.begin(), map.end()));
}
@ -276,9 +277,9 @@ void ColumnMap::getExtremes(Field & min, Field & max) const
Array nested_min_value = nested_min.get<Array>();
Array nested_max_value = nested_max.get<Array>();
// coverity[mismatched_iterator:FALSE]
// coverity[mismatched_iterator]
Map map_min_value(nested_min_value.begin(), nested_min_value.end());
// coverity[mismatched_iterator:FALSE]
// coverity[mismatched_iterator]
Map map_max_value(nested_max_value.begin(), nested_max_value.end());
min = std::move(map_min_value);

View File

@ -65,7 +65,11 @@ public:
const auto list_idx = findFreeListIndex(size);
/// If there is a free block.
// coverity[overrun-local:FALSE]
/*
findFreeListIndex accounts for leading 0 in the bits, hence it will not go as high as 63 as
indicated by coverity
*/
// coverity[overrun-local]
if (auto & free_block_ptr = free_lists[list_idx])
{
/// Let's take it. And change the head of the list to the next
@ -94,7 +98,8 @@ public:
/// Insert the released block into the head of the list.
auto & free_block_ptr = free_lists[list_idx];
// coverity[overrun-local:FALSE]
// maximuum value of list_ixd is 15 when size is 65536
// coverity[overrun-local]
const auto old_head = free_block_ptr;
free_block_ptr = reinterpret_cast<Block *>(ptr);
free_block_ptr->next = old_head;

View File

@ -32,28 +32,32 @@ FieldVisitorHash::FieldVisitorHash(SipHash & hash_) : hash(hash_) {}
void FieldVisitorHash::operator() (const Null &) const
{
UInt8 type = Field::Types::Null;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
}
void FieldVisitorHash::operator() (const NegativeInfinity &) const
{
UInt8 type = Field::Types::NegativeInfinity;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
}
void FieldVisitorHash::operator() (const PositiveInfinity &) const
{
UInt8 type = Field::Types::PositiveInfinity;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
}
void FieldVisitorHash::operator() (const UInt64 & x) const
{
UInt8 type = Field::Types::UInt64;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x);
}
@ -68,7 +72,8 @@ void FieldVisitorHash::operator() (const UInt128 & x) const
void FieldVisitorHash::operator() (const Int64 & x) const
{
UInt8 type = Field::Types::Int64;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x);
}
@ -83,7 +88,8 @@ void FieldVisitorHash::operator() (const Int128 & x) const
void FieldVisitorHash::operator() (const UUID & x) const
{
UInt8 type = Field::Types::UUID;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x);
}
@ -91,7 +97,8 @@ void FieldVisitorHash::operator() (const UUID & x) const
void FieldVisitorHash::operator() (const Float64 & x) const
{
UInt8 type = Field::Types::Float64;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x);
}
@ -99,7 +106,8 @@ void FieldVisitorHash::operator() (const Float64 & x) const
void FieldVisitorHash::operator() (const String & x) const
{
UInt8 type = Field::Types::String;
// coverity[overrun-buffer-val:FALSE]
// Checked and there is no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.size());
hash.update(x.data(), x.size());
@ -108,7 +116,8 @@ void FieldVisitorHash::operator() (const String & x) const
void FieldVisitorHash::operator() (const Tuple & x) const
{
UInt8 type = Field::Types::Tuple;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.size());
@ -119,7 +128,8 @@ void FieldVisitorHash::operator() (const Tuple & x) const
void FieldVisitorHash::operator() (const Map & x) const
{
UInt8 type = Field::Types::Map;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.size());
@ -135,7 +145,8 @@ void FieldVisitorHash::operator() ([[maybe_unused]] const ByteMap & x) const
void FieldVisitorHash::operator() (const Array & x) const
{
UInt8 type = Field::Types::Array;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.size());
@ -146,9 +157,11 @@ void FieldVisitorHash::operator() (const Array & x) const
void FieldVisitorHash::operator() (const DecimalField<Decimal32> & x) const
{
UInt8 type = Field::Types::Decimal32;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(x.getValue().value);
}
@ -176,7 +189,8 @@ void FieldVisitorHash::operator() (const DecimalField<Decimal256> & x) const
void FieldVisitorHash::operator() (const AggregateFunctionStateData & x) const
{
UInt8 type = Field::Types::AggregateFunctionState;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.name.size());
hash.update(x.name.data(), x.name.size());
@ -187,7 +201,8 @@ void FieldVisitorHash::operator() (const AggregateFunctionStateData & x) const
void FieldVisitorHash::operator() (const UInt256 & x) const
{
UInt8 type = Field::Types::UInt256;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x);
}
@ -202,7 +217,8 @@ void FieldVisitorHash::operator() (const Int256 & x) const
void FieldVisitorHash::operator() (const BitMap64 & x) const
{
UInt8 type = Field::Types::BitMap64;
// coverity[overrun-buffer-val:FALSE]
// Checked update implementation and there is no out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.cardinality());

View File

@ -32,19 +32,25 @@ static void dummyFunctionForInterposing()
void* dummy;
/// Suppression for PVS-Studio and clang-tidy.
free(nullptr); // -V575 NOLINT
// coverity[leaked_storage:FALSE]
// file and function not used
// coverity[leaked_storage]
ignore(malloc(0)); // -V575 NOLINT
// coverity[leaked_storage:FALSE]
// file and function not used
// coverity[leaked_storage]
ignore(calloc(0, 0)); // -V575 NOLINT
// coverity[leaked_storage:FALSE]
// file and function not used
// coverity[leaked_storage]
ignore(realloc(nullptr, 0)); // -V575 NOLINT
ignore(posix_memalign(&dummy, 0, 0)); // -V575 NOLINT
// coverity[leaked_storage:FALSE]
// file and function not used
// coverity[leaked_storage]
ignore(aligned_alloc(0, 0)); // -V575 NOLINT
// coverity[leaked_storage:FALSE]
// file and function not used
// coverity[leaked_storage]
ignore(valloc(0)); // -V575 NOLINT
ignore(memalign(0, 0)); // -V575 NOLINT
ignore(pvalloc(0)); // -V575 NOLINT
// coverity[leaked_storage:FALSE]
// file and function not used
// coverity[leaked_storage]
}
#endif

View File

@ -696,7 +696,8 @@ void CompressionCodecT64::updateHash(SipHash & hash) const
{
getCodecDesc()->updateTreeHash(hash);
hash.update(type_idx);
// coverity[overrun-buffer-val:FALSE]
// checked update implementation and there is no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(variant);
}

View File

@ -442,7 +442,9 @@ namespace MySQLReplication
);
if (!meta)
// coverity[store_truncates_time_t:FALSE]
// The max value of the 64 bit int flagged here exceeds the year value that is
// supported by ClickHouse as verified with Alfred
// coverity[store_truncates_time_t]
row.push_back(Field{UInt32(date_time)});
else
{

View File

@ -120,7 +120,8 @@ void insertPostgreSQLValue(
readDateTimeText(time, in, assert_cast<const DataTypeDateTime *>(data_type.get())->getTimeZone());
if (time < 0)
time = 0;
// coverity[store_truncates_time_t:FALSE]
// DataTypeDateTime will not exceed UInt32 due to readDateTimeText
// coverity[store_truncates_time_t]
assert_cast<ColumnUInt32 &>(column).insertValue(time);
break;
}
@ -173,7 +174,8 @@ void insertPostgreSQLValue(
throw Exception(ErrorCodes::BAD_ARGUMENTS,
"Got less dimensions than expected. ({} instead of {})", max_dimension, expected_dimensions);
// coverity[mismatched_iterator:FALSE]
// Both inherit from FieldVector
// coverity[mismatched_iterator]
assert_cast<ColumnArray &>(column).insert(Array(dimensions[1].begin(), dimensions[1].end()));
break;
}

View File

@ -132,7 +132,8 @@ void Settings::addProgramOptions(boost::program_options::options_description & o
const std::string_view name = field.getName();
auto on_program_option
= boost::function1<void, const std::string &>([this, name](const std::string & value) { set(name, value); });
// coverity[uninit_use_in_call:FALSE]
// on_program_option is initialized with the lambda within boost:program_options
// coverity[uninit_use_in_call]
options.add(boost::shared_ptr<boost::program_options::option_description>(new boost::program_options::option_description(
name.data(),
boost::program_options::value<std::string>()->composing()->notifier(on_program_option),

View File

@ -162,7 +162,8 @@ BlockInputStreamPtr MongoDBDictionarySource::loadIds(const std::vector<UInt64> &
for (const UInt64 id : ids)
ids_array->add(DB::toString(id), Int32(id));
// coverity[double_free:FALSE]
// Invokes SharedPtr copy constructor
// coverity[double_free]
cursor->query().selector().addNewDocument(dict_struct.id->name).add("$in", ids_array);
return std::make_shared<MongoDBBlockInputStream>(connection, std::move(cursor), sample_block, max_block_size);
@ -214,7 +215,8 @@ BlockInputStreamPtr MongoDBDictionarySource::loadKeys(const Columns & key_column
if (key_attribute.is_object_id)
{
Poco::MongoDB::ObjectId::Ptr loaded_id(new Poco::MongoDB::ObjectId(loaded_str));
// coverity[double_free:FALSE]
// Invokes SharedPtr copy constructor
// coverity[double_free]
key.add(key_attribute.name, loaded_id);
}
else
@ -230,9 +232,11 @@ BlockInputStreamPtr MongoDBDictionarySource::loadKeys(const Columns & key_column
}
/// If more than one key we should use $or
// coverity[double_free:FALSE]
// Invokes SharedPtr copy constructor
// coverity[double_free]
cursor->query().selector().add("$or", keys_array);
// coverity[double_free:FALSE]
// Invokes SharedPtr copy constructor
// coverity[double_free]
return std::make_shared<MongoDBBlockInputStream>(connection, std::move(cursor), sample_block, max_block_size);
}

View File

@ -106,7 +106,8 @@ namespace DB
readDateTimeText(time, in);
if (time < 0)
time = 0;
// coverity[store_truncates_time_t:FALSE]
// readDateTimeText gives time value that will not exceed UInt32
// coverity[store_truncates_time_t]
assert_cast<ColumnUInt32 &>(column).insertValue(time);
break;
}

View File

@ -181,7 +181,8 @@ namespace
readDateTimeText(time, in, assert_cast<const DataTypeDateTime &>(data_type).getTimeZone());
if (time < 0)
time = 0;
// coverity[store_truncates_time_t:FALSE]
// readDateTimeText gives time value that will not exceed UInt32
// coverity[store_truncates_time_t]
assert_cast<ColumnUInt32 &>(column).insertValue(time);
read_bytes_size += 4;
break;

View File

@ -1488,10 +1488,12 @@ namespace
read_function = [this]() -> UInt32
{
readStr(text_buffer);
// coverity[store_truncates_time_t:FALSE]
// stringToDateTime calls readDateTimeText, which gives time that will not exceed UInt32
// coverity[store_truncates_time_t]
return stringToDateTime(text_buffer);
};
// coverity[store_truncates_time_t:FALSE]
// stringToDateTime calls readDateTimeText, which gives time that will not exceed UInt32
// coverity[store_truncates_time_t]
default_function = [this]() -> UInt32 { return stringToDateTime(field_descriptor.default_value_string()); };
break;
}

View File

@ -1267,7 +1267,8 @@ struct Transformer
if constexpr (is_extended_result)
vec_to[i] = transform.executeExtendedResult(vec_from[i], time_zone);
else
// coverity[store_truncates_time_t:FALSE]
// narrowing conversions for time_t has a transformer to handle it
// coverity[store_truncates_time_t]
vec_to[i] = transform.execute(vec_from[i], time_zone);
}
};

View File

@ -1014,7 +1014,8 @@ inline void convertFromTime<DataTypeDateTime>(DataTypeDateTime::FieldType & x, t
else if (unlikely(time > 0xFFFFFFFF))
x = 0xFFFFFFFF;
else
// coverity[store_truncates_time_t:FALSE]
// Handles exceeding 32 bit above
// coverity[store_truncates_time_t]
x = time;
}
@ -1094,7 +1095,8 @@ inline bool tryParseImpl<DataTypeDateTime>(DataTypeDateTime::FieldType & x, Read
time_t tmp = 0;
if (!tryReadDateTimeText(tmp, rb, *time_zone))
return false;
// coverity[store_truncates_time_t:FALSE]
// tryReadDateTimeText gives time that will not exceed UInt32
// coverity[store_truncates_time_t]
x = tmp;
return true;
}

View File

@ -892,7 +892,8 @@ private:
ImplementationSelector<IFunction> selector;
};
// coverity[overrun-buffer-val:FALSE]
// checked applyWithSeed calls and no apparent out of bound buffer
// coverity[overrun-buffer-val]
DECLARE_MULTITARGET_CODE(
template <typename Impl, bool with_seed = false>

View File

@ -643,7 +643,8 @@ UInt128 sipHash128(Polygon && polygon)
auto hash_ring = [&hash](const auto & ring)
{
UInt32 size = ring.size();
// coverity[overrun-buffer-val:FALSE]
// checked underlying update implementation, no out of bounds access
// coverity[overrun-buffer-val]
hash.update(size);
hash.update(reinterpret_cast<const char *>(ring.data()), size * sizeof(ring[0]));
};

View File

@ -37,7 +37,8 @@ namespace
class ExecutableFunctionToday : public IExecutableFunction
{
public:
// coverity[store_truncates_time_t:FALSE]
// Only called by FunctionBaseToday which passes UInt16
// coverity[store_truncates_time_t]
explicit ExecutableFunctionToday(time_t time_) : day_value(time_) {}
String getName() const override { return "today"; }

View File

@ -14,7 +14,8 @@ namespace DB
class ExecutableFunctionYesterday : public IExecutableFunction
{
public:
// coverity[store_truncates_time_t:FALSE]
// Only called by FunctionBaseToday which passes UInt16
// coverity[store_truncates_time_t]
explicit ExecutableFunctionYesterday(time_t time_) : day_value(time_) {}
String getName() const override { return "yesterday"; }

View File

@ -185,7 +185,8 @@ namespace
s.update(k.is_target_https);
s.update(k.proxy_host);
s.update(k.proxy_port);
// coverity[overrun-local:FALSE]
// checked update implementation no apparent out of bounds
// coverity[overrun-local]
s.update(k.is_proxy_https);
return s.get64();
}

View File

@ -317,7 +317,8 @@ public:
if (readAndDecompress) return;
size_t size_decompressed;
// Record size_compressed here
// coverity[uninit_use_in_call:FALSE]
// Initialized by reference with readCompressedData
// coverity[uninit_use_in_call]
size_compressed = readCompressedData(size_decompressed);
//TODO: check whether we need check len here
memory.resize(size_decompressed);

View File

@ -59,7 +59,8 @@ namespace
auto & quota_limits = *it;
quota_limits.randomize_interval = query_limits.randomize_interval;
for (auto resource_type : collections::range(Quota::MAX_RESOURCE_TYPE))
// coverity[overrun-local:FALSE]
// collections::range is end exclusive
// coverity[overrun-local]
quota_limits.max[resource_type] = query_limits.max[resource_type];
}

View File

@ -867,7 +867,8 @@ static FillColumnDescription getWithFillDescription(const ASTOrderByElement & or
}
}
// coverity[unit_use:FALSE]
// one of fill_from, fill_step and fill_to is initialized
// coverity[unit_use]
return descr;
}

View File

@ -173,7 +173,8 @@ namespace
create_query_limits.duration = limits.duration;
create_query_limits.randomize_interval = limits.randomize_interval;
for (auto resource_type : collections::range(Quota::MAX_RESOURCE_TYPE))
// coverity[overrun-local:FALSE]
// collections::range is end exclusive
// coverity[overrun-local]
create_query_limits.max[resource_type] = limits.max[resource_type];
query->all_limits.push_back(create_query_limits);
}

View File

@ -684,10 +684,11 @@ DeleteBitmapVector MergeTreeDataDeduper::repairImpl(const IMergeTreeDataPartsVec
DeleteBitmapVector res(parts.size());
DeleteCallback cb = [&res](const RowPos & pos) { addRowIdToBitmap(res[pos.child], pos.rowid); };
// coverity[out_of_scope:FALSE]
ReplacingSortedKeysIterator keys_iter(IndexFile::BytewiseComparator(), parts, std::move(input_iters), cb, version_mode);
keys_iter.SeekToFirst();
while (keys_iter.Valid())
// delete_flag_bitmaps is default initialized
// coverity[use_invalid_in_call]
keys_iter.Next();
return res;
}

View File

@ -104,7 +104,8 @@ namespace
bool need_comma = false;
for (auto resource_type : collections::range(Quota::MAX_RESOURCE_TYPE))
{
// coverity[overrun-local:FALSE]
// collections::range is end exclusive
// coverity[overrun-local]
if (limits.max[resource_type])
{
if (std::exchange(need_comma, true))

View File

@ -613,7 +613,8 @@ std::string_view obfuscateWord(std::string_view src, WordMap & obfuscate_map, Wo
/// Prevent collisions
while (!used_nouns.insert(noun).second)
{
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash_func.update('\0');
noun = nouns.begin()[hash_func.get64() % nouns.size()];
}

View File

@ -34,8 +34,7 @@ namespace DB
LocalBroadcastChannel::LocalBroadcastChannel(DataTransKeyPtr data_key_, LocalChannelOptions options_, std::shared_ptr<QueryExchangeLog> query_exchange_log_)
: data_key(std::move(data_key_))
, options(std::move(options_))
// coverity[use_after_move:FALSE]
, receive_queue(options_.queue_size)
, receive_queue(options.queue_size)
, logger(&Poco::Logger::get("LocalBroadcastChannel"))
, query_exchange_log(query_exchange_log_)
{
@ -119,7 +118,7 @@ BroadcastStatus LocalBroadcastChannel::finish(BroadcastStatusCode status_code, S
send_metric.finish_code = new_status_ptr->code;
send_metric.is_modifier = 1;
send_metric.message = new_status_ptr->message;
// coverity[leaked_storage:FALSE]
// coverity[leaked_storage]
return res;
}
else

View File

@ -378,7 +378,8 @@ size_t ConstantExpressionTemplate::TemplateStructure::getTemplateHash(const ASTP
for (const auto & info : replaced_literals)
hash_state.update(info.type->getName());
// coverity[overrun-buffer-val:FALSE];
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val];
hash_state.update(null_as_default);
/// Allows distinguish expression in the last column in Values format

View File

@ -48,7 +48,8 @@ void LineAsStringRowInputFormat::readLineObject(IColumn & column)
loadAtPosition(in, object, pos);
/// Last character is always \n.
// coverity[overrun-buffer-arg:FALSE]
// Empty object will be caught by readRow(), so this will not happen
// coverity[overrun-buffer-arg]
column.insertData(object.data(), object.size() - 1);
}

View File

@ -213,7 +213,8 @@ void MySQLHandler::finishHandshake(MySQLProtocol::ConnectionPhase::HandshakeResp
size_t pos = 0;
/// Reads at least count and at most packet_size bytes.
// coverity[uninit_use:FALSE]
// buf is initialized in lambda under receiveBytes
// coverity[uninit_use]
auto read_bytes = [this, &buf, &pos, &packet_size](size_t count) -> void {
while (pos < count)
{
@ -398,7 +399,8 @@ void MySQLHandlerSSL::finishHandshakeSSL(
payload.ignore(PACKET_HEADER_SIZE);
ssl_request.readPayloadWithUnpacked(payload);
client_capabilities = ssl_request.capability_flags;
// coverity[uninit_use:FALSE]
// capability_flags initialized under readPayloadWithUnpacked
// coverity[uninit_use]
max_packet_size = ssl_request.max_packet_size ? ssl_request.max_packet_size : MAX_PACKET_LENGTH;
secure_connection = true;
ss = std::make_shared<SecureStreamSocket>(SecureStreamSocket::attach(socket(), SSLManager::instance().defaultServerContext()));

View File

@ -116,7 +116,8 @@ StatsData CachedStatsProxyImpl::get(const StatsTableIdentifier & table_id, bool
item_ptr = makePocoShared<StatsCollection>(catalog->readSingleStats(table_id, col_name));
cache.update(key, item_ptr);
}
// coverity[double_free:FALSE]
// SharedPtr copy constructor invoked
// coverity[double_free]
result.column_stats.emplace(pr.name, *item_ptr);
}
return result;

View File

@ -36,7 +36,8 @@ struct TableBuilder::Rep
, index_block(&index_block_options)
, num_entries(0)
, closed(false)
// coverity[ctor_dtor_leak:FALSE]
// destructor does release filter_block
// coverity[ctor_dtor_leak]
, filter_block(opt.filter_policy == nullptr ? nullptr : new FilterBlockBuilder(opt.filter_policy.get()))
, pending_index_entry(false)
{

View File

@ -390,7 +390,8 @@ namespace
{
ColumnPtr column;
if (rows)
// coverity[mismatched_iterator:FALSE]
// both inherit from FieldVector
// coverity[mismatched_iterator]
column = partition_value_type->createColumnConst(rows, Tuple(partition_value.begin(), partition_value.end()))
->convertToFullColumnIfConst();
else
@ -431,7 +432,8 @@ namespace
{
ColumnPtr column;
if (rows)
// coverity[mismatched_iterator:FALSE]
// both inherit from FieldVector
// coverity[mismatched_iterator]
column = partition_value_type->createColumnConst(rows, Tuple(partition_value.begin(), partition_value.end()))
->convertToFullColumnIfConst();
else

View File

@ -399,7 +399,8 @@ NamesAndTypesList MergeTreeCNCHDataDumper::getKeyColumns() const
{
Names sort_key_columns_vec = data.getInMemoryMetadata().getSortingKeyColumns();
std::set<String> key_columns(sort_key_columns_vec.cbegin(), sort_key_columns_vec.cend());
// coverity[use_invalid:FALSE]
// no issue with data.getInMemoryMetadata().getSecondaryIndices() being a temporary variable
// coverity[use_invalid]
for (const auto & index : data.getInMemoryMetadata().getSecondaryIndices())
{
const auto & index_columns_vec = index.column_names;

View File

@ -62,25 +62,29 @@ namespace
void operator() (const Null &) const
{
UInt8 type = Field::Types::Null;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
}
void operator() (const NegativeInfinity &) const
{
UInt8 type = Field::Types::NegativeInfinity;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
}
void operator() (const PositiveInfinity &) const
{
UInt8 type = Field::Types::PositiveInfinity;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
}
void operator() (const UInt64 & x) const
{
UInt8 type = Field::Types::UInt64;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x);
}
@ -99,14 +103,16 @@ namespace
void operator() (const Int64 & x) const
{
UInt8 type = Field::Types::Int64;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x);
}
void operator() (const Int128 & x) const
{
UInt8 type = Field::Types::Int128;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x);
}
@ -123,14 +129,16 @@ namespace
void operator() (const Float64 & x) const
{
UInt8 type = Field::Types::Float64;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x);
}
void operator() (const String & x) const
{
UInt8 type = Field::Types::String;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.size());
hash.update(x.data(), x.size());
@ -138,7 +146,8 @@ namespace
void operator() (const Array & x) const
{
UInt8 type = Field::Types::Array;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.size());
@ -148,7 +157,8 @@ namespace
void operator() (const Tuple & x) const
{
UInt8 type = Field::Types::Tuple;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.size());
@ -158,7 +168,8 @@ namespace
void operator() (const Map & x) const
{
UInt8 type = Field::Types::Map;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.size());
@ -174,7 +185,8 @@ namespace
void operator() (const DecimalField<Decimal32> & x) const
{
UInt8 type = Field::Types::Decimal32;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.getValue().value);
}
@ -193,14 +205,16 @@ namespace
void operator() (const DecimalField<Decimal256> & x) const
{
UInt8 type = Field::Types::Decimal256;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.getValue().value);
}
void operator() (const AggregateFunctionStateData & x) const
{
UInt8 type = Field::Types::AggregateFunctionState;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.name.size());
hash.update(x.name.data(), x.name.size());
@ -210,7 +224,8 @@ namespace
void operator() (const BitMap64 & x) const
{
UInt8 type = Field::Types::BitMap64;
// coverity[overrun-buffer-val:FALSE]
// checked update implementation, no apparent out of bounds
// coverity[overrun-buffer-val]
hash.update(type);
hash.update(x.cardinality());

View File

@ -72,7 +72,8 @@ private:
* - in this case `n - 1` elements are added (where `n` is the number of arguments).
*/
if (i != 0 || element.function == RPNElement::FUNCTION_NOT)
// coverity[use_after_move:FALSE]
// No issues with using move and emplace back
// coverity[use_after_move]
rpn.emplace_back(std::move(element));
}

View File

@ -218,7 +218,8 @@ StoragePtr StorageFactory::get(
}
ASTs empty_engine_args;
// coverity[out_of_scope:FALSE]
//No issues with calling StorageID below with in braced initialization
// coverity[out_of_scope]
Arguments arguments{
.engine_name = name,
.engine_args = has_engine_args ? storage_def->engine->arguments->children : empty_engine_args,

View File

@ -255,10 +255,11 @@ public:
else
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Type conversion not supported");
if (is_nullable)
// coverity[use_after_move:FALSE]
return ColumnNullable::create(std::move(nested_column), ColumnUInt8::create(nested_column->size(), 0));
if (is_nullable) {
size_t col_size = nested_column->size();
return ColumnNullable::create(std::move(nested_column), ColumnUInt8::create(col_size, 0));
}
return nested_column;
}

View File

@ -84,9 +84,11 @@ void StorageSystemQuotaLimits::fillData(MutableColumns & res_columns, ContextPtr
NullMap * column_max_null_map[MAX_RESOURCE_TYPE];
for (auto resource_type : collections::range(MAX_RESOURCE_TYPE))
{
// coverity[overrun-local:FALSE]
// collections::range is end exclusive
// coverity[overrun-local]
column_max[resource_type] = &assert_cast<ColumnNullable &>(*res_columns[column_index]).getNestedColumn();
// coverity[overrun-local:FALSE]
// collections::range is end exclusive
// coverity[overrun-local]
column_max_null_map[resource_type] = &assert_cast<ColumnNullable &>(*res_columns[column_index++]).getNullMapData();
}

View File

@ -119,13 +119,14 @@ void StorageSystemQuotaUsage::fillDataImpl(
NullMap * column_max_null_map[MAX_RESOURCE_TYPE];
for (auto resource_type : collections::range(MAX_RESOURCE_TYPE))
{
// coverity[overrun-local:FALSE]
// collections::range is end exclusive, hence we can ignore all below
// coverity[overrun-local]
column_usage[resource_type] = &assert_cast<ColumnNullable &>(*res_columns[column_index]).getNestedColumn();
// coverity[overrun-local:FALSE]
// coverity[overrun-local]
column_usage_null_map[resource_type] = &assert_cast<ColumnNullable &>(*res_columns[column_index++]).getNullMapData();
// coverity[overrun-local:FALSE]
// coverity[overrun-local]
column_max[resource_type] = &assert_cast<ColumnNullable &>(*res_columns[column_index]).getNestedColumn();
// coverity[overrun-local:FALSE]
// coverity[overrun-local]
column_max_null_map[resource_type] = &assert_cast<ColumnNullable &>(*res_columns[column_index++]).getNullMapData();
}
@ -154,13 +155,14 @@ void StorageSystemQuotaUsage::fillDataImpl(
column_duration_null_map.push_back(true);
for (auto resource_type : collections::range(MAX_RESOURCE_TYPE))
{
// coverity[overrun-local:FALSE]
// collections::range is end exclusive, hence we can ignore all below
// coverity[overrun-local]
column_usage[resource_type]->insertDefault();
// coverity[overrun-local:FALSE]
// coverity[overrun-local]
column_usage_null_map[resource_type]->push_back(true);
// coverity[overrun-local:FALSE]
// coverity[overrun-local]
column_max[resource_type]->insertDefault();
// coverity[overrun-local:FALSE]
// coverity[overrun-local]
column_max_null_map[resource_type]->push_back(true);
}
return;

View File

@ -70,9 +70,10 @@ void StorageSystemRowPolicies::fillData(MutableColumns & res_columns, ContextPtr
NullMap * column_condition_null_map[MAX_CONDITION_TYPE];
for (auto condition_type : collections::range(MAX_CONDITION_TYPE))
{
// coverity[overrun-local:FALSE]
// collections::range is end exclusive, hence we can ignore all below
// coverity[overrun-local]
column_condition[condition_type] = &assert_cast<ColumnString &>(assert_cast<ColumnNullable &>(*res_columns[column_index]).getNestedColumn());
// coverity[overrun-local:FALSE]
// coverity[overrun-local]
column_condition_null_map[condition_type] = &assert_cast<ColumnNullable &>(*res_columns[column_index++]).getNullMapData();
}
@ -103,9 +104,10 @@ void StorageSystemRowPolicies::fillData(MutableColumns & res_columns, ContextPtr
const String & condition = conditions[condition_type];
if (condition.empty())
{
// coverity[overrun-local:FALSE]
// collections::range is end exclusive, hence we can ignore all below
// coverity[overrun-local]
column_condition[condition_type]->insertDefault();
// coverity[overrun-local:FALSE]
// coverity[overrun-local]
column_condition_null_map[condition_type]->push_back(true);
}
else

View File

@ -192,7 +192,8 @@ int main(int argc, char ** argv)
{
try
{
// coverity[path_manipulation_sink:FALSE]
// test file that will not be shipped to production
// coverity[path_manipulation_sink]
return mainImpl(argc, argv);
}
catch (const Poco::Exception & e)