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

bblanchon / ArduinoJson / 13566673611

27 Feb 2025 12:42PM CUT coverage: 99.33% (+0.001%) from 99.329%
13566673611

push

github

bblanchon
Fix overflowed()

2 of 2 new or added lines in 1 file covered. (100.0%)

3 existing lines in 1 file now uncovered.

4005 of 4032 relevant lines covered (99.33%)

10853.67 hits per line

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

97.67
/src/ArduinoJson/Array/ArrayImpl.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2025, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

7
#include <ArduinoJson/Array/ArrayData.hpp>
8
#include <ArduinoJson/Variant/VariantCompare.hpp>
9
#include <ArduinoJson/Variant/VariantData.hpp>
10

11
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
12

13
inline ArrayData::iterator ArrayData::at(
469✔
14
    size_t index, const ResourceManager* resources) const {
15
  auto it = createIterator(resources);
469✔
16
  while (!it.done() && index) {
791✔
17
    it.next(resources);
322✔
18
    --index;
322✔
19
  }
20
  return it;
469✔
21
}
22

23
inline VariantData* ArrayData::addElement(ResourceManager* resources) {
3,024✔
24
  auto slot = resources->allocVariant();
3,024✔
25
  if (!slot)
3,024✔
26
    return nullptr;
11✔
27
  CollectionData::appendOne(slot, resources);
3,013✔
28
  return slot.ptr();
3,013✔
29
}
30

31
inline VariantData* ArrayData::getOrAddElement(size_t index,
151✔
32
                                               ResourceManager* resources) {
33
  auto it = createIterator(resources);
151✔
34
  while (!it.done() && index > 0) {
176✔
35
    it.next(resources);
25✔
36
    index--;
25✔
37
  }
38
  if (it.done())
151✔
39
    index++;
114✔
40
  VariantData* element = it.data();
151✔
41
  while (index > 0) {
530✔
42
    element = addElement(resources);
379✔
43
    if (!element)
379✔
44
      return nullptr;
×
45
    index--;
379✔
46
  }
47
  return element;
151✔
48
}
49

50
inline VariantData* ArrayData::getElement(
455✔
51
    size_t index, const ResourceManager* resources) const {
52
  return at(index, resources).data();
455✔
53
}
54

55
inline void ArrayData::removeElement(size_t index, ResourceManager* resources) {
14✔
56
  remove(at(index, resources), resources);
14✔
57
}
14✔
58

59
template <typename T>
60
inline bool ArrayData::addValue(const T& value, ResourceManager* resources) {
66,678✔
61
  ARDUINOJSON_ASSERT(resources != nullptr);
62
  auto slot = resources->allocVariant();
66,678✔
63
  if (!slot)
66,678✔
64
    return false;
7✔
65
  JsonVariant variant(slot.ptr(), resources);
66,671✔
66
  if (!variant.set(value)) {
66,671✔
67
    resources->freeVariant(slot);
4✔
68
    return false;
4✔
69
  }
70
  CollectionData::appendOne(slot, resources);
66,667✔
71
  return true;
66,667✔
72
}
73

74
// Returns the size (in bytes) of an array with n elements.
75
constexpr size_t sizeofArray(size_t n) {
84✔
76
  return n * ResourceManager::slotSize;
84✔
77
}
78

79
ARDUINOJSON_END_PRIVATE_NAMESPACE
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