Skip to content

Commit

Permalink
Ignore GCC array bounds warning
Browse files Browse the repository at this point in the history
  • Loading branch information
mborland committed Nov 11, 2024
1 parent cd8bc39 commit 375acff
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/boost/crypt/drbg/hmac_drbg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ auto hmac_drbg<HMACType, max_hasher_security, outlen, prediction_resistance>::up
BOOST_CRYPT_ASSERT(value_.size() + 1U + provided_data_size <= storage_size);
static_cast<void>(storage_size);

// GCC optimizes this to memcpy (like it should),
// but then complains about theoretical array boundaries (provided_data_size can be 0)
#if defined(__GNUC__) && __GNUC__ >= 5
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds="
#endif

// Step 1: V || 0x00 || provided data
boost::crypt::size_t offset {};
for (boost::crypt::size_t i {}; i < value_.size(); ++i)
Expand All @@ -129,6 +136,10 @@ auto hmac_drbg<HMACType, max_hasher_security, outlen, prediction_resistance>::up
storage[offset++] = static_cast<boost::crypt::uint8_t>(provided_data[i]);
}

#if defined(__GNUC__) && __GNUC__ >= 5
#pragma GCC diagnostic pop
#endif

HMACType hmac(key_);
hmac.process_bytes(storage, offset);
key_ = hmac.get_digest();
Expand Down

0 comments on commit 375acff

Please sign in to comment.