Skip to content

Commit

Permalink
Merge pull request #4161 from YosysHQ/nak/add_sig_extract_asserts
Browse files Browse the repository at this point in the history
SigSpec/SigChunk::extract(): assert offset/length are not out of range
  • Loading branch information
nakengelhardt authored Jan 29, 2024
2 parents 2f4dd99 + efe4d6d commit 027cb31
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions kernel/rtlil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3686,6 +3686,9 @@ RTLIL::SigChunk::SigChunk(const RTLIL::SigBit &bit)

RTLIL::SigChunk RTLIL::SigChunk::extract(int offset, int length) const
{
log_assert(offset >= 0);
log_assert(length >= 0);
log_assert(offset + length <= width);
RTLIL::SigChunk ret;
if (wire) {
ret.wire = wire;
Expand Down Expand Up @@ -4398,6 +4401,9 @@ void RTLIL::SigSpec::remove(int offset, int length)

RTLIL::SigSpec RTLIL::SigSpec::extract(int offset, int length) const
{
log_assert(offset >= 0);
log_assert(length >= 0);
log_assert(offset + length <= width_);
unpack();
cover("kernel.rtlil.sigspec.extract_pos");
return std::vector<RTLIL::SigBit>(bits_.begin() + offset, bits_.begin() + offset + length);
Expand Down

0 comments on commit 027cb31

Please sign in to comment.