Coverage Report

Created: 2026-06-13 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxml2/include/private/memory.h
Line
Count
Source
1
#ifndef XML_MEMORY_H_PRIVATE__
2
#define XML_MEMORY_H_PRIVATE__
3
4
#include "../../libxml.h"
5
6
#include <limits.h>
7
#include <stddef.h>
8
9
#ifndef SIZE_MAX
10
  #define SIZE_MAX ((size_t) -1)
11
#endif
12
13
442k
#define XML_MAX_ITEMS 1000000000 /* 1 billion */
14
15
XML_HIDDEN void
16
xmlInitMemoryInternal(void);
17
XML_HIDDEN void
18
xmlCleanupMemoryInternal(void);
19
20
/**
21
 * @array:  pointer to array
22
 * @capacity:  pointer to capacity (in/out)
23
 * @elemSize:  size of an element in bytes
24
 * @min:  elements in initial allocation
25
 * @max:  maximum elements in the array
26
 *
27
 * Grow an array by at least one element, checking for overflow.
28
 *
29
 * Returns the new array size on success, -1 on failure.
30
 */
31
static XML_INLINE int
32
233k
xmlGrowCapacity(int capacity, size_t elemSize, int min, int max) {
33
233k
    int extra;
34
35
233k
    if (capacity <= 0) {
36
14.5k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
37
14.5k
        (void) min;
38
14.5k
        return(1);
39
#else
40
        return(min);
41
#endif
42
14.5k
    }
43
44
219k
    if ((capacity >= max) ||
45
218k
        ((size_t) capacity > SIZE_MAX / 2 / elemSize))
46
635
        return(-1);
47
48
    /* Grow by 50% */
49
218k
    extra = (capacity + 1) / 2;
50
51
218k
    if (capacity > max - extra)
52
1.27k
        return(max);
53
54
217k
    return(capacity + extra);
55
218k
}
parser.c:xmlGrowCapacity
Line
Count
Source
32
231k
xmlGrowCapacity(int capacity, size_t elemSize, int min, int max) {
33
231k
    int extra;
34
35
231k
    if (capacity <= 0) {
36
14.5k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
37
14.5k
        (void) min;
38
14.5k
        return(1);
39
#else
40
        return(min);
41
#endif
42
14.5k
    }
43
44
216k
    if ((capacity >= max) ||
45
216k
        ((size_t) capacity > SIZE_MAX / 2 / elemSize))
46
635
        return(-1);
47
48
    /* Grow by 50% */
49
216k
    extra = (capacity + 1) / 2;
50
51
216k
    if (capacity > max - extra)
52
1.27k
        return(max);
53
54
214k
    return(capacity + extra);
55
216k
}
Unexecuted instantiation: parserInternals.c:xmlGrowCapacity
Unexecuted instantiation: threads.c:xmlGrowCapacity
Unexecuted instantiation: tree.c:xmlGrowCapacity
uri.c:xmlGrowCapacity
Line
Count
Source
32
2.53k
xmlGrowCapacity(int capacity, size_t elemSize, int min, int max) {
33
2.53k
    int extra;
34
35
2.53k
    if (capacity <= 0) {
36
0
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
37
0
        (void) min;
38
0
        return(1);
39
#else
40
        return(min);
41
#endif
42
0
    }
43
44
2.53k
    if ((capacity >= max) ||
45
2.53k
        ((size_t) capacity > SIZE_MAX / 2 / elemSize))
46
0
        return(-1);
47
48
    /* Grow by 50% */
49
2.53k
    extra = (capacity + 1) / 2;
50
51
2.53k
    if (capacity > max - extra)
52
7
        return(max);
53
54
2.53k
    return(capacity + extra);
55
2.53k
}
Unexecuted instantiation: valid.c:xmlGrowCapacity
Unexecuted instantiation: xmlmemory.c:xmlGrowCapacity
Unexecuted instantiation: catalog.c:xmlGrowCapacity
Unexecuted instantiation: HTMLparser.c:xmlGrowCapacity
Unexecuted instantiation: xmlregexp.c:xmlGrowCapacity
Unexecuted instantiation: relaxng.c:xmlGrowCapacity
Unexecuted instantiation: xmlschemas.c:xmlGrowCapacity
Unexecuted instantiation: xpath.c:xmlGrowCapacity
Unexecuted instantiation: encoding.c:xmlGrowCapacity
Unexecuted instantiation: pattern.c:xmlGrowCapacity
Unexecuted instantiation: xmlreader.c:xmlGrowCapacity
Unexecuted instantiation: xinclude.c:xmlGrowCapacity
56
57
XML_HIDDEN void *
58
xmlGrowArray(void *array, size_t elemSize, int *capacity, int min, int max);
59
60
#endif /* XML_MEMORY_H_PRIVATE__ */