Coverage Report

Created: 2026-11-10 14:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
src/memchr.c
Line
Count
Source
1
#include "prism/internal/memchr.h"
2
3
#include <stdbool.h>
4
#include <stdint.h>
5
#include <string.h>
6
7
299
#define TRAILING_BYTE_MINIMUM 0x40
8
9
/**
10
 * We need to roll our own memchr to handle cases where the encoding changes and
11
 * we need to search for a character in a buffer that could be the trailing byte
12
 * of a multibyte character.
13
 */
14
const void *
15
5.00k
pm_memchr(const void *memory, int character, size_t number, bool encoding_changed, const pm_encoding_t *encoding) {
16
5.00k
    if (encoding_changed && 
encoding->multibyte879
&&
character >= 299
TRAILING_BYTE_MINIMUM299
) {
  Branch (16:9): [True: 879, False: 4.13k]
  Branch (16:29): [True: 299, False: 580]
  Branch (16:52): [True: 0, False: 299]
17
0
        const uint8_t *source = (const uint8_t *) memory;
18
0
        size_t index = 0;
19
20
0
        while (index < number) {
  Branch (20:16): [True: 0, False: 0]
21
0
            if (source[index] == character) {
  Branch (21:17): [True: 0, False: 0]
22
0
                return (void *) (source + index);
23
0
            }
24
25
0
            size_t width = encoding->char_width(source + index, (ptrdiff_t) (number - index));
26
0
            if (width == 0) {
  Branch (26:17): [True: 0, False: 0]
27
0
                return NULL;
28
0
            }
29
30
0
            index += width;
31
0
        }
32
33
0
        return NULL;
34
5.00k
    } else {
35
5.00k
        return memchr(memory, character, number);
36
5.00k
    }
37
5.00k
}