Skip to content

Commit

Permalink
Improve padding calculation in eBPF parser (#3254)
Browse files Browse the repository at this point in the history
  • Loading branch information
tatry authored Apr 27, 2022
1 parent abd523b commit cbc46de
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion backends/ebpf/ebpfParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ StateTranslationVisitor::compileExtract(const IR::Expression* destination) {
auto etype = EBPFTypeFactory::instance->create(ftype);
if (etype->is<EBPFScalarType>()) {
auto scalarType = etype->to<EBPFScalarType>();
unsigned padding = scalarType->alignment() * 8 - scalarType->widthInBits();
unsigned readWordSize = scalarType->alignment() * 8;
unsigned unaligned = scalarType->widthInBits() % readWordSize;
unsigned padding = readWordSize - unaligned;
if (padding == readWordSize)
padding = 0;
if (scalarType->widthInBits() + padding >= curr_padding) {
curr_padding = padding;
}
Expand Down

0 comments on commit cbc46de

Please sign in to comment.