本文整理汇总了C++中CheckedInt::value方法的典型用法代码示例。如果您正苦于以下问题:C++ CheckedInt::value方法的具体用法?C++ CheckedInt::value怎么用?C++ CheckedInt::value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CheckedInt
的用法示例。
在下文中一共展示了CheckedInt::value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ScanForMetadata
already_AddRefed<mozilla::MediaByteBuffer>
MoofParser::Metadata()
{
MediaByteRange moov;
ScanForMetadata(moov);
CheckedInt<MediaByteBuffer::size_type> moovLength = moov.Length();
if (!moovLength.isValid() || !moovLength.value()) {
// No moov, or cannot be used as array size.
return nullptr;
}
RefPtr<MediaByteBuffer> metadata = new MediaByteBuffer();
if (!metadata->SetLength(moovLength.value(), fallible)) {
LOG(Moof, "OOM");
return nullptr;
}
RefPtr<BlockingStream> stream = new BlockingStream(mSource);
size_t read;
bool rv =
stream->ReadAt(moov.mStart, metadata->Elements(), moovLength.value(), &read);
if (!rv || read != moovLength.value()) {
return nullptr;
}
return metadata.forget();
}
示例2: MakeSpan
nsresult
mozHunspell::ConvertCharset(const nsAString& aStr, std::string& aDst)
{
if (NS_WARN_IF(!mEncoder)) {
return NS_ERROR_NOT_INITIALIZED;
}
auto src = MakeSpan(aStr.BeginReading(), aStr.Length());
CheckedInt<size_t> needed =
mEncoder->MaxBufferLengthFromUTF16WithoutReplacement(src.Length());
if (!needed.isValid()) {
return NS_ERROR_OUT_OF_MEMORY;
}
aDst.resize(needed.value());
char* dstPtr = &aDst[0];
auto dst = MakeSpan(reinterpret_cast<uint8_t*>(dstPtr), needed.value());
uint32_t result;
size_t read;
size_t written;
Tie(result, read, written) =
mEncoder->EncodeFromUTF16WithoutReplacement(src, dst, true);
Unused << read;
MOZ_ASSERT(result != kOutputFull);
if (result != kInputEmpty) {
return NS_ERROR_UENC_NOMAPPING;
}
aDst.resize(written);
mEncoder->Encoding()->NewEncoderInto(*mEncoder);
return NS_OK;
}
示例3:
size_t
LZ4::compressLimitedOutput(const char* aSource, size_t aInputSize, char* aDest,
size_t aMaxOutputSize)
{
CheckedInt<int> inputSizeChecked = aInputSize;
MOZ_ASSERT(inputSizeChecked.isValid());
CheckedInt<int> maxOutputSizeChecked = aMaxOutputSize;
MOZ_ASSERT(maxOutputSizeChecked.isValid());
return LZ4_compress_limitedOutput(aSource, aDest, inputSizeChecked.value(),
maxOutputSizeChecked.value());
}
示例4: BytesPerPixel
int32_t
ComputeRGBStride(SurfaceFormat aFormat, int32_t aWidth)
{
CheckedInt<int32_t> size = BytesPerPixel(aFormat);
size *= aWidth;
if (!size.isValid() || size.value() <= 0) {
gfxDebug() << "ComputeStride overflow " << aWidth;
return 0;
}
return GetAlignedStride<4>(size.value());
}
示例5: LOG
void
RequestContext::ScheduleUnblock()
{
MOZ_ASSERT(!IsNeckoChild());
MOZ_ASSERT(NS_IsMainThread());
if (!gHttpHandler) {
return;
}
uint32_t quantum = gHttpHandler->TailBlockingDelayQuantum(mAfterDOMContentLoaded);
uint32_t delayMax = gHttpHandler->TailBlockingDelayMax();
uint32_t totalMax = gHttpHandler->TailBlockingTotalMax();
if (!mBeginLoadTime.IsNull()) {
// We decrease the maximum delay progressively with the time since the page load
// begin. This seems like a reasonable and clear heuristic allowing us to start
// loading tailed requests in a deterministic time after the load has started.
uint32_t sinceBeginLoad = static_cast<uint32_t>(
(TimeStamp::NowLoRes() - mBeginLoadTime).ToMilliseconds());
uint32_t tillTotal = totalMax - std::min(sinceBeginLoad, totalMax);
uint32_t proportion = totalMax // values clamped between 0 and 60'000
? (delayMax * tillTotal) / totalMax
: 0;
delayMax = std::min(delayMax, proportion);
}
CheckedInt<uint32_t> delay = quantum * mNonTailRequests;
if (!mAfterDOMContentLoaded) {
// Before DOMContentLoaded notification we want to make sure that tailed
// requests don't start when there is a short delay during which we may
// not have any active requests on the page happening.
delay += quantum;
}
if (!delay.isValid() || delay.value() > delayMax) {
delay = delayMax;
}
LOG(("RequestContext::ScheduleUnblock this=%p non-tails=%u tail-queue=%zu delay=%u after-DCL=%d",
this, mNonTailRequests, mTailQueue.Length(), delay.value(), mAfterDOMContentLoaded));
TimeStamp now = TimeStamp::NowLoRes();
mUntailAt = now + TimeDuration::FromMilliseconds(delay.value());
if (mTimerScheduledAt.IsNull() || mUntailAt < mTimerScheduledAt) {
LOG(("RequestContext %p timer would fire too late, rescheduling", this));
RescheduleUntailTimer(now);
}
}
示例6: associateBufferSubDataImpl
bool WebGLBuffer::associateBufferSubDataImpl(GC3Dintptr offset, ArrayBuffer* array, GC3Dintptr arrayByteOffset, GC3Dsizeiptr byteLength)
{
if (!array || offset < 0 || arrayByteOffset < 0 || byteLength < 0)
return false;
if (byteLength) {
CheckedInt<GC3Dintptr> checkedBufferOffset(offset);
CheckedInt<GC3Dintptr> checkedArrayOffset(arrayByteOffset);
CheckedInt<GC3Dsizeiptr> checkedLength(byteLength);
CheckedInt<GC3Dintptr> checkedArrayMax = checkedArrayOffset + checkedLength;
CheckedInt<GC3Dintptr> checkedBufferMax = checkedBufferOffset + checkedLength;
if (!checkedArrayMax.valid() || checkedArrayMax.value() > static_cast<int32_t>(array->byteLength()) || !checkedBufferMax.valid() || checkedBufferMax.value() > m_byteLength)
return false;
}
switch (m_target) {
case GraphicsContext3D::ELEMENT_ARRAY_BUFFER:
clearCachedMaxIndices();
if (byteLength) {
if (!m_elementArrayBuffer)
return false;
memcpy(static_cast<unsigned char*>(m_elementArrayBuffer->data()) + offset,
static_cast<unsigned char*>(array->data()) + arrayByteOffset,
byteLength);
}
return true;
case GraphicsContext3D::ARRAY_BUFFER:
return true;
default:
return false;
}
}
示例7: PodMove
void
AudioBuffer::CopyToChannel(JSContext* aJSContext, const Float32Array& aSource,
uint32_t aChannelNumber, uint32_t aStartInChannel,
ErrorResult& aRv)
{
aSource.ComputeLengthAndData();
uint32_t length = aSource.Length();
CheckedInt<uint32_t> end = aStartInChannel;
end += length;
if (aChannelNumber >= NumberOfChannels() ||
!end.isValid() || end.value() > mLength) {
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
return;
}
if (!mSharedChannels && JS_GetTypedArrayLength(mJSChannels[aChannelNumber]) != mLength) {
// The array was probably neutered
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
return;
}
if (!RestoreJSChannelData(aJSContext)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
PodMove(JS_GetFloat32ArrayData(mJSChannels[aChannelNumber]) + aStartInChannel,
aSource.Data(), length);
}
示例8: MakeFromMalloc
static sk_sp<SkData>
MakeSkData(unsigned char* aData, const IntSize& aSize, int32_t aStride)
{
CheckedInt<size_t> size = aStride;
size *= aSize.height;
if (size.isValid()) {
void* mem = sk_malloc_flags(size.value(), 0);
if (mem) {
if (aData) {
memcpy(mem, aData, size.value());
}
return SkData::MakeFromMalloc(mem, size.value());
}
}
return nullptr;
}
示例9: sizeof
void
AllocateAudioBlock(uint32_t aChannelCount, AudioChunk* aChunk)
{
if (aChunk->mBuffer && !aChunk->mBuffer->IsShared() &&
aChunk->ChannelCount() == aChannelCount) {
MOZ_ASSERT(aChunk->mBufferFormat == AUDIO_FORMAT_FLOAT32);
MOZ_ASSERT(aChunk->mDuration == WEBAUDIO_BLOCK_SIZE);
// No need to allocate again.
aChunk->mVolume = 1.0f;
return;
}
CheckedInt<size_t> size = WEBAUDIO_BLOCK_SIZE;
size *= aChannelCount;
size *= sizeof(float);
if (!size.isValid()) {
MOZ_CRASH();
}
// XXX for SIMD purposes we should do something here to make sure the
// channel buffers are 16-byte aligned.
nsRefPtr<SharedBuffer> buffer = SharedBuffer::Create(size.value());
aChunk->mDuration = WEBAUDIO_BLOCK_SIZE;
aChunk->mChannelData.SetLength(aChannelCount);
float* data = static_cast<float*>(buffer->Data());
for (uint32_t i = 0; i < aChannelCount; ++i) {
aChunk->mChannelData[i] = data + i*WEBAUDIO_BLOCK_SIZE;
}
aChunk->mBuffer = buffer.forget();
aChunk->mVolume = 1.0f;
aChunk->mBufferFormat = AUDIO_FORMAT_FLOAT32;
}
示例10: adoptRef
PassRefPtr<DataView> DataView::create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned byteLength)
{
RELEASE_ASSERT(byteOffset <= buffer->byteLength());
CheckedInt<uint32_t> checkedOffset(byteOffset);
CheckedInt<uint32_t> checkedLength(byteLength);
CheckedInt<uint32_t> checkedMax = checkedOffset + checkedLength;
RELEASE_ASSERT(checkedMax.isValid());
RELEASE_ASSERT(checkedMax.value() <= buffer->byteLength());
return adoptRef(new DataView(buffer, byteOffset, byteLength));
}
示例11: Index
void
ChildSHistory::Go(int32_t aOffset, ErrorResult& aRv)
{
CheckedInt<int32_t> index = Index();
index += aOffset;
if (!index.isValid()) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
aRv = mHistory->GotoIndex(index.value());
}
示例12: adoptRef
PassRefPtr<DataView> DataView::create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned byteLength)
{
if (byteOffset > buffer->byteLength())
return 0;
CheckedInt<uint32_t> checkedOffset(byteOffset);
CheckedInt<uint32_t> checkedLength(byteLength);
CheckedInt<uint32_t> checkedMax = checkedOffset + checkedLength;
if (!checkedMax.isValid() || checkedMax.value() > buffer->byteLength())
return 0;
return adoptRef(new DataView(buffer, byteOffset, byteLength));
}
示例13:
HRESULT
FramesToUsecs(int64_t aSamples, uint32_t aRate, int64_t* aOutUsecs)
{
MOZ_ASSERT(aOutUsecs);
CheckedInt<int64_t> i = aSamples;
i *= USECS_PER_S;
i /= aRate;
NS_ENSURE_TRUE(i.isValid(), E_FAIL);
*aOutUsecs = i.value();
return S_OK;
}
示例14: GetOffset
uint32_t
ImageDataSerializerBase::ComputeMinBufferSize(IntSize aSize,
SurfaceFormat aFormat)
{
MOZ_ASSERT(aSize.height >= 0 && aSize.width >= 0);
if (aSize.height <= 0 || aSize.width <= 0) {
gfxDebug() << "Non-positive image buffer size request " << aSize.width << "x" << aSize.height;
return 0;
}
CheckedInt<int32_t> bufsize = ComputeStride(aFormat, aSize.width);
bufsize *= aSize.height;
if (!bufsize.isValid() || bufsize.value() <= 0) {
gfxDebug() << "Buffer size overflow " << aSize.width << "x" << aSize.height;
return 0;
}
return SurfaceBufferInfo::GetOffset()
+ GetAlignedStride<16>(bufsize.value());
}
示例15: mImageSize
Deinterlacer::Deinterlacer(const nsIntSize& aImageSize)
: mImageSize(aImageSize)
{
CheckedInt<size_t> bufferSize = mImageSize.width;
bufferSize *= mImageSize.height;
bufferSize *= sizeof(uint32_t);
if (!bufferSize.isValid()) {
return;
}
mBuffer = MakeUniqueFallible<uint8_t[]>(bufferSize.value());
}