예제 #1
0
파일: angletypes.cpp 프로젝트: null77/angle
GLsizeiptr GetBoundBufferAvailableSize(const OffsetBindingPointer<Buffer> &binding)
{
    Buffer *buffer = binding.get();
    if (buffer)
    {
        if (binding.getSize() == 0)
            return static_cast<GLsizeiptr>(buffer->getSize());
        angle::CheckedNumeric<GLintptr> offset       = binding.getOffset();
        angle::CheckedNumeric<GLsizeiptr> size       = binding.getSize();
        angle::CheckedNumeric<GLsizeiptr> bufferSize = buffer->getSize();
        auto end                                     = offset + size;
        auto clampedSize                             = size;
        auto difference                              = end - bufferSize;
        if (!difference.IsValid())
        {
            return 0;
        }
        if (difference.ValueOrDie() > 0)
        {
            clampedSize = size - difference;
        }
        return clampedSize.ValueOrDefault(0);
    }
    else
    {
        return 0;
    }
}
예제 #2
0
T CheckedMul(base::CheckedNumeric<T> lhs,
             base::CheckedNumeric<T> rhs,
             TDiagnostics *diag,
             const TSourceLoc &line)
{
    ASSERT(lhs.IsValid() && rhs.IsValid());
    auto result = lhs * rhs;
    if (!result.IsValid())
    {
        diag->error(line, "Multiplication out of range", "*", "");
        return 0;
    }
    return result.ValueOrDefault(0);
}