mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Fix invalid use of strlen in read_attribute
This commit is contained in:
parent
407e40fec3
commit
46a7058c70
1 changed files with 7 additions and 1 deletions
|
|
@ -202,7 +202,13 @@ read_attribute(hid_t obj_id, const char* name, std::vector<std::string>& vec)
|
|||
read_attr_string(obj_id, name, n, buffer[0]);
|
||||
|
||||
for (int i = 0; i < m; ++i) {
|
||||
vec.emplace_back(&buffer[i][0], std::min(strlen(buffer[i]), n));
|
||||
// Determine proper length of string -- strlen doesn't work because
|
||||
// buffer[i] might not have any null characters
|
||||
std::size_t k = 0;
|
||||
for (; k < n; ++k) if (buffer[i][k] == '\0') break;
|
||||
|
||||
// Create string based on (char*, size_t) constructor
|
||||
vec.emplace_back(&buffer[i][0], k);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue