• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ArkScript-lang / Ark / 16470715875

23 Jul 2025 12:31PM UTC coverage: 86.694% (-0.02%) from 86.717%
16470715875

Pull #559

github

web-flow
Merge 36aea3591 into 66d9c291c
Pull Request #559: Fix potential out of bounds scope allocation

8 of 11 new or added lines in 2 files covered. (72.73%)

7343 of 8470 relevant lines covered (86.69%)

116295.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.14
/src/arkreactor/VM/ScopeView.cpp
1
#include <Ark/VM/ScopeView.hpp>
2

3
#include <limits>
4

5
namespace Ark::internal
6
{
7
    ScopeView::ScopeView(pair_t* storage, const std::size_t start) noexcept :
141,001✔
8
        m_storage(storage), m_start(start), m_size(0), m_min_id(std::numeric_limits<uint16_t>::max()), m_max_id(0)
141,001✔
9
    {}
282,002✔
10

11
    bool ScopeView::push_back(uint16_t id, Value&& val) noexcept
28,998✔
12
    {
28,998✔
13
        if (m_start + m_size >= ScopeStackSize) [[unlikely]]
28,998✔
NEW
14
            return false;
×
15

16
        if (id < m_min_id)
28,998✔
17
            m_min_id = id;
5,255✔
18
        if (id > m_max_id)
28,998✔
19
            m_max_id = id;
22,569✔
20

21
        m_storage[m_start + m_size] = std::make_pair(id, std::move(val));
28,998✔
22
        ++m_size;
28,998✔
23
        return true;
28,998✔
24
    }
28,998✔
25

26
    bool ScopeView::push_back(uint16_t id, const Value& val) noexcept
236,495✔
27
    {
236,495✔
28
        if (m_start + m_size >= ScopeStackSize) [[unlikely]]
236,495✔
NEW
29
            return false;
×
30

31
        if (id < m_min_id)
236,495✔
32
            m_min_id = id;
133,451✔
33
        if (id > m_max_id)
236,495✔
34
            m_max_id = id;
219,517✔
35

36
        m_storage[m_start + m_size] = std::make_pair(id, val);
236,495✔
37
        ++m_size;
236,495✔
38
        return true;
236,495✔
39
    }
236,495✔
40

41
    bool ScopeView::maybeHas(const uint16_t id) const noexcept
1,097,327✔
42
    {
1,097,327✔
43
        return m_min_id <= id && id <= m_max_id;
1,097,327✔
44
    }
45

46
    Value* ScopeView::operator[](const uint16_t id_to_look_for) noexcept
1,097,334✔
47
    {
1,097,334✔
48
        if (!maybeHas(id_to_look_for))
1,097,334✔
49
            return nullptr;
600,183✔
50

51
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
2,936,605✔
52
        {
53
            auto& [id, value] = m_storage[i];
2,439,454✔
54
            if (id == id_to_look_for)
2,439,454✔
55
                return &value;
474,287✔
56
        }
2,439,454✔
57
        return nullptr;
22,862✔
58
    }
1,097,334✔
59

60
    const Value* ScopeView::operator[](const uint16_t id_to_look_for) const noexcept
×
61
    {
×
62
        if (!maybeHas(id_to_look_for))
×
63
            return nullptr;
×
64

65
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
×
66
        {
67
            auto& [id, value] = m_storage[i];
×
68
            if (id == id_to_look_for)
×
69
                return &value;
×
70
        }
×
71
        return nullptr;
×
72
    }
×
73

74
    uint16_t ScopeView::idFromValue(const Value& val) const noexcept
2,096,128✔
75
    {
2,096,128✔
76
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
4,192,256✔
77
        {
78
            const auto& [id, value] = m_storage[i];
2,098,175✔
79
            if (value == val)
2,096,128✔
80
                return id;
2,047✔
81
        }
2,096,128✔
82
        return std::numeric_limits<uint16_t>::max();
2,094,081✔
83
    }
2,096,128✔
84

85
    void ScopeView::reset() noexcept
31,056✔
86
    {
31,056✔
87
        m_size = 0;
31,056✔
88
        m_min_id = std::numeric_limits<uint16_t>::max();
31,056✔
89
        m_max_id = 0;
31,056✔
90
    }
31,056✔
91

92
    bool operator==(const ScopeView& A, const ScopeView& B) noexcept
×
93
    {
×
94
        // if we have two scopes with the same number of elements and starting at the same position,
95
        // they must be identical, as we have a single storage for all scopes
96
        return A.m_size == B.m_size && A.m_start == B.m_start;
×
97
    }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc