Fixed bug:

- duplicated members under some conditions (it was not causing any functional issue)

Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
pull/530/head
Quentin JEROME 2 years ago
parent b648e46fe6
commit 68aa8a8d0b

@ -78,13 +78,20 @@ impl StructHelper {
match member_type {
BtfType::Struct(_) => {
// we push the structure name
self.members.push(MemberHelper::new(
p.clone(),
member_offset,
member_type.clone(),
None,
));
// in case of structure containing an unamed union and again
// a struct the algorithm creates duplicates members so
// we need to check if we aleady have the member before insertion.
// this is not optimal, it would be better in a hashmap
if !self.contains_member(p.to_string()) {
// we push the structure name
self.members.push(MemberHelper::new(
p.clone(),
member_offset,
member_type.clone(),
None,
));
}
// we process all members of the structure
self.resolve_members_rec(btf, member_type, &p, member_offset)?;
}
@ -121,9 +128,6 @@ impl StructHelper {
// members of unions all have the same offset
if !matches!(t.kind(), BtfKind::Union) {
// a zero member_size is an issue as two members
// will have the same offsets
debug_assert_ne!(member_size, 0);
member_offset += member_size;
}
}
@ -155,6 +159,11 @@ impl StructHelper {
self.members.iter().find(|m| m.is_path(path))
}
#[inline]
pub(crate) fn contains_member<P: AsRef<str>>(&self, path: P) -> bool {
self.get_member(path).is_some()
}
/// Returns the size of the [`StructHelper`]. This might not be the real size of
/// the structure as it does not take alignement into account. In order to have
/// the size of aligned structure use [`size_of_aligned`] method.

Loading…
Cancel
Save