Skip to content

Commit

Permalink
Bugs fixes.
Browse files Browse the repository at this point in the history
Correct version of name_for_agent_t's move operator.

Correct version of agent_identity_t::pointer_only_t::make_c_string.
  • Loading branch information
eao197 committed Mar 15, 2024
1 parent 964d23e commit fd224ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions dev/so_5/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,25 @@ agent_identity_t::pointer_only_t::make_c_string() const noexcept

// NOTE: this code won't compile if there is no std::uintptr_t type,
// but we don't care about such platforms at the moment.
std::uintptr_t ptr_as_uint = reinterpret_cast<std::uintptr_t>(m_pointer_value);
std::uintptr_t ptr_as_uint =
reinterpret_cast<std::uintptr_t>(m_pointer_value);

// Handle by 4 bits portions from the most significant bit.
// Leading zeros are not skipped (for the simplicity of implementation).
unsigned bits_to_process = sizeof(void *) * 8u;
while( bits_to_process >= 4u )
constexpr unsigned int half_octet = 4u;
unsigned bits_to_process = sizeof(void *) * (half_octet * 2u);
while( bits_to_process >= half_octet )
{
const auto v = (ptr_as_uint >> (bits_to_process - 4u)) & 0x0Fu;
const std::size_t index = static_cast<std::size_t>( v );
const auto index = static_cast<std::size_t>(
(ptr_as_uint >> (bits_to_process - half_octet)) & 0x0Fu
);

*(it++) = hex_symbols[ index ];

bits_to_process -= 4u;
bits_to_process -= half_octet;
}

*(it++) = '>'; ++it;
*(it++) = '>';
*it = 0;

return result;
Expand Down Expand Up @@ -137,7 +141,7 @@ name_for_agent_t &
name_for_agent_t::operator=( name_for_agent_t && other ) noexcept
{
name_for_agent_t tmp{ std::move(other) };
swap( *this, other );
swap( *this, tmp );
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion dev/so_5/agent_identity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class agent_identity_t

// NOTE: this method is implemented in agent.cpp source file.
//! Make a c-string with text representation of a value.
SO_5_FUNC [[nodiscard]]
[[nodiscard]] SO_5_FUNC
std::array<char, c_string_size>
make_c_string() const noexcept;
};
Expand Down

0 comments on commit fd224ab

Please sign in to comment.