Skip to content

Commit 291a18b

Browse files
committed
fix compiler and ci warnings
Clean up the remaining warnings that are under h5pp's control. - fix discarded exception objects and a size_t-to-int narrowing site - replace unsafe string copying in vlen/fixed-string helpers and user-type tests - update Conan metadata to the C++20 baseline and quiet the optional libaec lookup - reduce workflow noise from apt usage, cache path setup, coverage capture, and MSVC test-only complex warnings
1 parent b717fe5 commit 291a18b

16 files changed

Lines changed: 122 additions & 73 deletions

.github/workflows/macos14.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ jobs:
3333
with:
3434
python-version: '3.x'
3535

36+
- name: Prepare cache directories
37+
run: |
38+
mkdir -p ~/.ccache ~/.conan2 install/github-actions-${{ matrix.manager }}
39+
3640
- name: Setup caches
3741
id: h5pp-cache
3842
uses: actions/cache@v4.2.0

.github/workflows/macos15.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ jobs:
3333
with:
3434
python-version: '3.x'
3535

36+
- name: Prepare cache directories
37+
run: |
38+
mkdir -p ~/.ccache ~/.conan2 install/github-actions-${{ matrix.manager }}
39+
3640
- name: Setup caches
3741
id: h5pp-cache
3842
uses: actions/cache@v4.2.0

.github/workflows/ubuntu22.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ jobs:
3636

3737
- name: Update apt
3838
run: |
39-
sudo apt update
39+
sudo apt-get update
40+
41+
- name: Prepare cache directories
42+
run: |
43+
mkdir -p ~/.ccache ~/.conan2 install/github-actions-${{ matrix.manager }}
4044
4145
4246
- name: Setup caches
@@ -52,22 +56,22 @@ jobs:
5256
- name: Setup gcc
5357
if: matrix.compiler == 'gcc'
5458
run: |
55-
sudo apt install gcc-12 g++-12 -y
59+
sudo apt-get install gcc-12 g++-12 -y
5660
echo "FC=gfortran-12" >> $GITHUB_ENV
5761
echo "CC=gcc-12" >> $GITHUB_ENV
5862
echo "CXX=g++-12" >> $GITHUB_ENV
5963
6064
- name: Setup clang
6165
if: matrix.compiler == 'clang'
6266
run: |
63-
sudo apt install clang-15 libomp-15-dev -y
67+
sudo apt-get install clang-15 libomp-15-dev -y
6468
echo "FC=gfortran-12" >> $GITHUB_ENV
6569
echo "CC=clang-15" >> $GITHUB_ENV
6670
echo "CXX=clang++-15" >> $GITHUB_ENV
6771
6872
- name: Setup build tools
6973
run: |
70-
sudo apt install ccache ninja-build gcovr lcov -y
74+
sudo apt-get install ccache ninja-build gcovr lcov -y
7175
echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV
7276
7377
- name: Setup conan

.github/workflows/ubuntu24.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ jobs:
3939

4040
- name: Update apt
4141
run: |
42-
sudo apt update
42+
sudo apt-get update
43+
44+
- name: Prepare cache directories
45+
run: |
46+
mkdir -p ~/.ccache ~/.conan2 install/github-actions-${{ matrix.manager }}
4347
4448
4549
- name: Setup caches
@@ -55,27 +59,27 @@ jobs:
5559
- name: Setup gcc
5660
if: matrix.compiler == 'gcc'
5761
run: |
58-
sudo apt install gcc-14 g++-14 -y
62+
sudo apt-get install gcc-14 g++-14 -y
5963
echo "FC=gfortran-14" >> $GITHUB_ENV
6064
echo "CC=gcc-14" >> $GITHUB_ENV
6165
echo "CXX=g++-14" >> $GITHUB_ENV
6266
6367
- name: Setup clang
6468
if: matrix.compiler == 'clang'
6569
run: |
66-
sudo apt install clang-18 libomp-18-dev -y
70+
sudo apt-get install clang-18 libomp-18-dev -y
6771
echo "FC=gfortran-14" >> $GITHUB_ENV
6872
echo "CC=clang-18" >> $GITHUB_ENV
6973
echo "CXX=clang++-18" >> $GITHUB_ENV
7074
7175
- name: Setup build tools
7276
run: |
73-
sudo apt install ccache ninja-build gcovr lcov -y
77+
sudo apt-get install ccache ninja-build gcovr lcov -y
7478
echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV
7579
7680
- name: Setup apt packages (dependencies)
7781
if: matrix.manager == 'find'
78-
run: sudo apt install libhdf5-dev libaec-dev libfmt-dev libspdlog-dev libeigen3-dev catch2 -y
82+
run: sudo apt-get install libhdf5-dev libaec-dev libfmt-dev libspdlog-dev libeigen3-dev catch2 -y
7983

8084
- name: Setup conan
8185
if: matrix.manager == 'conan'
@@ -114,8 +118,8 @@ jobs:
114118
- name: Generate coverage report
115119
if: matrix.compiler == 'gcc' && matrix.manager == 'find'
116120
run: |
117-
lcov --gcov-tool=gcov-14 --capture --directory build/github-actions-find --output-file coverage.info
118-
lcov --gcov-tool=gcov-14 --ignore-errors unused --remove coverage.info '*/test-*' '/usr/*' 'include/c++/*' '*include/fmt/*' '*include/spdlog/*' '*/Eigen/*' '*/hdf5/*' '*catch.hpp' --output-file coverage.info
121+
lcov --gcov-tool=gcov-14 --capture --rc geninfo_unexecuted_blocks=1 --no-external --directory build/github-actions-find --output-file coverage.info
122+
lcov --gcov-tool=gcov-14 --ignore-errors unused --remove coverage.info '*/test-*' '*catch.hpp' --output-file coverage.info
119123
lcov --gcov-tool=gcov-14 --list coverage.info
120124
121125
- name: Upload coverage to Codecov

.github/workflows/windows2022.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ jobs:
3232
with:
3333
python-version: '3.x'
3434

35+
- name: Prepare cache directories
36+
shell: pwsh
37+
run: |
38+
New-Item -ItemType Directory -Force -Path "$HOME\\.conan2" | Out-Null
39+
New-Item -ItemType Directory -Force -Path "install/github-actions-${{ matrix.manager }}" | Out-Null
40+
3541
- name: Setup caches
3642
id: h5pp-cache
3743
uses: actions/cache@v4.2.0

cmake/HDF5TargetUtils.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ function(h5pp_get_modern_hdf5_target_name)
244244
find_package(ZLIB ${HDF5_ZLIB_REQUIRED} QUIET BYPASS_PROVIDER)
245245
find_package(SZIP ${HDF5_SZIP_REQUIRED} QUIET BYPASS_PROVIDER)
246246
if(NOT DEFINED libaec_FOUND AND NOT TARGET libaec::sz)
247-
find_package(libaec ${HDF5_LIBAEC_REQUIRED} BYPASS_PROVIDER)
247+
find_package(libaec ${HDF5_LIBAEC_REQUIRED} QUIET BYPASS_PROVIDER)
248248
endif()
249249
find_library(LIBRARY_Z z ${HDF5_z_REQUIRED} QUIET)
250250
find_library(LIBRARY_SZ sz ${HDF5_sz_REQUIRED} QUIET)
251251
find_library(LIBRARY_libaec aec ${HDF5_libaec_REQUIRED} QUIET)
252-
endfunction()
252+
endfunction()

conanfile.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
class H5ppConan(ConanFile):
1313
name = "h5pp"
1414
version = "2.0.0"
15-
description = "A C++17 wrapper for HDF5 with focus on simplicity"
15+
description = "A C++20 wrapper for HDF5 with focus on simplicity"
1616
homepage = "https://github.com/DavidAce/h5pp"
1717
author = "DavidAce <aceituno@kth.se>"
18-
topics = ("hdf5", "binary", "storage", "header-only", "cpp17")
18+
topics = ("hdf5", "binary", "storage", "header-only", "cpp20")
1919
url = "https://github.com/DavidAce/h5pp"
2020
license = "MIT"
2121
settings = "os", "compiler", "build_type", "arch"
@@ -47,6 +47,7 @@ def _compilers_minimum_version(self):
4747
"Visual Studio": "15.7",
4848
"clang": "6",
4949
"apple-clang": "10",
50+
"msvc": "193",
5051
}
5152

5253
def config_options(self):
@@ -78,14 +79,12 @@ def validate(self):
7879
if self.options.get_safe('with_float128'):
7980
check_min_cppstd(self, 23)
8081
else:
81-
check_min_cppstd(self, 17)
82+
check_min_cppstd(self, 20)
8283

8384
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
8485
if minimum_version:
8586
if Version(self.settings.compiler.version) < minimum_version:
86-
raise ConanInvalidConfiguration("h5pp requires C++17, which your compiler does not support.")
87-
else:
88-
self.output.warning("h5pp requires C++17. Your compiler is unknown. Assuming it supports C++17.")
87+
raise ConanInvalidConfiguration("h5pp requires C++20, which your compiler does not support.")
8988

9089
if self.options.get_safe('with_float128') and self.options.get_safe('with_quadmath'):
9190
raise ConanInvalidConfiguration("These are mutually exclusive options: h5pp:with_float128 and h5pp:with_quadmath")

include/h5pp/details/h5ppFstr.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "h5ppHid.h"
44
#include "h5ppLogger.h"
55
#include "h5ppTypeSfinae.h"
6+
#include <algorithm>
67
#include <charconv>
78
#include <cstdlib>
89
#include <cstring>
@@ -13,6 +14,11 @@
1314
namespace h5pp::type::flen {
1415
namespace internal {
1516
static constexpr bool debug_fstr_t = false;
17+
18+
inline void copy_bytes(char *dst, const char *src, size_t len) {
19+
if(len == 0) return;
20+
std::memcpy(dst, src, len);
21+
}
1622
}
1723

1824
template<size_t N>
@@ -130,7 +136,7 @@ namespace h5pp::type::flen {
130136
template<size_t N>
131137
inline fstr_t<N>::fstr_t(const fstr_t &v) {
132138
if(v.ptr == nullptr) return;
133-
strncpy(ptr, v.ptr, N);
139+
internal::copy_bytes(ptr, v.ptr, N - 1);
134140
ptr[N - 1] = '\0';
135141
#if defined(H5PP_USE_FMT)
136142
if constexpr(internal::debug_fstr_t) h5pp::logger::log->info("fstr_t copied into {}: {}", fmt::ptr(ptr), ptr);
@@ -139,7 +145,7 @@ namespace h5pp::type::flen {
139145
template<size_t N>
140146
inline fstr_t<N>::fstr_t(const char *v) {
141147
if(v == nullptr) return;
142-
strncpy(ptr, v, N);
148+
internal::copy_bytes(ptr, v, std::min(strlen(v), N - 1));
143149
ptr[N - 1] = '\0';
144150
#if defined(H5PP_USE_FMT)
145151
if constexpr(internal::debug_fstr_t) h5pp::logger::log->info("fstr_t copied into {}: {}", fmt::ptr(ptr), ptr);
@@ -148,7 +154,7 @@ namespace h5pp::type::flen {
148154
template<size_t N>
149155
inline fstr_t<N>::fstr_t(std::string_view v) {
150156
if(v.empty()) return;
151-
strncpy(ptr, v.data(), N);
157+
internal::copy_bytes(ptr, v.data(), std::min(v.size(), N - 1));
152158
ptr[N - 1] = '\0';
153159
#if defined(H5PP_USE_FMT)
154160
if constexpr(internal::debug_fstr_t) h5pp::logger::log->info("fstr_t copied into {}: {}", fmt::ptr(ptr), ptr);
@@ -158,7 +164,7 @@ namespace h5pp::type::flen {
158164
template<size_t N>
159165
inline fstr_t<N>::fstr_t(fstr_t &&v) noexcept {
160166
if(v.ptr == nullptr) return;
161-
strncpy(ptr, v.ptr, N);
167+
internal::copy_bytes(ptr, v.ptr, N - 1);
162168
ptr[N - 1] = '\0';
163169
#if defined(H5PP_USE_FMT)
164170
if constexpr(internal::debug_fstr_t) h5pp::logger::log->info("fstr_t copied into {}: {}", fmt::ptr(ptr), ptr);
@@ -173,7 +179,7 @@ namespace h5pp::type::flen {
173179
inline fstr_t<N> &fstr_t<N>::operator=(const fstr_t &v) noexcept {
174180
if(this != &v and ptr != v.ptr) {
175181
clear();
176-
strncpy(ptr, v.ptr, N);
182+
internal::copy_bytes(ptr, v.ptr, N - 1);
177183
ptr[N - 1] = '\0';
178184
#if defined(H5PP_USE_FMT)
179185
if constexpr(internal::debug_fstr_t) h5pp::logger::log->info("fstr_t assigned into {}: {}", fmt::ptr(ptr), ptr);
@@ -184,7 +190,7 @@ namespace h5pp::type::flen {
184190
template<size_t N>
185191
inline fstr_t<N> &fstr_t<N>::operator=(std::string_view v) {
186192
clear();
187-
strncpy(ptr, v.data(), N);
193+
internal::copy_bytes(ptr, v.data(), std::min(v.size(), N - 1));
188194
ptr[N - 1] = '\0';
189195
#if defined(H5PP_USE_FMT)
190196
if constexpr(internal::debug_fstr_t) h5pp::logger::log->info("fstr_t assigned into {}: {}", fmt::ptr(ptr), ptr);
@@ -285,7 +291,7 @@ namespace h5pp::type::flen {
285291
inline void fstr_t<N>::append(const char *v) {
286292
if(v == nullptr) return;
287293
size_t oldlen = size();
288-
strncpy(ptr + oldlen, v, N - oldlen);
294+
internal::copy_bytes(ptr + oldlen, v, std::min(strlen(v), N - oldlen - 1));
289295
ptr[N - 1] = '\0';
290296
#if defined(H5PP_USE_FMT)
291297
if constexpr(internal::debug_fstr_t) h5pp::logger::log->info("fstr_t appended to {} | {} -> {}", fmt::ptr(ptr), v, ptr);
@@ -299,7 +305,13 @@ namespace h5pp::type::flen {
299305

300306
template<size_t N>
301307
inline void fstr_t<N>::append(std::string_view v) {
302-
append(v.data());
308+
if(v.empty()) return;
309+
size_t oldlen = size();
310+
internal::copy_bytes(ptr + oldlen, v.data(), std::min(v.size(), N - oldlen - 1));
311+
ptr[N - 1] = '\0';
312+
#if defined(H5PP_USE_FMT)
313+
if constexpr(internal::debug_fstr_t) h5pp::logger::log->info("fstr_t appended to {} | {} -> {}", fmt::ptr(ptr), v, ptr);
314+
#endif
303315
}
304316

305317
template<size_t N>
@@ -448,4 +460,4 @@ struct fmt::formatter<h5pp::fstr_t<N>> : formatter<std::string_view> {
448460
auto format(const h5pp::fstr_t<N> &f, format_context &ctx) { return fmt::formatter<string_view>::format(f.c_str(), ctx); }
449461
};
450462
#endif
451-
#endif
463+
#endif

include/h5pp/details/h5ppHdf5.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ namespace h5pp::hdf5 {
149149

150150
[[nodiscard]] inline hsize_t getSizeSelected(const hid::h5s &space) {
151151
hssize_t size = H5Sget_select_npoints(space);
152-
if(size < 0) h5pp::runtime_error("getSizeSelected: H5Sget_select_npoints failed");
152+
if(size < 0) throw h5pp::runtime_error("getSizeSelected: H5Sget_select_npoints failed");
153153
return type::safe_cast<hsize_t>(size);
154154
}
155155

@@ -1502,17 +1502,17 @@ namespace h5pp::hdf5 {
15021502
auto newDimensions = dataInfo.dataDims.value();
15031503
if(dataInfo.dataSlab and dataInfo.dataSlab->extent) {
15041504
if(dataInfo.dataDims->size() != dataInfo.dataSlab->extent->size()) {
1505-
h5pp::runtime_error("rank mismatch: \n data dims {}\n data slab {}",
1506-
dataInfo.dataDims.value(),
1507-
dataInfo.dataSlab->string());
1505+
throw h5pp::runtime_error("rank mismatch: \n data dims {}\n data slab {}",
1506+
dataInfo.dataDims.value(),
1507+
dataInfo.dataSlab->string());
15081508
}
15091509
newDimensions = dataInfo.dataSlab->extent.value();
15101510
}
15111511
if(dsetInfo.dsetSlab and dsetInfo.dsetSlab->offset and dsetInfo.dsetSlab->extent) {
15121512
const auto &offset = dsetInfo.dsetSlab->offset.value();
15131513
const auto &extent = dsetInfo.dsetSlab->extent.value();
15141514
if(newDimensions.size() != offset.size() or newDimensions.size() != extent.size())
1515-
h5pp::runtime_error("rank mismatch: \n data dims {}\n dset slab {}", newDimensions, dsetInfo.dsetSlab->string());
1515+
throw h5pp::runtime_error("rank mismatch: \n data dims {}\n dset slab {}", newDimensions, dsetInfo.dsetSlab->string());
15161516
for(size_t idx = 0; idx < newDimensions.size(); idx++)
15171517
newDimensions[idx] = std::max(newDimensions[idx], offset[idx] + extent[idx]);
15181518
}
@@ -2017,7 +2017,7 @@ namespace h5pp::hdf5 {
20172017
haddr_t chaddr = 0;
20182018
hsize_t chsize = 0;
20192019
herr_t eci = H5Dget_chunk_info_by_coord(h5dset, chunkOffset.data(), &mask, &chaddr, &chsize);
2020-
if(eci < 0) h5pp::runtime_error("Failed to get chunk info for offset {}", chunkOffset);
2020+
if(eci < 0) throw h5pp::runtime_error("Failed to get chunk info for offset {}", chunkOffset);
20212021

20222022
if(chsize == 0 or chaddr == HADDR_UNDEF) {
20232023
h5pp::logger::log->trace("Reading chunk at offset {}: chunk is not allocated yet, clearing output buffer", chunkOffset);
@@ -2664,7 +2664,7 @@ namespace h5pp::hdf5 {
26642664
#else
26652665
herr_t reclaim_err = H5Dvlen_reclaim(attrInfo.h5Type.value(), attrInfo.h5Space.value(), H5P_DEFAULT, vdata.data());
26662666
#endif
2667-
if(reclaim_err < 0) h5pp::runtime_error("readAttribute: failed to reclaim variable-length array buffer");
2667+
if(reclaim_err < 0) throw h5pp::runtime_error("readAttribute: failed to reclaim variable-length array buffer");
26682668
} else {
26692669
// All the elements in the dataset have the same string size
26702670
// The whole dataset is read into a contiguous block of memory.
@@ -2944,7 +2944,7 @@ namespace h5pp::hdf5 {
29442944
/* Step 1: Get the dataset and memory spaces */
29452945
std::array<hsize_t, 1> dataDims = {extent.value()}; /* create a simple memory data space */
29462946
hid::h5s dsetSpace = H5Dget_space(info.h5Dset.value()); /* get a copy of the new file data space for writing */
2947-
hid::h5s dataSpace = H5Screate_simple(dataDims.size(), dataDims.data(), nullptr);
2947+
hid::h5s dataSpace = H5Screate_simple(type::safe_cast<int>(dataDims.size()), dataDims.data(), nullptr);
29482948

29492949
/* Step 2: draw a region in the dataset */
29502950
std::array<hsize_t, 1> dsetOffset = {offset.value()};
@@ -3325,12 +3325,12 @@ namespace h5pp::hdf5 {
33253325
herr_t retval = H5Dread(info.h5Dset.value(), h5t_fields, dataSpace, dsetSpace, plists.dsetXfer, vdata.data());
33263326
if(retval < 0) {
33273327
auto h5t_info = getH5TInfo(h5t_fields);
3328-
h5pp::runtime_error("readTableField: H5Dread failed for variable-length field data\n"
3329-
"table [{}] | {}{}{}",
3330-
info.tablePath.value(),
3331-
h5t_info.string(),
3332-
h5t_info.numMembers ? "\n" : "",
3333-
h5t_info.string_members());
3328+
throw h5pp::runtime_error("readTableField: H5Dread failed for variable-length field data\n"
3329+
"table [{}] | {}{}{}",
3330+
info.tablePath.value(),
3331+
h5t_info.string(),
3332+
h5t_info.numMembers ? "\n" : "",
3333+
h5t_info.string_members());
33343334
}
33353335

33363336
// Now vdata contains the dataset selection, and we need to put the data into the user-given container.
@@ -3386,12 +3386,12 @@ namespace h5pp::hdf5 {
33863386

33873387
if(reclaim_err) {
33883388
auto h5t_info = getH5TInfo(h5t_fields);
3389-
h5pp::runtime_error("readTableField: H5Dvlen_reclaim failed when reading variable-length field data\n"
3390-
"table [{}] | {}{}{}",
3391-
info.tablePath.value(),
3392-
h5t_info.string(),
3393-
h5t_info.numMembers ? "\n" : "",
3394-
h5t_info.string_members());
3389+
throw h5pp::runtime_error("readTableField: H5Dvlen_reclaim failed when reading variable-length field data\n"
3390+
"table [{}] | {}{}{}",
3391+
info.tablePath.value(),
3392+
h5t_info.string(),
3393+
h5t_info.numMembers ? "\n" : "",
3394+
h5t_info.string_members());
33953395
}
33963396
return;
33973397
} else if constexpr(std::is_same_v<DataType, std::vector<std::byte>>) {

0 commit comments

Comments
 (0)