@@ -193,7 +193,7 @@ Response Response::from_bits(const std::vector<uint8_t>& response, const Nonce&
193193 const size_t size = path.size ();
194194 const size_t levels = size / 64 ;
195195
196- if (size % 64 ) {
196+ if (size % 64 != 0 ) {
197197 throw Roughtime_Error (" Merkle tree path size must be multiple of 64 bytes" );
198198 }
199199 if (indx >= (1U << levels)) {
@@ -204,7 +204,7 @@ Response Response::from_bits(const std::vector<uint8_t>& response, const Nonce&
204204 auto hash = hashLeaf (nonce.get_nonce ());
205205 auto index = indx;
206206 for (std::size_t level = 0 ; level < levels; ++level) {
207- hashNode (hash, slicer.take <64 >(), index & 1 );
207+ hashNode (hash, slicer.take <64 >(), index % 2 == 1 );
208208 index >>= 1 ;
209209 }
210210
@@ -291,9 +291,9 @@ Chain::Chain(std::string_view str) {
291291
292292std::vector<Response> Chain::responses () const {
293293 std::vector<Response> responses;
294- for (unsigned i = 0 ; i < m_links.size (); ++i) {
294+ for (size_t i = 0 ; i < m_links.size (); ++i) {
295295 const auto & l = m_links[i];
296- const auto nonce = i ? nonce_from_blind (m_links[i - 1 ].response (), l.nonce_or_blind ()) : l.nonce_or_blind ();
296+ const auto nonce = i > 0 ? nonce_from_blind (m_links[i - 1 ].response (), l.nonce_or_blind ()) : l.nonce_or_blind ();
297297 const auto response = Response::from_bits (l.response (), nonce);
298298 if (!response.validate (l.public_key ())) {
299299 throw Roughtime_Error (" Invalid signature or public key" );
@@ -365,7 +365,7 @@ std::vector<uint8_t> online_request(std::string_view uri, const Nonce& nonce, st
365365 // add one additional byte to be able to differentiate if datagram got truncated
366366 const auto n = socket->read (buffer.data (), buffer.size ());
367367
368- if (!n || std::chrono::system_clock::now () - start_time > timeout) {
368+ if (n == 0 || std::chrono::system_clock::now () - start_time > timeout) {
369369 throw System_Error (" Timeout waiting for response" );
370370 }
371371
0 commit comments