diff options
author | Dana Robinson <43805+derobins@users.noreply.github.com> | 2022-07-11 15:59:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-11 15:59:51 (GMT) |
commit | fa7caf843508b250f085e88cf5edfc2606da1205 (patch) | |
tree | 8ecc6f13d62952ab8ee49ea59bae9c2a47684e9b /c++/src/H5Exception.cpp | |
parent | f599e2ac7fb7fb146b49e2f349a9c100e897f7ef (diff) | |
download | hdf5-fa7caf843508b250f085e88cf5edfc2606da1205.zip hdf5-fa7caf843508b250f085e88cf5edfc2606da1205.tar.gz hdf5-fa7caf843508b250f085e88cf5edfc2606da1205.tar.bz2 |
Fixes C++ sign-conversion warnings w/ clang 14 (#1870)
* Fixes sign-conversion warnings w/ clang 14
* Committing clang-format changes
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'c++/src/H5Exception.cpp')
-rw-r--r-- | c++/src/H5Exception.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/c++/src/H5Exception.cpp b/c++/src/H5Exception.cpp index a42c151..5687514 100644 --- a/c++/src/H5Exception.cpp +++ b/c++/src/H5Exception.cpp @@ -73,9 +73,14 @@ Exception::getMajorString(hid_t err_major) const if (mesg_size < 0) throw IdComponentException("Exception::getMajorString", "H5Eget_msg failed"); + // The actual message size is the cast value + 1 for the terminal ASCII NUL + // (unfortunate in/out type sign mismatch) + size_t actual_mesg_size = static_cast<size_t>(mesg_size) + 1; + // Call H5Eget_msg again to get the actual message - char *mesg_C = new char[mesg_size + 1]; // temporary C-string for C API - mesg_size = H5Eget_msg(err_major, NULL, mesg_C, mesg_size + 1); + char *mesg_C = new char[actual_mesg_size]; // temporary C-string for C API + + mesg_size = H5Eget_msg(err_major, NULL, mesg_C, actual_mesg_size); // Check for failure again if (mesg_size < 0) { @@ -110,9 +115,14 @@ Exception::getMinorString(hid_t err_minor) const if (mesg_size < 0) throw IdComponentException("Exception::getMinorString", "H5Eget_msg failed"); + // The actual message size is the cast value + 1 for the terminal ASCII NUL + // (unfortunate in/out type sign mismatch) + size_t actual_mesg_size = static_cast<size_t>(mesg_size) + 1; + // Call H5Eget_msg again to get the actual message - char *mesg_C = new char[mesg_size + 1]; // temporary C-string for C API - mesg_size = H5Eget_msg(err_minor, NULL, mesg_C, mesg_size + 1); + char *mesg_C = new char[actual_mesg_size]; // temporary C-string for C API + + mesg_size = H5Eget_msg(err_minor, NULL, mesg_C, actual_mesg_size); // Check for failure again if (mesg_size < 0) { |