1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

Fix signed/unsigned char comparison bug

These functions would not working properly if given a high bit char
value.
This commit is contained in:
Jason Rhinelander 2021-02-25 23:40:42 -04:00
parent 00df8b85da
commit 8b00eacabf

View file

@ -94,8 +94,9 @@ llarp_buffer_t::read_uint64(uint64_t& i)
} }
size_t size_t
llarp_buffer_t::read_until(char delim, byte_t* result, size_t resultsize) llarp_buffer_t::read_until(char c_delim, byte_t* result, size_t resultsize)
{ {
const auto delim = static_cast<byte_t>(c_delim);
size_t read = 0; size_t read = 0;
// do the bound check first, to avoid over running // do the bound check first, to avoid over running
@ -115,8 +116,9 @@ llarp_buffer_t::read_until(char delim, byte_t* result, size_t resultsize)
} }
bool bool
operator==(const llarp_buffer_t& buff, const char* str) operator==(const llarp_buffer_t& buff, const char* c_str)
{ {
const auto* str = reinterpret_cast<const byte_t*>(c_str);
ManagedBuffer copy{buff}; ManagedBuffer copy{buff};
while (*str && copy.underlying.cur != (copy.underlying.base + copy.underlying.sz)) while (*str && copy.underlying.cur != (copy.underlying.base + copy.underlying.sz))
{ {