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/H5Attribute.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/H5Attribute.cpp')
-rw-r--r-- | c++/src/H5Attribute.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index a0aa33f..c9490ee 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -235,8 +235,9 @@ Attribute::getInMemDataSize() const } // Calculate and return the size of the data - size_t data_size = type_size * num_elements; - return (data_size); + size_t data_size = type_size * static_cast<size_t>(num_elements); + + return data_size; } //-------------------------------------------------------------------------- @@ -324,11 +325,15 @@ Attribute::getName() const } // Attribute's name exists, retrieve it else if (name_size > 0) { + // The actual size is the cast value + 1 for the terminal ASCII NUL + // (unfortunate in/out type sign mismatch) + size_t actual_name_size = static_cast<size_t>(name_size) + 1; + // Create buffer for C string - char *name_C = new char[name_size + 1](); + char *name_C = new char[actual_name_size](); // Use overloaded function - name_size = getName(name_C, name_size + 1); + name_size = getName(name_C, actual_name_size); // Convert the C attribute name to return attr_name = name_C; @@ -338,7 +343,7 @@ Attribute::getName() const } // Return attribute's name - return (attr_name); + return attr_name; } //-------------------------------------------------------------------------- @@ -390,7 +395,7 @@ Attribute::getName(H5std_string &attr_name, size_t len) const // If no length is provided, get the entire attribute name if (len == 0) { attr_name = getName(); - name_size = attr_name.length(); + name_size = static_cast<ssize_t>(attr_name.length()); } // If length is provided, get that number of characters in name else { @@ -409,7 +414,7 @@ Attribute::getName(H5std_string &attr_name, size_t len) const // Otherwise, keep attr_name intact // Return name size - return (name_size); + return name_size; } //-------------------------------------------------------------------------- |