diff options
Diffstat (limited to 'c++/src/H5Object.cpp')
-rw-r--r-- | c++/src/H5Object.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index cb803af..d092ef0 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -497,11 +497,16 @@ H5Object::getObjName() const } // Object'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 = getObjName(name_C, name_size + 1); + name_size = getObjName(name_C, actual_name_size); // Convert the C object name to return obj_name = name_C; @@ -509,8 +514,9 @@ H5Object::getObjName() const // Clean up resource delete[] name_C; } + // Return object's name - return (obj_name); + return obj_name; } //-------------------------------------------------------------------------- @@ -534,7 +540,7 @@ H5Object::getObjName(H5std_string &obj_name, size_t len) const // If no length is provided, get the entire object name if (len == 0) { obj_name = getObjName(); - name_size = obj_name.length(); + name_size = static_cast<ssize_t>(obj_name.length()); } // If length is provided, get that number of characters in name else { @@ -553,7 +559,7 @@ H5Object::getObjName(H5std_string &obj_name, size_t len) const // Otherwise, keep obj_name intact // Return name size - return (name_size); + return name_size; } #ifndef DOXYGEN_SHOULD_SKIP_THIS |