Coverage Report

Created: 2026-01-17 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openvswitch/include/openvswitch/dynamic-string.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016 Nicira, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at:
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef OPENVSWITCH_DYNAMIC_STRING_H
18
#define OPENVSWITCH_DYNAMIC_STRING_H 1
19
20
#include <stdarg.h>
21
#include <stdbool.h>
22
#include <stddef.h>
23
#include <stdint.h>
24
#include <stdio.h>
25
#include "openvswitch/compiler.h"
26
27
#ifdef __cplusplus
28
extern "C" {
29
#endif
30
31
struct uuid;
32
33
/* A "dynamic string", that is, a buffer that can be used to construct a
34
 * string across a series of operations that extend or modify it.
35
 *
36
 * The 'string' member does not always point to a null-terminated string.
37
 * Initially it is NULL, and even when it is nonnull, some operations do not
38
 * ensure that it is null-terminated.  Use ds_cstr() to ensure that memory is
39
 * allocated for the string and that it is null-terminated. */
40
struct ds {
41
    char *string;       /* Null-terminated string. */
42
    size_t length;      /* Bytes used, not including null terminator. */
43
    size_t allocated;   /* Bytes allocated, not including null terminator. */
44
};
45
46
3.72M
#define DS_EMPTY_INITIALIZER { NULL, 0, 0 }
47
48
void ds_init(struct ds *);
49
void ds_clear(struct ds *);
50
void ds_truncate(struct ds *, size_t new_length);
51
void ds_reserve(struct ds *, size_t min_length);
52
char *ds_put_uninit(struct ds *, size_t n);
53
static inline void ds_put_char(struct ds *, char);
54
void ds_put_utf8(struct ds *, int uc);
55
void ds_put_char_multiple(struct ds *, char, size_t n);
56
void ds_put_buffer(struct ds *, const char *, size_t n);
57
void ds_put_cstr(struct ds *, const char *);
58
void ds_put_and_free_cstr(struct ds *, char *);
59
void ds_put_format(struct ds *, const char *, ...) OVS_PRINTF_FORMAT(2, 3);
60
void ds_put_format_valist(struct ds *, const char *, va_list)
61
    OVS_PRINTF_FORMAT(2, 0);
62
void ds_put_printable(struct ds *, const char *, size_t);
63
void ds_put_uuid(struct ds *, const struct uuid *);
64
void ds_put_hex(struct ds *ds, const void *buf, size_t size);
65
void ds_put_hex_with_delimiter(struct ds *, const void *, size_t, char *);
66
void ds_put_hex_dump(struct ds *ds, const void *buf_, size_t size,
67
                     uintptr_t ofs, bool ascii);
68
void ds_put_sparse_hex_dump(struct ds *ds, const void *buf_, size_t size,
69
                            uintptr_t ofs, bool ascii);
70
int ds_get_line(struct ds *, FILE *);
71
int ds_get_preprocessed_line(struct ds *, FILE *, int *line_number);
72
int ds_get_test_line(struct ds *, FILE *);
73
74
void ds_put_strftime_msec(struct ds *, const char *format, long long int when,
75
                          bool utc);
76
char *xastrftime_msec(const char *format, long long int when, bool utc);
77
78
char *ds_cstr(struct ds *);
79
const char *ds_cstr_ro(const struct ds *);
80
char *ds_steal_cstr(struct ds *);
81
void ds_destroy(struct ds *);
82
void ds_swap(struct ds *, struct ds *);
83
84
int ds_last(const struct ds *);
85
bool ds_chomp(struct ds *, int c);
86
void ds_clone(struct ds *, struct ds *);
87

88
/* Inline functions. */
89
90
void ds_put_char__(struct ds *, char);
91
92
static inline void
93
ds_put_char(struct ds *ds, char c)
94
193M
{
95
193M
    if (ds->length < ds->allocated) {
96
192M
        ds->string[ds->length++] = c;
97
192M
        ds->string[ds->length] = '\0';
98
192M
    } else {
99
713k
        ds_put_char__(ds, c);
100
713k
    }
101
193M
}
Unexecuted instantiation: flow_extract_target.c:ds_put_char
Unexecuted instantiation: dp-packet.c:ds_put_char
dynamic-string.c:ds_put_char
Line
Count
Source
94
98.5M
{
95
98.5M
    if (ds->length < ds->allocated) {
96
97.9M
        ds->string[ds->length++] = c;
97
97.9M
        ds->string[ds->length] = '\0';
98
97.9M
    } else {
99
598k
        ds_put_char__(ds, c);
100
598k
    }
101
98.5M
}
flow.c:ds_put_char
Line
Count
Source
94
61.0k
{
95
61.0k
    if (ds->length < ds->allocated) {
96
59.3k
        ds->string[ds->length++] = c;
97
59.3k
        ds->string[ds->length] = '\0';
98
59.3k
    } else {
99
1.70k
        ds_put_char__(ds, c);
100
1.70k
    }
101
61.0k
}
match.c:ds_put_char
Line
Count
Source
94
627k
{
95
627k
    if (ds->length < ds->allocated) {
96
614k
        ds->string[ds->length++] = c;
97
614k
        ds->string[ds->length] = '\0';
98
614k
    } else {
99
13.0k
        ds_put_char__(ds, c);
100
13.0k
    }
101
627k
}
netdev.c:ds_put_char
Line
Count
Source
94
63.3k
{
95
63.3k
    if (ds->length < ds->allocated) {
96
63.2k
        ds->string[ds->length++] = c;
97
63.2k
        ds->string[ds->length] = '\0';
98
63.2k
    } else {
99
157
        ds_put_char__(ds, c);
100
157
    }
101
63.3k
}
ofp-match.c:ds_put_char
Line
Count
Source
94
3.33k
{
95
3.33k
    if (ds->length < ds->allocated) {
96
3.33k
        ds->string[ds->length++] = c;
97
3.33k
        ds->string[ds->length] = '\0';
98
3.33k
    } else {
99
0
        ds_put_char__(ds, c);
100
0
    }
101
3.33k
}
Unexecuted instantiation: ofp-msgs.c:ds_put_char
ofp-port.c:ds_put_char
Line
Count
Source
94
111k
{
95
111k
    if (ds->length < ds->allocated) {
96
105k
        ds->string[ds->length++] = c;
97
105k
        ds->string[ds->length] = '\0';
98
105k
    } else {
99
5.94k
        ds_put_char__(ds, c);
100
5.94k
    }
101
111k
}
ofp-print.c:ds_put_char
Line
Count
Source
94
1.82M
{
95
1.82M
    if (ds->length < ds->allocated) {
96
1.79M
        ds->string[ds->length++] = c;
97
1.79M
        ds->string[ds->length] = '\0';
98
1.79M
    } else {
99
29.7k
        ds_put_char__(ds, c);
100
29.7k
    }
101
1.82M
}
Unexecuted instantiation: ofp-prop.c:ds_put_char
ofp-protocol.c:ds_put_char
Line
Count
Source
94
6.39k
{
95
6.39k
    if (ds->length < ds->allocated) {
96
4.99k
        ds->string[ds->length++] = c;
97
4.99k
        ds->string[ds->length] = '\0';
98
4.99k
    } else {
99
1.39k
        ds_put_char__(ds, c);
100
1.39k
    }
101
6.39k
}
ofp-queue.c:ds_put_char
Line
Count
Source
94
50.7k
{
95
50.7k
    if (ds->length < ds->allocated) {
96
48.2k
        ds->string[ds->length++] = c;
97
48.2k
        ds->string[ds->length] = '\0';
98
48.2k
    } else {
99
2.45k
        ds_put_char__(ds, c);
100
2.45k
    }
101
50.7k
}
ofp-switch.c:ds_put_char
Line
Count
Source
94
19.0k
{
95
19.0k
    if (ds->length < ds->allocated) {
96
18.3k
        ds->string[ds->length++] = c;
97
18.3k
        ds->string[ds->length] = '\0';
98
18.3k
    } else {
99
741
        ds_put_char__(ds, c);
100
741
    }
101
19.0k
}
ofp-table.c:ds_put_char
Line
Count
Source
94
634k
{
95
634k
    if (ds->length < ds->allocated) {
96
630k
        ds->string[ds->length++] = c;
97
630k
        ds->string[ds->length] = '\0';
98
630k
    } else {
99
4.23k
        ds_put_char__(ds, c);
100
4.23k
    }
101
634k
}
Unexecuted instantiation: ofp-util.c:ds_put_char
Unexecuted instantiation: ofpbuf.c:ds_put_char
Unexecuted instantiation: ovs-router.c:ds_put_char
packets.c:ds_put_char
Line
Count
Source
94
5.77k
{
95
5.77k
    if (ds->length < ds->allocated) {
96
5.75k
        ds->string[ds->length++] = c;
97
5.75k
        ds->string[ds->length] = '\0';
98
5.75k
    } else {
99
18
        ds_put_char__(ds, c);
100
18
    }
101
5.77k
}
Unexecuted instantiation: poll-loop.c:ds_put_char
Unexecuted instantiation: smap.c:ds_put_char
Unexecuted instantiation: socket-util.c:ds_put_char
Unexecuted instantiation: sset.c:ds_put_char
Unexecuted instantiation: timeval.c:ds_put_char
Unexecuted instantiation: tnl-ports.c:ds_put_char
tun-metadata.c:ds_put_char
Line
Count
Source
94
29.3k
{
95
29.3k
    if (ds->length < ds->allocated) {
96
28.0k
        ds->string[ds->length++] = c;
97
28.0k
        ds->string[ds->length] = '\0';
98
28.0k
    } else {
99
1.32k
        ds_put_char__(ds, c);
100
1.32k
    }
101
29.3k
}
Unexecuted instantiation: unixctl.c:ds_put_char
Unexecuted instantiation: vlog.c:ds_put_char
Unexecuted instantiation: netdev-linux.c:ds_put_char
Unexecuted instantiation: netlink-socket.c:ds_put_char
Unexecuted instantiation: rtnetlink.c:ds_put_char
Unexecuted instantiation: route-table.c:ds_put_char
Unexecuted instantiation: tc.c:ds_put_char
Unexecuted instantiation: backtrace.c:ds_put_char
Unexecuted instantiation: classifier.c:ds_put_char
Unexecuted instantiation: command-line.c:ds_put_char
Unexecuted instantiation: coverage.c:ds_put_char
Unexecuted instantiation: dp-packet-gso.c:ds_put_char
Unexecuted instantiation: dpif-offload.c:ds_put_char
Unexecuted instantiation: dpif-offload-dummy.c:ds_put_char
Unexecuted instantiation: dpif.c:ds_put_char
Unexecuted instantiation: fatal-signal.c:ds_put_char
json.c:ds_put_char
Line
Count
Source
94
87.3M
{
95
87.3M
    if (ds->length < ds->allocated) {
96
87.3M
        ds->string[ds->length++] = c;
97
87.3M
        ds->string[ds->length] = '\0';
98
87.3M
    } else {
99
4.39k
        ds_put_char__(ds, c);
100
4.39k
    }
101
87.3M
}
Unexecuted instantiation: jsonrpc.c:ds_put_char
meta-flow.c:ds_put_char
Line
Count
Source
94
884
{
95
884
    if (ds->length < ds->allocated) {
96
818
        ds->string[ds->length++] = c;
97
818
        ds->string[ds->length] = '\0';
98
818
    } else {
99
66
        ds_put_char__(ds, c);
100
66
    }
101
884
}
Unexecuted instantiation: namemap.c:ds_put_char
Unexecuted instantiation: netdev-dummy.c:ds_put_char
Unexecuted instantiation: netdev-vport.c:ds_put_char
Unexecuted instantiation: netlink.c:ds_put_char
nx-match.c:ds_put_char
Line
Count
Source
94
21.3k
{
95
21.3k
    if (ds->length < ds->allocated) {
96
19.7k
        ds->string[ds->length++] = c;
97
19.7k
        ds->string[ds->length] = '\0';
98
19.7k
    } else {
99
1.59k
        ds_put_char__(ds, c);
100
1.59k
    }
101
21.3k
}
Unexecuted instantiation: odp-execute.c:ds_put_char
Unexecuted instantiation: odp-execute-private.c:ds_put_char
odp-util.c:ds_put_char
Line
Count
Source
94
2.71M
{
95
2.71M
    if (ds->length < ds->allocated) {
96
2.70M
        ds->string[ds->length++] = c;
97
2.70M
        ds->string[ds->length] = '\0';
98
2.70M
    } else {
99
10.1k
        ds_put_char__(ds, c);
100
10.1k
    }
101
2.71M
}
ofp-actions.c:ds_put_char
Line
Count
Source
94
99.5k
{
95
99.5k
    if (ds->length < ds->allocated) {
96
94.4k
        ds->string[ds->length++] = c;
97
94.4k
        ds->string[ds->length] = '\0';
98
94.4k
    } else {
99
5.15k
        ds_put_char__(ds, c);
100
5.15k
    }
101
99.5k
}
ofp-bundle.c:ds_put_char
Line
Count
Source
94
8.82k
{
95
8.82k
    if (ds->length < ds->allocated) {
96
8.82k
        ds->string[ds->length++] = c;
97
8.82k
        ds->string[ds->length] = '\0';
98
8.82k
    } else {
99
0
        ds_put_char__(ds, c);
100
0
    }
101
8.82k
}
ofp-connection.c:ds_put_char
Line
Count
Source
94
200k
{
95
200k
    if (ds->length < ds->allocated) {
96
198k
        ds->string[ds->length++] = c;
97
198k
        ds->string[ds->length] = '\0';
98
198k
    } else {
99
1.61k
        ds_put_char__(ds, c);
100
1.61k
    }
101
200k
}
ofp-ct.c:ds_put_char
Line
Count
Source
94
3.88k
{
95
3.88k
    if (ds->length < ds->allocated) {
96
3.39k
        ds->string[ds->length++] = c;
97
3.39k
        ds->string[ds->length] = '\0';
98
3.39k
    } else {
99
486
        ds_put_char__(ds, c);
100
486
    }
101
3.88k
}
Unexecuted instantiation: ofp-ed-props.c:ds_put_char
Unexecuted instantiation: ofp-errors.c:ds_put_char
ofp-flow.c:ds_put_char
Line
Count
Source
94
224k
{
95
224k
    if (ds->length < ds->allocated) {
96
214k
        ds->string[ds->length++] = c;
97
214k
        ds->string[ds->length] = '\0';
98
214k
    } else {
99
10.2k
        ds_put_char__(ds, c);
100
10.2k
    }
101
224k
}
ofp-group.c:ds_put_char
Line
Count
Source
94
82.5k
{
95
82.5k
    if (ds->length < ds->allocated) {
96
77.6k
        ds->string[ds->length++] = c;
97
77.6k
        ds->string[ds->length] = '\0';
98
77.6k
    } else {
99
4.94k
        ds_put_char__(ds, c);
100
4.94k
    }
101
82.5k
}
ofp-ipfix.c:ds_put_char
Line
Count
Source
94
22.8k
{
95
22.8k
    if (ds->length < ds->allocated) {
96
21.4k
        ds->string[ds->length++] = c;
97
21.4k
        ds->string[ds->length] = '\0';
98
21.4k
    } else {
99
1.40k
        ds_put_char__(ds, c);
100
1.40k
    }
101
22.8k
}
ofp-meter.c:ds_put_char
Line
Count
Source
94
28.8k
{
95
28.8k
    if (ds->length < ds->allocated) {
96
22.7k
        ds->string[ds->length++] = c;
97
22.7k
        ds->string[ds->length] = '\0';
98
22.7k
    } else {
99
6.17k
        ds_put_char__(ds, c);
100
6.17k
    }
101
28.8k
}
ofp-monitor.c:ds_put_char
Line
Count
Source
94
20.4k
{
95
20.4k
    if (ds->length < ds->allocated) {
96
17.3k
        ds->string[ds->length++] = c;
97
17.3k
        ds->string[ds->length] = '\0';
98
17.3k
    } else {
99
3.06k
        ds_put_char__(ds, c);
100
3.06k
    }
101
20.4k
}
ofp-packet.c:ds_put_char
Line
Count
Source
94
125k
{
95
125k
    if (ds->length < ds->allocated) {
96
121k
        ds->string[ds->length++] = c;
97
121k
        ds->string[ds->length] = '\0';
98
121k
    } else {
99
4.09k
        ds_put_char__(ds, c);
100
4.09k
    }
101
125k
}
Unexecuted instantiation: ofp-parse.c:ds_put_char
Unexecuted instantiation: ox-stat.c:ds_put_char
Unexecuted instantiation: pcap-file.c:ds_put_char
Unexecuted instantiation: stream.c:ds_put_char
Unexecuted instantiation: svec.c:ds_put_char
Unexecuted instantiation: syslog-direct.c:ds_put_char
Unexecuted instantiation: syslog-libc.c:ds_put_char
Unexecuted instantiation: tnl-neigh-cache.c:ds_put_char
Unexecuted instantiation: netdev-native-tnl.c:ds_put_char
Unexecuted instantiation: unicode.c:ds_put_char
Unexecuted instantiation: daemon-unix.c:ds_put_char
Unexecuted instantiation: stream-unix.c:ds_put_char
Unexecuted instantiation: dpif-netlink.c:ds_put_char
Unexecuted instantiation: dpif-netlink-rtnl.c:ds_put_char
Unexecuted instantiation: dpif-offload-tc.c:ds_put_char
Unexecuted instantiation: dpif-offload-tc-netdev.c:ds_put_char
Unexecuted instantiation: netlink-conntrack.c:ds_put_char
Unexecuted instantiation: netlink-notifier.c:ds_put_char
Unexecuted instantiation: stream-ssl.c:ds_put_char
bundle.c:ds_put_char
Line
Count
Source
94
19.0k
{
95
19.0k
    if (ds->length < ds->allocated) {
96
18.4k
        ds->string[ds->length++] = c;
97
18.4k
        ds->string[ds->length] = '\0';
98
18.4k
    } else {
99
549
        ds_put_char__(ds, c);
100
549
    }
101
19.0k
}
Unexecuted instantiation: conntrack.c:ds_put_char
Unexecuted instantiation: cooperative-multitasking.c:ds_put_char
Unexecuted instantiation: ct-dpif.c:ds_put_char
Unexecuted instantiation: dpctl.c:ds_put_char
Unexecuted instantiation: dpif-netdev.c:ds_put_char
Unexecuted instantiation: dpif-netdev-private-dfc.c:ds_put_char
Unexecuted instantiation: dpif-netdev-private-dpif.c:ds_put_char
Unexecuted instantiation: dpif-netdev-private-extract.c:ds_put_char
Unexecuted instantiation: dpif-netdev-perf.c:ds_put_char
Unexecuted instantiation: ipf.c:ds_put_char
learn.c:ds_put_char
Line
Count
Source
94
43.4k
{
95
43.4k
    if (ds->length < ds->allocated) {
96
43.1k
        ds->string[ds->length++] = c;
97
43.1k
        ds->string[ds->length] = '\0';
98
43.1k
    } else {
99
283
        ds_put_char__(ds, c);
100
283
    }
101
43.4k
}
Unexecuted instantiation: multipath.c:ds_put_char
Unexecuted instantiation: process.c:ds_put_char
Unexecuted instantiation: stream-tcp.c:ds_put_char
Unexecuted instantiation: conntrack-icmp.c:ds_put_char
Unexecuted instantiation: conntrack-tcp.c:ds_put_char
Unexecuted instantiation: conntrack-tp.c:ds_put_char
Unexecuted instantiation: conntrack-other.c:ds_put_char
Unexecuted instantiation: dpif-netdev-extract-study.c:ds_put_char
Unexecuted instantiation: dpif-netdev-lookup.c:ds_put_char
Unexecuted instantiation: dpif-netdev-lookup-autovalidator.c:ds_put_char
Unexecuted instantiation: dpif-netdev-lookup-generic.c:ds_put_char
Unexecuted instantiation: ovsdb-data.c:ds_put_char
Unexecuted instantiation: ovsdb-error.c:ds_put_char
Unexecuted instantiation: ovsdb-idl.c:ds_put_char
Unexecuted instantiation: ovsdb-types.c:ds_put_char
Unexecuted instantiation: ovsdb-cs.c:ds_put_char
Unexecuted instantiation: odp_target.c:ds_put_char
Unexecuted instantiation: miniflow_target.c:ds_put_char
Unexecuted instantiation: ofp_print_target.c:ds_put_char
Unexecuted instantiation: ofctl_parse_target.c:ds_put_char
102
103
#ifdef __cplusplus
104
}
105
#endif
106
107
#endif /* dynamic-string.h */