brute force linear search */
| 73 | |
| 74 | /* brute force linear search */ |
| 75 | static long int fmap_lsearch(const uint8_t *image, size_t len) |
| 76 | { |
| 77 | unsigned long offset; |
| 78 | int fmap_found = 0; |
| 79 | |
| 80 | for (offset = 0; offset < len - strlen(FMAP_SIGNATURE); offset++) { |
| 81 | if (is_valid_fmap((const struct fmap *)&image[offset])) { |
| 82 | fmap_found = 1; |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | if (!fmap_found) |
| 88 | return -1; |
| 89 | |
| 90 | if (offset + fmap_size((const struct fmap *)&image[offset]) > len) |
| 91 | return -1; |
| 92 | |
| 93 | return offset; |
| 94 | } |
| 95 | |
| 96 | /* if image length is a power of 2, use binary search */ |
| 97 | static long fmap_bsearch(const uint8_t *image, size_t len) |
no test coverage detected