Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

size fix #120

Merged
merged 2 commits into from
Dec 1, 2024
Merged

size fix #120

merged 2 commits into from
Dec 1, 2024

Conversation

hchataing
Copy link
Collaborator

  • Missing () in generated payload size encoder
  • Add semantic test for payload size field encoding

Copy link
Collaborator

@mgeisler mgeisler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the changes and it's not actually clear to me which of them fixes anything?

@@ -457,7 +457,7 @@ impl Packet for GrandChild {
maximum_size: 0xff,
});
}
buf.put_u8(2 + self.payload.len() as u8);
buf.put_u8((2 + self.payload.len()) as u8);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks like it could be a fix. However, on a second look,

(2 + self.payload.len()) as u8

and

2 + (self.payload.len() as u8)

should give the same result, right? Will the 2 literal not be type-inferred to be a u8 here?

Is the problem with very large integers (larger than i32?) which can overflow in some way?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is more apparent on this declaration:

little_endian_packets

struct Elem {
    _size_(value) : 8,
    value : 8[],
}

packet Parent {
    _size_(_payload_) : 8,
    _payload_,
}

packet Child : Parent {
    b : Elem,
    d : Elem,
}

The generated code for <Child as Packet>::encode contained the following line which was missing parentheses

buf.put_u8(self.b.encoded_len() + self.d.encoded_len() as u8);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the added semantic test to properly check this output.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, now I see the problem clearly! Thanks 🙂

@hchataing hchataing merged commit 7bc6880 into main Dec 1, 2024
8 checks passed
@hchataing hchataing deleted the size-fix branch December 1, 2024 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants