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

FIX: store_be(size_t(42)) would not compile on Xcode #4126

Merged
merged 1 commit into from
Jun 15, 2024

Conversation

reneme
Copy link
Collaborator

@reneme reneme commented Jun 14, 2024

Xcode defines uint64_t as "unsigned long long" and size_t as "unsigned long int". Both are 64bit types, but the compiler failed to call reverse_bytes() for size_t regardless. It claimed the call is ambiguous. This was initially found by @FAlbertDev in #4119.

The workaround makes reverse_bytes() an (awful) template that just assumes to get a std::unsigned_integral T and disambiguates on sizeof(T) using if constexpr. I'm certainly open to better ideas. But then again: C++23 will obsolete this anyway.

@reneme reneme added the bug label Jun 14, 2024
@reneme reneme added this to the Botan 3.5.0 milestone Jun 14, 2024
@reneme reneme requested a review from randombit June 14, 2024 14:23
@reneme reneme self-assigned this Jun 14, 2024
Copy link
Collaborator

@FAlbertDev FAlbertDev left a comment

Choose a reason for hiding this comment

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

Thanks! XCode hates this one weird trick.

The affected platform defines uint64_t as "unsigned long long" and size_t
as "unsigned long int". Both are 64bit types, but the compiler failed to
call reverse_bytes() for size_t regardless. It claimed the call is
ambiguous.
@randombit
Copy link
Owner

I'm confused why you would ever want to do this. The number of bytes written will depend on the size of size_t, which means it's not really useful for serialization. What am I missing?

@coveralls
Copy link

Coverage Status

coverage: 91.779% (-0.003%) from 91.782%
when pulling 2f83991 on Rohde-Schwarz:fix/store_be
into 4c3e9dc on randombit:master.

@reneme
Copy link
Collaborator Author

reneme commented Jun 15, 2024

This is not supposed to change any behavior. It's just working around Xcode's compiler not being able to dispatch the overload of reverse_bytes.

See here for a build failure on macOS: https://github.com/randombit/botan/actions/runs/9515856655/job/26230969296?pr=4119

@randombit
Copy link
Owner

This is not supposed to change any behavior.

Sure but my point was that we had not hit this so far because saying store_be(some_size_t) isn't really something that makes sense because the number of bytes emitted depends on the size of size_t, and so isn't really usable for anything. Serialize it, hash it, whatever, the difference in byte count will mean you have different output.

I looked at the specific code in ounsworth.cpp that triggered this and I guess store_be with a size_t is at least usable in that case, because you're post-processing it to truncate unused bytes. This feels like a real edge case to me (wtf is up with these overly complicated variable length encodings) but meh.

@reneme
Copy link
Collaborator Author

reneme commented Jun 15, 2024

Sure but my point was that we had not hit this so far because saying store_be(some_size_t) isn't really something that makes sense because the number of bytes emitted depends on the size of size_t, and so isn't really usable for anything.

True! I didn't even think of that. But that answers: "How did that ever work?" 🤣

@reneme reneme merged commit 9066d9c into randombit:master Jun 15, 2024
41 of 42 checks passed
@reneme reneme deleted the fix/store_be branch June 15, 2024 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants