当前位置: 首页>>代码示例>>C++>>正文


C++ CheckedInt类代码示例

本文整理汇总了C++中CheckedInt的典型用法代码示例。如果您正苦于以下问题:C++ CheckedInt类的具体用法?C++ CheckedInt怎么用?C++ CheckedInt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CheckedInt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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);
}
开发者ID:afabbro,项目名称:gecko-dev,代码行数:30,代码来源:AudioBuffer.cpp

示例2:

size_t
LZ4::compress(const char* aSource, size_t aInputSize, char* aDest)
{
  CheckedInt<int> inputSizeChecked = aInputSize;
  MOZ_ASSERT(inputSizeChecked.isValid());
  return LZ4_compress(aSource, aDest, inputSizeChecked.value());
}
开发者ID:afabbro,项目名称:gecko-dev,代码行数:7,代码来源:Compression.cpp

示例3: checkedBufferOffset

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;
    }
}
开发者ID:1833183060,项目名称:wke,代码行数:32,代码来源:WebGLBuffer.cpp

示例4: 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;
}
开发者ID:marcoscaceres,项目名称:gecko-dev,代码行数:33,代码来源:mozHunspell.cpp

示例5: AllocateAudioBlock

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;
}
开发者ID:volkanh,项目名称:gecko-dev,代码行数:31,代码来源:AudioNodeEngine.cpp

示例6: RELEASE_ASSERT

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));
}
开发者ID:kingysu,项目名称:blink-crosswalk,代码行数:10,代码来源:DataView.cpp

示例7: 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());
}
开发者ID:marcoscaceres,项目名称:gecko-dev,代码行数:11,代码来源:ChildSHistory.cpp

示例8: checkedOffset

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));
}
开发者ID:166MMX,项目名称:openjdk.java.net-openjfx-8u40-rt,代码行数:11,代码来源:DataView.cpp

示例9: FramesToUsecs

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;
}
开发者ID:ShakoHo,项目名称:gecko-dev,代码行数:11,代码来源:WMFUtils.cpp

示例10: ComputeRGBStride

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());
}
开发者ID:cclauss,项目名称:gecko-dev,代码行数:12,代码来源:ImageDataSerializer.cpp

示例11: HNsToFrames

HRESULT
HNsToFrames(int64_t aHNs, uint32_t aRate, int64_t* aOutFrames)
{
  MOZ_ASSERT(aOutFrames);
  const int64_t HNS_PER_S = USECS_PER_S * 10;
  CheckedInt<int64_t> i = aHNs;
  i *= aRate;
  i /= HNS_PER_S;
  NS_ENSURE_TRUE(i.isValid(), E_FAIL);
  *aOutFrames = i.value();
  return S_OK;
}
开发者ID:ShakoHo,项目名称:gecko-dev,代码行数:12,代码来源:WMFUtils.cpp

示例12: MOZ_ASSERT

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);
  }
}
开发者ID:luke-chang,项目名称:gecko-1,代码行数:52,代码来源:RequestContextService.cpp

示例13: 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());
}
开发者ID:Nazi-Nigger,项目名称:gecko-dev,代码行数:13,代码来源:Deinterlacer.cpp

示例14: UpdateLastUseIndex

void WebGLContext::UpdateLastUseIndex()
{
    static CheckedInt<uint64_t> sIndex = 0;

    sIndex++;

    // should never happen with 64-bit; trying to handle this would be riskier than
    // not handling it as the handler code would never get exercised.
    if (!sIndex.isValid()) {
        NS_RUNTIMEABORT("Can't believe it's been 2^64 transactions already!");
    }

    mLastUseIndex = sIndex.value();
}
开发者ID:Sleepwalker2014,项目名称:gecko-dev,代码行数:14,代码来源:WebGLContext.cpp

示例15: Create

 static already_AddRefed<AudioBlockBuffer> Create(uint32_t aChannelCount)
 {
   CheckedInt<size_t> size = WEBAUDIO_BLOCK_SIZE;
   size *= aChannelCount;
   size *= sizeof(float);
   size += sizeof(AudioBlockBuffer);
   if (!size.isValid()) {
     MOZ_CRASH();
   }
   void* m = moz_xmalloc(size.value());
   nsRefPtr<AudioBlockBuffer> p = new (m) AudioBlockBuffer();
   NS_ASSERTION((reinterpret_cast<char*>(p.get() + 1) - reinterpret_cast<char*>(p.get())) % 4 == 0,
                "AudioBlockBuffers should be at least 4-byte aligned");
   return p.forget();
 }
开发者ID:stephen-wilcox,项目名称:gecko-dev,代码行数:15,代码来源:AudioBlock.cpp


注:本文中的CheckedInt类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。