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

Use exception rather than assertion for parsing data #344

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

harryz2000
Copy link
Contributor

No description provided.

@@ -39,7 +39,8 @@ class BitReader

inline DWORD Get(DWORD n)
{
assert(n <= 32);
if (n > 32)
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer this, but it means that someone is calling Get() asking for more bits of data than are possible to fit in the DWORD. I.e. Is a bug in the caller really which assert() is theoretically correct for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we should be that strict. Passing n shouldn't be illegal but just invalid. The argument could be from data not from our manual input. So I don't think calling it with a value more than 32 is a bug. If we use assert, we must check it before passing it to this Get() function, which would be not convenient and I think that is against our intention to use exception.

Copy link
Contributor

@bcostdolby bcostdolby left a comment

Choose a reason for hiding this comment

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

lgtm

@harryz2000 harryz2000 merged commit ad16a28 into master Sep 13, 2024
2 checks passed
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