-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
static_cast<size_t> for QByteArray::size with std::max #4406
Conversation
src/util/cache.cpp
Outdated
@@ -16,7 +16,7 @@ cache_key_t cacheKeyFromMessageDigest(const QByteArray& messageDigest) { | |||
// 5 Hash function Usage | |||
// 5.1 Truncated Message Digest | |||
const auto significantByteCount = math_min( | |||
messageDigest.size(), | |||
static_cast<int>(messageDigest.size()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead better remove the static_cast<int>
casts. This should work. I expect that qsizetype
is an alias for size_t
on all platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried. It does not work with Qt5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I did not find documentation on qsizetype.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size_t is unsigned
qsizetype is ptrdiff_t wich is the signed counterpart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, what do you suggest as an alternative solution? Or just merge this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://doc.qt.io/qt-5/qtglobal.html#qsizetype-alias
We should either cast to qsizetype or size_t. Since the size() cannot be negative and sizeof is implicitly of type size_t this would be my preferred choice.
93625fb
to
326ed3c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for CI
src/util/cache.cpp
Outdated
for (auto i = 0; i < significantByteCount; ++i) { | ||
static_cast<size_t>(messageDigest.size()), | ||
sizeof(cache_key_t)); | ||
for (unsigned int i = 0; i < significantByteCount; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (unsigned int i = 0; i < significantByteCount; ++i) { | |
for (size_t i = 0; i < significantByteCount; ++i) { |
The case that size_t is an unsigned type can be considered as design flaw of the early c++ standard.
In Mixxx we have introduced SINT as ptrdiff_t because it allows auto factorization.
Line 13 in f2d670e
typedef std::ptrdiff_t SINT; |
So If you looking for a general patter to resolve this issue use ptrdiff_t.
326ed3c
to
6766e4a
Compare
QByteArray::size returns qsizetype in Qt6, which needs to be converted to size_t to pass to std::max.
6766e4a
to
1ebc690
Compare
CI passed. Merge? |
Thank you. |
QByteArray::size returns qsizetype in Qt6, which needs to be
converted to an int to pass to std::max.