GCC Code Coverage Report


Directory: ./
File: firmware/libfirmware/util/src/fragments.cpp
Date: 2025-10-03 00:57:22
Warnings: 2 unchecked decisions!
Coverage Exec Excl Total
Lines: 100.0% 32 0 32
Functions: 100.0% 2 0 2
Branches: 100.0% 18 0 18
Decisions: 71.4% 10 - 14

Line Branch Decision Exec Source
1 /*
2 * FragmentEntry.cpp
3 *
4 * Created on: Jan 5, 2022
5 * @author Andrey Belomutskiy, (c) 2012-2022
6 */
7
8 #include <rusefi/fragments.h>
9
10 #include <rusefi/rusefi_math.h>
11 #include <cstring>
12
13 7 size_t copyRange(uint8_t* destination, FragmentList src, size_t skip, size_t size) {
14 7 size_t fragmentIndex = 0;
15
16 // Find which fragment to start - skip any full fragments smaller than `skip` parameter
17
4/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 6 times.
0/1
? Decision couldn't be analyzed.
18 while (fragmentIndex < src.count && skip >= src.fragments[fragmentIndex].size) {
18 11 skip -= src.fragments[fragmentIndex].size;
19 11 fragmentIndex++;
20 }
21
22 7 size_t destinationIndex = 0;
23
24
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 5 times.
2/2
✓ Decision 'true' taken 14 times.
✓ Decision 'false' taken 5 times.
19 while (size > 0) {
25
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12 times.
2/2
✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 12 times.
14 if (fragmentIndex >= src.count) {
26 // somehow we are past the end of fragments - fill with zeros
27 2 memset(destination + destinationIndex, 0, size);
28 2 return destinationIndex;
29 }
30
31 12 int copyNowSize = minI(size, src.fragments[fragmentIndex].size - skip);
32 12 const uint8_t* fromBase = src.fragments[fragmentIndex].get();
33
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9 times.
2/2
✓ Decision 'true' taken 3 times.
✓ Decision 'false' taken 9 times.
12 if (!fromBase) {
34 // we have no buffer for this fragment - fill with zeroes
35 3 memset(destination + destinationIndex, 0, copyNowSize);
36 } else {
37 9 memcpy(destination + destinationIndex, fromBase + skip, copyNowSize);
38 }
39 12 destinationIndex += copyNowSize;
40 12 skip = 0;
41 12 size -= copyNowSize;
42 12 fragmentIndex++;
43 }
44 5 return destinationIndex;
45 }
46
47 14 size_t getRangePtr(uint8_t **ptr, FragmentList src, size_t offset, size_t size)
48 {
49 14 size_t fragmentIndex = 0;
50
51 // Find which fragment to start - skip any full fragments smaller than `skip` parameter
52
4/4
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 27 times.
✓ Branch 3 taken 12 times.
0/1
? Decision couldn't be analyzed.
41 while (fragmentIndex < src.count && offset >= src.fragments[fragmentIndex].size) {
53 27 offset -= src.fragments[fragmentIndex].size;
54 27 fragmentIndex++;
55 }
56
57
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12 times.
2/2
✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 12 times.
14 if (fragmentIndex >= src.count) {
58 // out of range
59 2 *ptr = NULL;
60 2 return size;
61 }
62
63
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 3 times.
2/2
✓ Decision 'true' taken 9 times.
✓ Decision 'false' taken 3 times.
12 if (src.fragments[fragmentIndex].get() != NULL)
64 9 *ptr = (uint8_t *)src.fragments[fragmentIndex].get() + offset;
65 else
66 3 *ptr = NULL;
67 12 return minI(size, src.fragments[fragmentIndex].size - offset);
68 }
69