Coverage Report

Created: 2026-08-31 07:13

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
33.0k
void jsonp_error_init(json_error_t *error, const char *source) {
5
33.0k
    if (error) {
6
29.3k
        error->text[0] = '\0';
7
29.3k
        error->line = -1;
8
29.3k
        error->column = -1;
9
29.3k
        error->position = 0;
10
29.3k
        if (source)
11
29.3k
            jsonp_error_set_source(error, source);
12
0
        else
13
0
            error->source[0] = '\0';
14
29.3k
    }
15
33.0k
}
16
17
29.3k
void jsonp_error_set_source(json_error_t *error, const char *source) {
18
29.3k
    size_t length;
19
20
29.3k
    if (!error || !source)
21
0
        return;
22
23
29.3k
    length = strlen(source);
24
29.3k
    if (length < JSON_ERROR_SOURCE_LENGTH)
25
29.3k
        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
29.3k
}
32
33
void jsonp_error_set(json_error_t *error, int line, int column, size_t position,
34
1.90k
                     enum json_error_code code, const char *msg, ...) {
35
1.90k
    va_list ap;
36
37
1.90k
    va_start(ap, msg);
38
1.90k
    jsonp_error_vset(error, line, column, position, code, msg, ap);
39
1.90k
    va_end(ap);
40
1.90k
}
41
42
void jsonp_error_vset(json_error_t *error, int line, int column, size_t position,
43
1.90k
                      enum json_error_code code, const char *msg, va_list ap) {
44
1.90k
    if (!error)
45
0
        return;
46
47
1.90k
    if (error->text[0] != '\0') {
48
        /* error already set */
49
522
        return;
50
522
    }
51
52
1.37k
    error->line = line;
53
1.37k
    error->column = column;
54
1.37k
    error->position = (int)position;
55
56
1.37k
    vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH - 1, msg, ap);
57
1.37k
    error->text[JSON_ERROR_TEXT_LENGTH - 2] = '\0';
58
1.37k
    error->text[JSON_ERROR_TEXT_LENGTH - 1] = code;
59
1.37k
}