Skip to content

Commit e8f7a34

Browse files
committed
libpressio version 0.50.5
Bug Fixes: + span now does not use reserved name _Offset + pressio_data now checks if the buffer is empty before calling malloc to prevent undefined behavior on platforms where malloc(0) is undefined behavior + pressio_metrics now handles self assignment + bit grooming now uses the correct BG_DOUBLE type for doubles + prevent catastrophic truncation in kl_divergance plugin
1 parent 9e64647 commit e8f7a34

File tree

7 files changed

+19
-14
lines changed

7 files changed

+19
-14
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
2-
project(libpressio VERSION "0.50.4" LANGUAGES CXX C)
2+
project(libpressio VERSION "0.50.5" LANGUAGES CXX C)
33

44
#correct was to set a default build type
55
# https://blog.kitware.com/cmake-and-the-default-build-type/

include/libpressio_ext/compat/span.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,15 @@ class span {
233233
return {data() + size() - count, count};
234234
}
235235

236-
template <size_t _Offset, size_t Count = compat_dynamic_extent>
236+
template <size_t Offset, size_t Count = compat_dynamic_extent>
237237

238238
constexpr auto subspan() const noexcept
239-
-> span<element_type, Count != compat_dynamic_extent ? Count : Extent - _Offset>
239+
-> span<element_type, Count != compat_dynamic_extent ? Count : Extent - Offset>
240240
{
241241
#if __cplusplus >= 201703L
242-
static_assert(_Offset <= Extent, "Offset out of range in span::subspan()");
242+
static_assert(Offset <= Extent, "Offset out of range in span::subspan()");
243243
#endif
244-
return {data() + _Offset, Count == compat_dynamic_extent ? size() - _Offset : Count};
244+
return {data() + Offset, Count == compat_dynamic_extent ? size() - Offset : Count};
245245
}
246246

247247

@@ -419,15 +419,15 @@ class span<Type, compat_dynamic_extent> {
419419
return {data() + size() - count, count};
420420
}
421421

422-
template <size_t _Offset, size_t Count = compat_dynamic_extent>
422+
template <size_t Offset, size_t Count = compat_dynamic_extent>
423423

424424
constexpr span<Type, compat_dynamic_extent> subspan() const noexcept
425425
{
426426
#if __cplusplus >= 201703L
427-
assert(_Offset <= size() && "Offset out of range in span::subspan()");
428-
assert(Count == compat_dynamic_extent || _Offset + Count <= size() && "Count out of range in span::subspan()");
427+
assert(Offset <= size() && "Offset out of range in span::subspan()");
428+
assert(Count == compat_dynamic_extent || Offset + Count <= size() && "Count out of range in span::subspan()");
429429
#endif
430-
return {data() + _Offset, Count == compat_dynamic_extent ? size() - _Offset : Count};
430+
return {data() + Offset, Count == compat_dynamic_extent ? size() - Offset : Count};
431431
}
432432

433433
constexpr span<element_type, compat_dynamic_extent>

include/libpressio_ext/cpp/data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ struct pressio_data {
313313
* \returns true if the structure has has data
314314
*/
315315
bool has_data() const {
316-
return data_ptr != nullptr;
316+
return data_ptr != nullptr && size_in_bytes() > 0;
317317
}
318318

319319
/**

include/libpressio_ext/cpp/metrics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ struct pressio_metrics {
153153
* move assigns a metric from another pointer
154154
*/
155155
pressio_metrics& operator=(pressio_metrics const& metrics) {
156+
if(&metrics == this) return *this;
156157
plugin = metrics->clone();
157158
return *this;
158159
}

src/plugins/compressors/bit_groooming_plugin.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class bit_grooming_plugin: public libpressio_compressor_plugin {
170170
}
171171
else if(type == pressio_double_dtype)
172172
{
173-
return BG_FLOAT;
173+
return BG_DOUBLE;
174174
}
175175
else
176176
{

src/plugins/metrics/kl_divergance.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ namespace kl_divergence{
3333
std::for_each( decomp_begin, decomp_end, [&q_counts,&X](value_type q) { q_counts[q] += 1; X.insert(q);});
3434

3535
for (auto const& x : X) {
36-
m.p_q += p_counts[x] / p_size * std::log((p_counts[x] * q_size)/ (q_counts[x]* p_size));
37-
m.q_p += q_counts[x] / q_size * std::log((q_counts[x] * p_size)/ (p_counts[x]* q_size));
36+
m.p_q += static_cast<double>(p_counts[x]) / static_cast<double>(p_size) * std::log((p_counts[x] * q_size)/ (static_cast<double>(q_counts[x])* p_size));
37+
m.q_p += static_cast<double>(q_counts[x]) / static_cast<double>(q_size) * std::log((q_counts[x] * p_size)/ (static_cast<double>(p_counts[x])* q_size));
3838

3939
}
4040

src/pressio_data.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ namespace {
200200
compat::exclusive_scan(compat::rbegin(iter_max), compat::rend(iter_max), compat::rbegin(strides), 1, compat::multiplies<>{});
201201
for (size_t src_idx = 0; src_idx < max_idx; ++src_idx) {
202202
size_t dst_idx = compat::transform_reduce(std::begin(iter), std::end(iter), std::begin(strides), 0, compat::plus<>{}, compat::multiplies<>{});
203-
r2_begin[src_idx] = r1_begin[dst_idx];
203+
//clang-tidy treats this line as bugprone conversion since
204+
//it can cause unintended behavior in switch-case statements
205+
//matching against character codes. Since we aren't doing
206+
//that here, ignore this warning.
207+
r2_begin[src_idx] = r1_begin[dst_idx]; //NOLINT
204208

205209
size_t idx = 0;
206210
bool updating = true;

0 commit comments

Comments
 (0)