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

Rework Id creation to check statically for invalid IDs #230

Merged
merged 8 commits into from
Jan 28, 2024

Conversation

robUx4
Copy link
Contributor

@robUx4 robUx4 commented Jan 27, 2024

Maybe it's possible with std::enable_if but I haven't managed to do it. Not sure it would be usable on reading though.

We don't need to pass the length of the ID anymore (we may not even store it anymore).

libmatroska will need this to build Matroska-Org/libmatroska#169

@robUx4 robUx4 added enhancement api-break breaks the API (e.g. programs using it will have to adjust their source code) abi-break breaks the ABI (e.g. programs linked against the library have to be recompiled) labels Jan 27, 2024
Copy link
Contributor

@mbunkus mbunkus left a comment

Choose a reason for hiding this comment

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

Cannot test further at the moment, as the corresponding libMatroska PR doesn't merge anymore due to conflicts in KaxSemantic.cpp after merging some other PR.

ebml/EbmlId.h Outdated
return Value >= 0x4000;
if (Value < 0x1000000)
return Value >= 0x200000;
return Value >= 0x10000000;
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong indentation for the last return.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I'll rebase the branches soon.

It's a 32-bit value, there's only 4 possible lengths.
In C++17 that implies "inline".
It's deduced during contruction.
An EbmlId can never be bigger that 4. There is no constructor with a value higher than 4 bytes.
It can never be lower than 0 as it's unsigned.
It can never be 0 because a value of 0 corresponds to 0x80 in EBML.
When we have a buffer we can convert it to an Id value.
@mbunkus mbunkus merged commit 94cc560 into Matroska-Org:master Jan 28, 2024
15 checks passed
@robUx4 robUx4 deleted the id_length branch January 28, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abi-break breaks the ABI (e.g. programs linked against the library have to be recompiled) api-break breaks the API (e.g. programs using it will have to adjust their source code) enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants