core/layout/layout_string.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * @file layout_string.c | ||
| 3 | * @brief Walking a layout wire string far enough to answer whether it holds anything. | ||
| 4 | * | ||
| 5 | * @ingroup lib_core | ||
| 6 | */ | ||
| 7 | #include "layout_string.h" | ||
| 8 | |||
| 9 | 15 | int layout_parse_int(const char **cursor) | |
| 10 | { | ||
| 11 | 15 | int value = 0; | |
| 12 | 15 | bool too_big = false; | |
| 13 | |||
| 14 | // every digit is walked even once the number is too big, so the cursor still lands on the | ||
| 15 | // next field. stopping the maths at the cap keeps an int from ever overflowing | ||
| 16 |
4/4✓ Branch 0 taken 38 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 3 times.
|
50 | while (**cursor >= '0' && **cursor <= '9') |
| 17 | { | ||
| 18 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 22 times.
|
35 | if (value > LAYOUT_INT_MAX / 10) |
| 19 | { | ||
| 20 | 13 | too_big = true; | |
| 21 | } | ||
| 22 | else | ||
| 23 | { | ||
| 24 | 22 | value = value * 10 + (**cursor - '0'); | |
| 25 |
2/4✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
|
22 | too_big = too_big || value > LAYOUT_INT_MAX; |
| 26 | } | ||
| 27 | 35 | (*cursor)++; | |
| 28 | } | ||
| 29 | |||
| 30 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 13 times.
|
15 | return too_big ? -1 : value; |
| 31 | } | ||
| 32 | |||
| 33 | 9 | bool layout_has_any_block(const char *layout, int type_count) | |
| 34 | { | ||
| 35 |
4/4✓ Branch 0 taken 17 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 6 times.
|
27 | for (const char *p = layout; p && *p; ) |
| 36 | { | ||
| 37 | 11 | int type = layout_parse_int(&p); | |
| 38 |
4/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
|
11 | if (type > 0 && type < type_count) |
| 39 | { | ||
| 40 | 2 | return true; | |
| 41 | } | ||
| 42 | |||
| 43 | // this record is no good, so skip to the start of the next one | ||
| 44 |
4/4✓ Branch 0 taken 39 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 4 times.
|
44 | while (*p && *p != ';') |
| 45 | { | ||
| 46 | 35 | p++; | |
| 47 | } | ||
| 48 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
|
9 | if (*p == ';') |
| 49 | { | ||
| 50 | 4 | p++; | |
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | 7 | return false; | |
| 55 | } | ||
| 56 |