Skip to content

Commit 31440b5

Browse files
committed
Fix: You also need to pass the length of the name, the other method only works if the string in the variable length array is zero-terminated which can not be guaranteed.
1 parent 10020f4 commit 31440b5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/util/registry/Registry.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Registry final : public registry::Registry
8181

8282
TAccessResponse onAccess_1_0_Request_Received(TAccessRequest const &req)
8383
{
84-
auto const req_name = std::string_view(reinterpret_cast<const char *>(req.name.name.cbegin()));
84+
auto const req_name = std::string_view(reinterpret_cast<const char *>(req.name.name.cbegin()), req.name.name.size());
8585

8686
/* Try to set the registers value. Note, if this is a RO register
8787
* this call will fail with SetError::Mutability.

src/util/storage/register_storage.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace cyphal::support
3030
{
3131
// Find the next register in the registry.
3232
const auto reg_name_storage = rgy.index(index); // This is a little suboptimal but we don't care.
33-
const auto reg_name = std::string_view(reinterpret_cast<const char *>(reg_name_storage.name.cbegin()));
33+
const auto reg_name = std::string_view(reinterpret_cast<const char *>(reg_name_storage.name.cbegin()), reg_name_storage.name.size());
3434
if (reg_name.empty())
3535
{
3636
break; // No more registers to load.
@@ -89,7 +89,7 @@ template <typename ResetPredicate>
8989
for (std::size_t index = 0; index < rgy.size(); index++)
9090
{
9191
const auto reg_name_storage = rgy.index(index); // This is a little suboptimal but we don't care.
92-
const auto reg_name = std::string_view(reinterpret_cast<const char *>(reg_name_storage.name.cbegin()));
92+
const auto reg_name = std::string_view(reinterpret_cast<const char *>(reg_name_storage.name.cbegin()), reg_name_storage.name.size());
9393
if (reg_name.empty())
9494
{
9595
break; // No more registers to load.

0 commit comments

Comments
 (0)