Skip to content

Commit

Permalink
Fix #1291 Do not assert when --dump-packet-data option is enabled ... (
Browse files Browse the repository at this point in the history
…#1293)

* Fix #1291 Do not assert when --dump-packet-data option is enabled ...
... when sending a length 0 packet.

Granted this is an unusual situation, but there are test programs for
p4c and p4testgen where p4testgen creates tests where the expected
output packet is 0 bytes long, and if you run them while enabling
--dump-packet-data N option for behavioral-model, simple_switch
crashes with an assert.

Signed-off-by: Andy Fingerhut <[email protected]>

* Defensive programming

Signed-off-by: Andy Fingerhut <[email protected]>

* Address review commments.

Signed-off-by: Andy Fingerhut <[email protected]>

---------

Signed-off-by: Andy Fingerhut <[email protected]>
  • Loading branch information
jafingerhut authored Feb 19, 2025
1 parent a5afc50 commit d12eefc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/bm_sim/dev_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ DevMgr::clear_port_stats(port_t port_num) {
std::string
DevMgr::sample_packet_data(const char *buffer, int len) {
size_t amount = std::min(dump_packet_data, static_cast<size_t>(len));
assert(amount > 0);
if (amount == 0) {
return "";
}
std::ostringstream ret;
utils::dump_hexstring(ret, &buffer[0], &buffer[amount]);
return ret.str();
Expand Down

0 comments on commit d12eefc

Please sign in to comment.