Coverage Report

Created: 2026-04-28 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxmlb/src/xb-silo-node.h
Line
Count
Source
1
/*
2
 * Copyright 2021 Richard Hughes <richard@hughsie.com>
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 */
6
7
#pragma once
8
9
#include "xb-compile.h"
10
11
4.23M
#define XB_SILO_UNSET 0xffffffff
12
13
typedef enum {
14
  XB_SILO_NODE_FLAG_NONE = 0,
15
  XB_SILO_NODE_FLAG_IS_ELEMENT = 1 << 0,
16
  XB_SILO_NODE_FLAG_IS_TOKENIZED = 1 << 1,
17
} XbSiloNodeFlag;
18
19
typedef struct __attribute__((packed)) {
20
  guint8 flags : 2;
21
  guint8 attr_count : 6;
22
  guint8 token_count;   /* ONLY when is_element */
23
  guint32 element_name; /* ONLY when is_element: from strtab */
24
  guint32 parent;       /* ONLY when is_element: from 0 */
25
  guint32 next;       /* ONLY when is_element: from 0 */
26
  guint32 text;       /* ONLY when is_element: from strtab */
27
  guint32 tail;       /* ONLY when is_element: from strtab */
28
            /*
29
            guint32   attrs[attr_count];
30
            guint32   tokens[token_count];
31
            */
32
} XbSiloNode;
33
34
typedef struct __attribute__((packed)) {
35
  guint32 attr_name;  /* from strtab */
36
  guint32 attr_value; /* from strtab */
37
} XbSiloNodeAttr;
38
39
gchar *
40
xb_silo_node_to_string(const XbSiloNode *self) G_GNUC_NON_NULL(1);
41
42
/* private */
43
static inline gboolean
44
xb_silo_node_has_flag(const XbSiloNode *self, XbSiloNodeFlag flag)
45
0
{
46
0
  return (self->flags & flag) > 0;
47
0
}
Unexecuted instantiation: xb-builder.c:xb_silo_node_has_flag
Unexecuted instantiation: xb-builder-node.c:xb_silo_node_has_flag
Unexecuted instantiation: xb-node.c:xb_silo_node_has_flag
Unexecuted instantiation: xb-node-query.c:xb_silo_node_has_flag
Unexecuted instantiation: xb-query.c:xb_silo_node_has_flag
Unexecuted instantiation: xb-silo.c:xb_silo_node_has_flag
Unexecuted instantiation: xb-silo-export.c:xb_silo_node_has_flag
Unexecuted instantiation: xb-silo-query.c:xb_silo_node_has_flag
Unexecuted instantiation: xb-value-bindings.c:xb_silo_node_has_flag
Unexecuted instantiation: xb-machine.c:xb_silo_node_has_flag
48
49
static inline guint32
50
xb_silo_node_get_size(const XbSiloNode *self)
51
0
{
52
0
  if (xb_silo_node_has_flag(self, XB_SILO_NODE_FLAG_IS_ELEMENT)) {
53
0
    guint8 sz = sizeof(XbSiloNode);
54
0
    sz += self->attr_count * sizeof(XbSiloNodeAttr);
55
0
    sz += self->token_count * sizeof(guint32);
56
0
    return sz;
57
0
  }
58
59
  /* sentinel */
60
0
  return sizeof(guint8);
61
0
}
Unexecuted instantiation: xb-builder.c:xb_silo_node_get_size
Unexecuted instantiation: xb-builder-node.c:xb_silo_node_get_size
Unexecuted instantiation: xb-node.c:xb_silo_node_get_size
Unexecuted instantiation: xb-node-query.c:xb_silo_node_get_size
Unexecuted instantiation: xb-query.c:xb_silo_node_get_size
Unexecuted instantiation: xb-silo.c:xb_silo_node_get_size
Unexecuted instantiation: xb-silo-export.c:xb_silo_node_get_size
Unexecuted instantiation: xb-silo-query.c:xb_silo_node_get_size
Unexecuted instantiation: xb-value-bindings.c:xb_silo_node_get_size
Unexecuted instantiation: xb-machine.c:xb_silo_node_get_size
62
63
/* private */
64
static inline guint8
65
xb_silo_node_get_flags(const XbSiloNode *self)
66
0
{
67
0
  return self->flags;
68
0
}
Unexecuted instantiation: xb-builder.c:xb_silo_node_get_flags
Unexecuted instantiation: xb-builder-node.c:xb_silo_node_get_flags
Unexecuted instantiation: xb-node.c:xb_silo_node_get_flags
Unexecuted instantiation: xb-node-query.c:xb_silo_node_get_flags
Unexecuted instantiation: xb-query.c:xb_silo_node_get_flags
Unexecuted instantiation: xb-silo.c:xb_silo_node_get_flags
Unexecuted instantiation: xb-silo-export.c:xb_silo_node_get_flags
Unexecuted instantiation: xb-silo-query.c:xb_silo_node_get_flags
Unexecuted instantiation: xb-value-bindings.c:xb_silo_node_get_flags
Unexecuted instantiation: xb-machine.c:xb_silo_node_get_flags
69
70
/* private */
71
static inline guint32
72
xb_silo_node_get_text_idx(const XbSiloNode *self)
73
0
{
74
0
  return self->text;
75
0
}
Unexecuted instantiation: xb-builder.c:xb_silo_node_get_text_idx
Unexecuted instantiation: xb-builder-node.c:xb_silo_node_get_text_idx
Unexecuted instantiation: xb-node.c:xb_silo_node_get_text_idx
Unexecuted instantiation: xb-node-query.c:xb_silo_node_get_text_idx
Unexecuted instantiation: xb-query.c:xb_silo_node_get_text_idx
Unexecuted instantiation: xb-silo.c:xb_silo_node_get_text_idx
Unexecuted instantiation: xb-silo-export.c:xb_silo_node_get_text_idx
Unexecuted instantiation: xb-silo-query.c:xb_silo_node_get_text_idx
Unexecuted instantiation: xb-value-bindings.c:xb_silo_node_get_text_idx
Unexecuted instantiation: xb-machine.c:xb_silo_node_get_text_idx
76
77
/* private */
78
static inline guint32
79
xb_silo_node_get_tail_idx(const XbSiloNode *self)
80
0
{
81
0
  return self->tail;
82
0
}
Unexecuted instantiation: xb-builder.c:xb_silo_node_get_tail_idx
Unexecuted instantiation: xb-builder-node.c:xb_silo_node_get_tail_idx
Unexecuted instantiation: xb-node.c:xb_silo_node_get_tail_idx
Unexecuted instantiation: xb-node-query.c:xb_silo_node_get_tail_idx
Unexecuted instantiation: xb-query.c:xb_silo_node_get_tail_idx
Unexecuted instantiation: xb-silo.c:xb_silo_node_get_tail_idx
Unexecuted instantiation: xb-silo-export.c:xb_silo_node_get_tail_idx
Unexecuted instantiation: xb-silo-query.c:xb_silo_node_get_tail_idx
Unexecuted instantiation: xb-value-bindings.c:xb_silo_node_get_tail_idx
Unexecuted instantiation: xb-machine.c:xb_silo_node_get_tail_idx
83
84
/* private */
85
static inline guint8
86
xb_silo_node_get_attr_count(const XbSiloNode *self)
87
0
{
88
0
  return self->attr_count;
89
0
}
Unexecuted instantiation: xb-builder.c:xb_silo_node_get_attr_count
Unexecuted instantiation: xb-builder-node.c:xb_silo_node_get_attr_count
Unexecuted instantiation: xb-node.c:xb_silo_node_get_attr_count
Unexecuted instantiation: xb-node-query.c:xb_silo_node_get_attr_count
Unexecuted instantiation: xb-query.c:xb_silo_node_get_attr_count
Unexecuted instantiation: xb-silo.c:xb_silo_node_get_attr_count
Unexecuted instantiation: xb-silo-export.c:xb_silo_node_get_attr_count
Unexecuted instantiation: xb-silo-query.c:xb_silo_node_get_attr_count
Unexecuted instantiation: xb-value-bindings.c:xb_silo_node_get_attr_count
Unexecuted instantiation: xb-machine.c:xb_silo_node_get_attr_count
90
91
/* private */
92
static inline XbSiloNodeAttr *
93
xb_silo_node_get_attr(const XbSiloNode *self, guint8 idx)
94
0
{
95
0
  guint32 off = sizeof(XbSiloNode);
96
97
  /* bounds check to prevent out-of-bounds read */
98
0
  if (G_UNLIKELY(idx >= self->attr_count))
99
0
    return NULL;
100
101
0
  off += sizeof(XbSiloNodeAttr) * idx;
102
0
  return (XbSiloNodeAttr *)(((guint8 *)self) + off);
103
0
}
Unexecuted instantiation: xb-builder.c:xb_silo_node_get_attr
Unexecuted instantiation: xb-builder-node.c:xb_silo_node_get_attr
Unexecuted instantiation: xb-node.c:xb_silo_node_get_attr
Unexecuted instantiation: xb-node-query.c:xb_silo_node_get_attr
Unexecuted instantiation: xb-query.c:xb_silo_node_get_attr
Unexecuted instantiation: xb-silo.c:xb_silo_node_get_attr
Unexecuted instantiation: xb-silo-export.c:xb_silo_node_get_attr
Unexecuted instantiation: xb-silo-query.c:xb_silo_node_get_attr
Unexecuted instantiation: xb-value-bindings.c:xb_silo_node_get_attr
Unexecuted instantiation: xb-machine.c:xb_silo_node_get_attr
104
105
/* private */
106
static inline guint8
107
xb_silo_node_get_token_count(const XbSiloNode *self)
108
0
{
109
0
  return self->token_count;
110
0
}
Unexecuted instantiation: xb-builder.c:xb_silo_node_get_token_count
Unexecuted instantiation: xb-builder-node.c:xb_silo_node_get_token_count
Unexecuted instantiation: xb-node.c:xb_silo_node_get_token_count
Unexecuted instantiation: xb-node-query.c:xb_silo_node_get_token_count
Unexecuted instantiation: xb-query.c:xb_silo_node_get_token_count
Unexecuted instantiation: xb-silo.c:xb_silo_node_get_token_count
Unexecuted instantiation: xb-silo-export.c:xb_silo_node_get_token_count
Unexecuted instantiation: xb-silo-query.c:xb_silo_node_get_token_count
Unexecuted instantiation: xb-value-bindings.c:xb_silo_node_get_token_count
Unexecuted instantiation: xb-machine.c:xb_silo_node_get_token_count
111
112
/* private */
113
static inline guint32
114
xb_silo_node_get_token_idx(const XbSiloNode *self, guint idx)
115
0
{
116
0
  guint32 off = 0;
117
0
  guint32 stridx;
118
119
  /* not valid */
120
0
  if (!xb_silo_node_has_flag(self, XB_SILO_NODE_FLAG_IS_ELEMENT))
121
0
    return XB_SILO_UNSET;
122
0
  if (!xb_silo_node_has_flag(self, XB_SILO_NODE_FLAG_IS_TOKENIZED))
123
0
    return XB_SILO_UNSET;
124
125
  /* bounds check */
126
0
  if (G_UNLIKELY(idx >= self->token_count))
127
0
    return XB_SILO_UNSET;
128
129
  /* calculate offset to token */
130
0
  off += sizeof(XbSiloNode);
131
0
  off += self->attr_count * sizeof(XbSiloNodeAttr);
132
0
  off += idx * sizeof(guint32);
133
0
  memcpy(&stridx, (guint8 *)self + off, sizeof(stridx));
134
0
  return stridx;
135
0
}
Unexecuted instantiation: xb-builder.c:xb_silo_node_get_token_idx
Unexecuted instantiation: xb-builder-node.c:xb_silo_node_get_token_idx
Unexecuted instantiation: xb-node.c:xb_silo_node_get_token_idx
Unexecuted instantiation: xb-node-query.c:xb_silo_node_get_token_idx
Unexecuted instantiation: xb-query.c:xb_silo_node_get_token_idx
Unexecuted instantiation: xb-silo.c:xb_silo_node_get_token_idx
Unexecuted instantiation: xb-silo-export.c:xb_silo_node_get_token_idx
Unexecuted instantiation: xb-silo-query.c:xb_silo_node_get_token_idx
Unexecuted instantiation: xb-value-bindings.c:xb_silo_node_get_token_idx
Unexecuted instantiation: xb-machine.c:xb_silo_node_get_token_idx