Bug 1757565 - Explicitly cast from size_t to uint32_t in nsTStringLengthStorage. r=xpcom-reviewers,mccr8

I was looking at what all fails with -Werror=shorten-64-to-32
and this showed up prominently.

Differential Revision: https://phabricator.services.mozilla.com/D139940
This commit is contained in:
Jeff Muizelaar 2022-03-01 16:06:23 +00:00
parent 76ca55d0b9
commit 2f82844d6b

View File

@ -80,12 +80,12 @@ class nsTStringLengthStorage {
// Implicit conversion and assignment from `size_t` which assert that the
// value is in-range.
MOZ_IMPLICIT constexpr nsTStringLengthStorage(size_t aLength)
: mLength(aLength) {
: mLength(static_cast<uint32_t>(aLength)) {
MOZ_RELEASE_ASSERT(aLength <= kMax, "string is too large");
}
constexpr nsTStringLengthStorage& operator=(size_t aLength) {
MOZ_RELEASE_ASSERT(aLength <= kMax, "string is too large");
mLength = aLength;
mLength = static_cast<uint32_t>(aLength);
return *this;
}
MOZ_IMPLICIT constexpr operator size_t() const { return mLength; }