Bug 1312104 - part 1 - use BitwiseCast for punning between uint64_t/double in indexedDB; r=janv

We have code elsewhere for this sort of stuff; let's use it here.
This commit is contained in:
Nathan Froyd 2016-10-24 13:22:54 -04:00
Родитель 3e0e4383f2
Коммит 7f6b03f97d
2 изменённых файлов: 11 добавлений и 21 удалений

Просмотреть файл

@ -21,6 +21,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/AppProcessChecker.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/Casting.h"
#include "mozilla/EndianUtils.h"
#include "mozilla/LazyIdleThread.h"
#include "mozilla/Maybe.h"
@ -18960,12 +18961,7 @@ uint64_t
DatabaseOperationBase::ReinterpretDoubleAsUInt64(double aDouble)
{
// This is a duplicate of the js engine's byte munging in StructuredClone.cpp
union {
double d;
uint64_t u;
} pun;
pun.d = aDouble;
return pun.u;
return BitwiseCast<uint64_t>(aDouble);
}
// static

Просмотреть файл

@ -12,6 +12,7 @@
#include "js/Date.h"
#include "js/Value.h"
#include "jsfriendapi.h"
#include "mozilla/Casting.h"
#include "mozilla/EndianUtils.h"
#include "mozilla/FloatingPoint.h"
#include "mozIStorageStatement.h"
@ -594,11 +595,6 @@ Key::DecodeString(const unsigned char*& aPos, const unsigned char* aEnd,
aPos = iter + 1;
}
union Float64Union {
double d;
uint64_t u;
};
void
Key::EncodeNumber(double aFloat, uint8_t aType)
{
@ -612,13 +608,12 @@ Key::EncodeNumber(double aFloat, uint8_t aType)
*(buffer++) = aType;
Float64Union pun;
pun.d = aFloat;
uint64_t bits = BitwiseCast<uint64_t>(aFloat);
// Note: The subtraction from 0 below is necessary to fix
// MSVC build warning C4146 (negating an unsigned value).
uint64_t number = pun.u & PR_UINT64(0x8000000000000000) ?
(0 - pun.u) :
(pun.u | PR_UINT64(0x8000000000000000));
uint64_t number = bits & PR_UINT64(0x8000000000000000) ?
(0 - bits) :
(bits | PR_UINT64(0x8000000000000000));
mozilla::BigEndian::writeUint64(buffer, number);
}
@ -638,14 +633,13 @@ Key::DecodeNumber(const unsigned char*& aPos, const unsigned char* aEnd)
aPos += sizeof(number);
Float64Union pun;
// Note: The subtraction from 0 below is necessary to fix
// MSVC build warning C4146 (negating an unsigned value).
pun.u = number & PR_UINT64(0x8000000000000000) ?
(number & ~PR_UINT64(0x8000000000000000)) :
(0 - number);
uint64_t bits = number & PR_UINT64(0x8000000000000000) ?
(number & ~PR_UINT64(0x8000000000000000)) :
(0 - number);
return pun.d;
return BitwiseCast<double>(bits);
}
void