Coverage Report

Created: 2025-11-24 06:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/jansson/src/error.c
Line
Count
Source
1
#include "jansson_private.h"
2
#include <string.h>
3
4
4.81k
void jsonp_error_init(json_error_t *error, const char *source) {
5
4.81k
    if (error) {
6
4.81k
        error->text[0] = '\0';
7
4.81k
        error->line = -1;
8
4.81k
        error->column = -1;
9
4.81k
        error->position = 0;
10
4.81k
        if (source)
11
4.81k
            jsonp_error_set_source(error, source);
12
0
        else
13
0
            error->source[0] = '\0';
14
4.81k
    }
15
4.81k
}
16
17
4.81k
void jsonp_error_set_source(json_error_t *error, const char *source) {
18
4.81k
    size_t length;
19
20
4.81k
    if (!error || !source)
21
0
        return;
22
23
4.81k
    length = strlen(source);
24
4.81k
    if (length < JSON_ERROR_SOURCE_LENGTH)
25
4.81k
        strncpy(error->source, source, length + 1);
26
0
    else {
27
0
        size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4;
28
0
        memcpy(error->source, "...", 3);
29
0
        strncpy(error->source + 3, source + extra, length - extra + 1);
30
0
    }
31
4.81k
}
32
33
void jsonp_error_set(json_error_t *error, int line, int column, size_t position,
34
1.56k
                     enum json_error_code code, const char *msg, ...) {
35
1.56k
    va_list ap;
36
37
1.56k
    va_start(ap, msg);
38
1.56k
    jsonp_error_vset(error, line, column, position, code, msg, ap);
39
1.56k
    va_end(ap);
40
1.56k
}
41
42
void jsonp_error_vset(json_error_t *error, int line, int column, size_t position,
43
1.56k
                      enum json_error_code code, const char *msg, va_list ap) {
44
1.56k
    if (!error)
45
0
        return;
46
47
1.56k
    if (error->text[0] != '\0') {
48
        /* error already set */
49
457
        return;
50
457
    }
51
52
1.10k
    error->line = line;
53
1.10k
    error->column = column;
54
1.10k
    error->position = (int)position;
55
56
1.10k
    vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH - 1, msg, ap);
57
1.10k
    error->text[JSON_ERROR_TEXT_LENGTH - 2] = '\0';
58
1.10k
    error->text[JSON_ERROR_TEXT_LENGTH - 1] = code;
59
1.10k
}