Coverage Report

Created: 2025-07-23 06:31

/src/lighttpd1.4/src/buffer.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef _BUFFER_H_
2
#define _BUFFER_H_
3
#include "first.h"
4
5
struct tm;              /* declaration */
6
7
/**
8
 * max size of a buffer which will just be reset
9
 * to ->used = 0 instead of really freeing the buffer
10
 */
11
#define BUFFER_MAX_REUSE_SIZE 4096
12
13
/* generic string + binary data container; contains a terminating 0 in both
14
 * cases
15
 *
16
 * used == 0 indicates a special "empty" state (unset config values);
17
 * ptr might be NULL, too.
18
 *
19
 * copy/append functions will ensure used >= 1
20
 * (i.e. never leave it in the special empty state)
21
 */
22
typedef struct {
23
  char *ptr;
24
25
  /* "used" includes a terminating 0 */
26
  uint32_t used;
27
  /* size of allocated buffer at *ptr */
28
  uint32_t size;
29
} buffer;
30
31
/* create new buffer; either empty or copy given data */
32
__attribute_malloc__
33
__attribute_returns_nonnull__
34
buffer* buffer_init(void);
35
36
void buffer_free(buffer *b); /* b can be NULL */
37
38
/* reset b. if NULL != b && NULL != src, move src content to b. reset src. */
39
__attribute_nonnull__()
40
void buffer_move(buffer * restrict b, buffer * restrict src);
41
42
/* make sure buffer is large enough to store a string of given size
43
 * and a terminating zero.
44
 * sets b to an empty string, and may drop old content.
45
 * @return b->ptr
46
 */
47
__attribute_nonnull__()
48
__attribute_returns_nonnull__
49
char* buffer_string_prepare_copy(buffer *b, size_t size);
50
51
/* allocate buffer large enough to be able to append a string of given size
52
 * if b was empty (used == 0) it will contain an empty string (used == 1)
53
 * afterwards
54
 * "used" data is preserved; if not empty buffer must contain a
55
 * zero terminated string.
56
 */
57
__attribute_nonnull__()
58
__attribute_returns_nonnull__
59
char* buffer_string_prepare_append(buffer *b, size_t size);
60
61
/* extend and modify buffer for immediate addition of x bytes (differs from
62
 * buffer_string_prepare_append() which only ensures space is available)
63
 * returns pointer to which callers should immediately write x bytes
64
 */
65
__attribute_nonnull__()
66
__attribute_returns_nonnull__
67
char* buffer_extend(buffer * const restrict b, size_t x);
68
69
/* use after prepare_(copy,append) when you have written data to the buffer
70
 * to increase the buffer length by size. also sets the terminating zero.
71
 * requires enough space is present for the terminating zero (prepare with the
72
 * same size to be sure).
73
 */
74
__attribute_nonnull__()
75
void buffer_commit(buffer *b, size_t size);
76
77
/* clear buffer
78
 * - invalidate buffer contents
79
 * - unsets used chars but does not modify existing ptr contents
80
 *   (b->ptr *is not* set to an empty, '\0'-terminated string "")
81
 */
82
__attribute_nonnull__()
83
static inline void buffer_clear(buffer *b);
84
85
/* reset buffer
86
 * - invalidate buffer contents
87
 * - unsets used chars
88
 * - keeps smaller buffer (unmodified) for reuse
89
 *   (b->ptr *is not* set to an empty, '\0'-terminated string "")
90
 * - frees larger buffer (b->size > BUFFER_MAX_REUSE_SIZE)
91
 */
92
__attribute_nonnull__()
93
static inline void buffer_reset(buffer *b);
94
95
/* free buffer ptr
96
 * - invalidate buffer contents; free ptr; reset ptr, used, size to 0
97
 */
98
__attribute_cold__
99
__attribute_nonnull__()
100
void buffer_free_ptr(buffer *b);
101
102
void buffer_copy_string(buffer * restrict b, const char * restrict s);
103
void buffer_copy_string_len(buffer * restrict b, const char * restrict s, size_t len);
104
void buffer_copy_string_len_lc(buffer * restrict b, const char * restrict s, size_t len);
105
106
void buffer_append_string(buffer * restrict b, const char * restrict s);
107
void buffer_append_string_len(buffer * restrict b, const char * restrict s, size_t len);
108
void buffer_append_str2(buffer * restrict b, const char *s1, size_t len1, const char *s2, size_t len2);
109
void buffer_append_str3(buffer * restrict b, const char *s1, size_t len1, const char *s2, size_t len2, const char *s3, size_t len3);
110
111
#ifndef LI_CONST_IOVEC
112
#define LI_CONST_IOVEC
113
struct const_iovec {
114
  const void *iov_base;
115
  size_t iov_len;
116
};
117
#endif
118
119
__attribute_nonnull__()
120
void buffer_append_iovec(buffer * restrict b, const struct const_iovec *iov, size_t n);
121
122
#define buffer_append_uint_hex(b,len) buffer_append_uint_hex_lc((b),(len))
123
__attribute_nonnull__()
124
void buffer_append_uint_hex_lc(buffer *b, uintmax_t len);
125
__attribute_nonnull__()
126
void buffer_append_int(buffer *b, intmax_t val);
127
128
void buffer_append_strftime(buffer * restrict b, const char * restrict format, const struct tm * restrict tm);
129
130
/* '-', log_10 (2^bits) = bits * log 2 / log 10 < bits * 0.31, terminating 0 */
131
0
#define LI_ITOSTRING_LENGTH (2 + (8 * sizeof(intmax_t) * 31 + 99) / 100)
132
133
__attribute_nonnull__()
134
size_t li_itostrn(char *buf, size_t buf_len, intmax_t val);
135
__attribute_nonnull__()
136
size_t li_utostrn(char *buf, size_t buf_len, uintmax_t val);
137
138
/* buf must be (at least) 2*s_len big. uses lower-case hex letters. */
139
#define li_tohex(buf,buf_len,s,s_len) li_tohex_lc((buf),(buf_len),(s),(s_len))
140
__attribute_nonnull__()
141
void li_tohex_lc(char * restrict buf, size_t buf_len, const char * restrict s, size_t s_len);
142
__attribute_nonnull__()
143
void li_tohex_uc(char * restrict buf, size_t buf_len, const char * restrict s, size_t s_len);
144
145
__attribute_nonnull__()
146
__attribute_pure__
147
int buffer_eq_icase_ssn(const char * const a, const char * const b, const size_t len);
148
149
__attribute_nonnull__()
150
__attribute_pure__
151
int buffer_eq_icase_ss(const char * const a, const size_t alen, const char * const b, const size_t blen);
152
153
__attribute_nonnull__()
154
__attribute_pure__
155
int buffer_eq_icase_slen(const buffer * const b, const char * const s, const size_t slen);
156
157
__attribute_nonnull__()
158
__attribute_pure__
159
int buffer_eq_slen(const buffer * const b, const char * const s, const size_t slen);
160
161
__attribute_nonnull__()
162
__attribute_pure__
163
int buffer_is_equal(const buffer *a, const buffer *b);
164
165
__attribute_nonnull__()
166
void buffer_substr_replace (buffer * restrict b, size_t offset, size_t len, const buffer * restrict replace);
167
168
__attribute_nonnull__()
169
void buffer_append_string_encoded_hex_lc(buffer * restrict b, const char * restrict s, size_t len);
170
__attribute_nonnull__()
171
void buffer_append_string_encoded_hex_uc(buffer * restrict b, const char * restrict s, size_t len);
172
173
typedef enum {
174
  ENCODING_REL_URI = 0,  /* coding href rel-uri (/with space/and%percent) */
175
  ENCODING_REL_URI_PART, /* same as ENCODING_REL_URL plus coding / as %2F */
176
  ENCODING_HTML,         /* & becomes &amp; and so on */
177
  ENCODING_MINIMAL_XML   /* minimal encoding for xml */
178
} buffer_encoding_t;
179
180
void buffer_append_string_encoded(buffer * restrict b, const char * restrict s, size_t len, buffer_encoding_t encoding);
181
182
/* escape non-printable characters; simple escapes for \t, \r, \n; fallback to \xCC */
183
__attribute_nonnull__()
184
void buffer_append_string_c_escaped(buffer * restrict b, const char * restrict s, size_t len);
185
186
/* escape non-printable chars, '"', '\\', and chars which high bit set */
187
void buffer_append_bs_escaped (buffer * restrict b, const char * restrict s, size_t len);
188
void buffer_append_bs_escaped_json (buffer * restrict b, const char * restrict s, size_t len);
189
190
__attribute_nonnull__()
191
void buffer_urldecode_path(buffer *b);
192
193
__attribute_nonnull__()
194
__attribute_pure__
195
int buffer_is_valid_UTF8(const buffer *b);
196
197
__attribute_nonnull__()
198
void buffer_path_simplify(buffer *b);
199
200
__attribute_nonnull__()
201
void buffer_to_lower(buffer *b);
202
__attribute_nonnull__()
203
void buffer_to_upper(buffer *b);
204
205
206
/** deprecated */
207
__attribute_const__
208
char hex2int(unsigned char c);
209
210
int li_hex2bin (unsigned char *bin, size_t binlen, const char *hexstr, size_t len);
211
212
__attribute_pure__
213
static inline int light_isdigit(int c);
214
8.23k
static inline int light_isdigit(int c) {
215
8.23k
  return ((uint32_t)c-'0' <= '9'-'0');
216
8.23k
}
Unexecuted instantiation: fuzz_burl.c:light_isdigit
burl.c:light_isdigit
Line
Count
Source
214
8.23k
static inline int light_isdigit(int c) {
215
8.23k
  return ((uint32_t)c-'0' <= '9'-'0');
216
8.23k
}
Unexecuted instantiation: buffer.c:light_isdigit
Unexecuted instantiation: base64.c:light_isdigit
217
218
__attribute_pure__
219
static inline int light_isxdigit(int c);
220
0
static inline int light_isxdigit(int c) {
221
0
  return light_isdigit(c) || (((uint32_t)c | 0x20)-'a' <= 'f'-'a');
222
0
}
Unexecuted instantiation: fuzz_burl.c:light_isxdigit
Unexecuted instantiation: burl.c:light_isxdigit
Unexecuted instantiation: buffer.c:light_isxdigit
Unexecuted instantiation: base64.c:light_isxdigit
223
224
__attribute_pure__
225
static inline int light_isalpha(int c);
226
7.97k
static inline int light_isalpha(int c) {
227
7.97k
  return (((uint32_t)c | 0x20)-'a' <= 'z'-'a');
228
7.97k
}
Unexecuted instantiation: fuzz_burl.c:light_isalpha
burl.c:light_isalpha
Line
Count
Source
226
7.97k
static inline int light_isalpha(int c) {
227
7.97k
  return (((uint32_t)c | 0x20)-'a' <= 'z'-'a');
228
7.97k
}
Unexecuted instantiation: buffer.c:light_isalpha
Unexecuted instantiation: base64.c:light_isalpha
229
230
__attribute_pure__
231
static inline int light_isalnum(int c);
232
8.23k
static inline int light_isalnum(int c) {
233
8.23k
  return light_isdigit(c) || light_isalpha(c);
234
8.23k
}
Unexecuted instantiation: fuzz_burl.c:light_isalnum
burl.c:light_isalnum
Line
Count
Source
232
8.23k
static inline int light_isalnum(int c) {
233
8.23k
  return light_isdigit(c) || light_isalpha(c);
234
8.23k
}
Unexecuted instantiation: buffer.c:light_isalnum
Unexecuted instantiation: base64.c:light_isalnum
235
236
__attribute_pure__
237
static inline int light_isprint(int c);
238
0
static inline int light_isprint(int c) {
239
0
  return (uint32_t)(c - ' ') <= '~' - ' ';/*(ASCII isprint() ' ' .. '~')*/
240
0
}
Unexecuted instantiation: fuzz_burl.c:light_isprint
Unexecuted instantiation: burl.c:light_isprint
Unexecuted instantiation: buffer.c:light_isprint
Unexecuted instantiation: base64.c:light_isprint
241
242
/* https://en.wikipedia.org/wiki/Unicode_control_characters */
243
/* https://en.wikipedia.org/wiki/C0_and_C1_control_codes */
244
__attribute_pure__
245
static inline int light_iscntrl(int c);
246
0
static inline int light_iscntrl(int c) {
247
0
  return (c & 0x7F) < 0x20 || c == 0x7F; /*(optimized to branchless)*/
248
  /*(optimized for ASCII printable chars to return 0 more quickly)*/
249
  /*return __builtin_expect( (!light_isprint(c)), 0)
250
   *  && __builtin_expect( ((unsigned int)c < 0xA0), 0);*/
251
0
}
Unexecuted instantiation: fuzz_burl.c:light_iscntrl
Unexecuted instantiation: burl.c:light_iscntrl
Unexecuted instantiation: buffer.c:light_iscntrl
Unexecuted instantiation: base64.c:light_iscntrl
252
253
/* c (char byte) MUST be non-negative integer
254
 * (must mask off high bits after signed integer promotion)
255
 * https://en.wikipedia.org/wiki/UTF-8
256
 * detect invalid UTF-8 byte and byte in overlong encoding of 7-bit ASCII
257
 * (but does not detect other invalid/overlong multibyte encoding sequences) */
258
//#define light_utf8_invalid_byte(c) ((c) >= 0xF5 || ((c)|0x1) == 0xC1)
259
#define light_utf8_invalid_byte(c) \
260
49.8M
  (   __builtin_expect( ((c) >= 0xF5),       0) \
261
49.8M
   || __builtin_expect( (((c)|0x1) == 0xC1), 0) )
262
263
/* https://en.wikipedia.org/wiki/Unicode_control_characters */
264
/* https://en.wikipedia.org/wiki/C0_and_C1_control_codes */
265
__attribute_const__
266
static inline int light_iscntrl_or_utf8_invalid_byte(int c);
267
0
static inline int light_iscntrl_or_utf8_invalid_byte(int c) {
268
0
  /* return light_iscntrl(c) || light_utf8_invalid_byte(c); */
269
0
  /*(optimized for ASCII printable chars to return 0 more quickly)*/
270
0
  c &= 0xFF;
271
0
  return __builtin_expect( (!light_isprint(c)), 0)
272
0
    && (__builtin_expect( ((unsigned int)(c-0xA0) >= 0xF5-0xA0), 0)
273
0
        || __builtin_expect( (((c)|0x1) == 0xC1), 0));
274
0
}
Unexecuted instantiation: fuzz_burl.c:light_iscntrl_or_utf8_invalid_byte
Unexecuted instantiation: burl.c:light_iscntrl_or_utf8_invalid_byte
Unexecuted instantiation: buffer.c:light_iscntrl_or_utf8_invalid_byte
Unexecuted instantiation: base64.c:light_iscntrl_or_utf8_invalid_byte
275
276
0
#define light_isupper(c) ((uint32_t)(c)-'A' <= 'Z'-'A')
277
0
#define light_islower(c) ((uint32_t)(c)-'a' <= 'z'-'a')
278
279
#define light_bshift(b)           ((uint64_t)1uL << (b))
280
#define light_btst(a,b)  ((a) &   ((uint64_t)1uL << (b)))
281
#define light_bclr(a,b)  ((a) &= ~((uint64_t)1uL << (b)))
282
#define light_bset(a,b)  ((a) |=  ((uint64_t)1uL << (b)))
283
284
285
void buffer_append_path_len(buffer * restrict b, const char * restrict a, size_t alen); /* join strings with '/', if '/' not present */
286
void buffer_copy_path_len2(buffer * restrict b, const char * restrict s1, size_t len1, const char * restrict s2, size_t len2);
287
288
__attribute_nonnull__()
289
__attribute_pure__
290
static inline int buffer_has_slash_suffix (const buffer * const b);
291
292
__attribute_nonnull__()
293
__attribute_pure__
294
static inline int buffer_has_pathsep_suffix (const buffer * const b);
295
296
#define BUFFER_INTLEN_PTR(x) (int)buffer_clen(x), (x)->ptr
297
140
#define BUF_PTR_LEN(x)       (x)->ptr, buffer_clen(x)
298
299
#define CONST_LEN_STR(x) (uint32_t)sizeof(x)-1, x
300
#define CONST_STR_LEN(x) x, (uint32_t)sizeof(x) - 1
301
302
303
/* inline implementations */
304
305
__attribute_nonnull__()
306
__attribute_pure__
307
static inline int buffer_is_unset(const buffer *b);
308
0
static inline int buffer_is_unset(const buffer *b) {
309
0
    return 0 == b->used;
310
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_is_unset
Unexecuted instantiation: burl.c:buffer_is_unset
Unexecuted instantiation: buffer.c:buffer_is_unset
Unexecuted instantiation: base64.c:buffer_is_unset
311
312
__attribute_nonnull__()
313
__attribute_pure__
314
static inline int buffer_is_blank(const buffer *b);
315
372
static inline int buffer_is_blank(const buffer *b) {
316
372
    return b->used < 2; /* buffer_is_blank() || buffer_is_unset() */
317
372
}
Unexecuted instantiation: fuzz_burl.c:buffer_is_blank
Unexecuted instantiation: burl.c:buffer_is_blank
buffer.c:buffer_is_blank
Line
Count
Source
315
372
static inline int buffer_is_blank(const buffer *b) {
316
372
    return b->used < 2; /* buffer_is_blank() || buffer_is_unset() */
317
372
}
Unexecuted instantiation: base64.c:buffer_is_blank
318
319
/* buffer "C" len (bytes) */
320
__attribute_nonnull__()
321
__attribute_pure__
322
static inline uint32_t buffer_clen (const buffer *b);
323
8.22k
static inline uint32_t buffer_clen (const buffer *b) {
324
8.22k
    return b->used - (0 != b->used);
325
8.22k
}
Unexecuted instantiation: fuzz_burl.c:buffer_clen
burl.c:buffer_clen
Line
Count
Source
323
6.50k
static inline uint32_t buffer_clen (const buffer *b) {
324
6.50k
    return b->used - (0 != b->used);
325
6.50k
}
buffer.c:buffer_clen
Line
Count
Source
323
1.72k
static inline uint32_t buffer_clen (const buffer *b) {
324
1.72k
    return b->used - (0 != b->used);
325
1.72k
}
Unexecuted instantiation: base64.c:buffer_clen
326
327
/* buffer space remaining to append string without reallocating */
328
__attribute_nonnull__()
329
__attribute_pure__
330
static inline uint32_t buffer_string_space(const buffer *b);
331
0
static inline uint32_t buffer_string_space(const buffer *b) {
332
0
    return b->size ? b->size - (b->used | (0 == b->used)) : 0;
333
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_string_space
Unexecuted instantiation: burl.c:buffer_string_space
Unexecuted instantiation: buffer.c:buffer_string_space
Unexecuted instantiation: base64.c:buffer_string_space
334
335
__attribute_nonnull__()
336
static inline void buffer_copy_buffer(buffer * restrict b, const buffer * restrict src);
337
0
static inline void buffer_copy_buffer(buffer * restrict b, const buffer * restrict src) {
338
0
    buffer_copy_string_len(b, BUF_PTR_LEN(src));
339
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_copy_buffer
Unexecuted instantiation: burl.c:buffer_copy_buffer
Unexecuted instantiation: buffer.c:buffer_copy_buffer
Unexecuted instantiation: base64.c:buffer_copy_buffer
340
341
__attribute_nonnull__()
342
static inline void buffer_append_buffer(buffer * restrict b, const buffer * restrict src);
343
0
static inline void buffer_append_buffer(buffer * restrict b, const buffer * restrict src) {
344
0
    buffer_append_string_len(b, BUF_PTR_LEN(src));
345
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_append_buffer
Unexecuted instantiation: burl.c:buffer_append_buffer
Unexecuted instantiation: buffer.c:buffer_append_buffer
Unexecuted instantiation: base64.c:buffer_append_buffer
346
347
__attribute_nonnull__()
348
static inline void buffer_truncate(buffer *b, uint32_t len);
349
423
static inline void buffer_truncate(buffer *b, uint32_t len) {
350
423
    b->ptr[len] = '\0'; /* b->ptr must exist; use buffer_blank() for trunc 0 */
351
423
    b->used = len + 1;
352
423
}
Unexecuted instantiation: fuzz_burl.c:buffer_truncate
burl.c:buffer_truncate
Line
Count
Source
349
423
static inline void buffer_truncate(buffer *b, uint32_t len) {
350
423
    b->ptr[len] = '\0'; /* b->ptr must exist; use buffer_blank() for trunc 0 */
351
423
    b->used = len + 1;
352
423
}
Unexecuted instantiation: buffer.c:buffer_truncate
Unexecuted instantiation: base64.c:buffer_truncate
353
354
__attribute_nonnull__()
355
static inline void buffer_blank(buffer *b);
356
0
static inline void buffer_blank(buffer *b) {
357
0
    b->ptr ? buffer_truncate(b, 0) : (void)buffer_extend(b, 0);
358
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_blank
Unexecuted instantiation: burl.c:buffer_blank
Unexecuted instantiation: buffer.c:buffer_blank
Unexecuted instantiation: base64.c:buffer_blank
359
360
__attribute_nonnull__()
361
static inline void buffer_append_char (buffer *b, char c);
362
0
static inline void buffer_append_char (buffer *b, char c) {
363
0
    *(buffer_extend(b, 1)) = c;
364
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_append_char
Unexecuted instantiation: burl.c:buffer_append_char
Unexecuted instantiation: buffer.c:buffer_append_char
Unexecuted instantiation: base64.c:buffer_append_char
365
366
/* append '/' to non-empty strings not ending in '/' */
367
__attribute_nonnull__()
368
static inline void buffer_append_slash(buffer *b);
369
0
static inline void buffer_append_slash(buffer *b) {
370
0
    const uint32_t len = buffer_clen(b);
371
0
    if (len > 0 && '/' != b->ptr[len-1])
372
0
        buffer_append_char(b, '/');
373
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_append_slash
Unexecuted instantiation: burl.c:buffer_append_slash
Unexecuted instantiation: buffer.c:buffer_append_slash
Unexecuted instantiation: base64.c:buffer_append_slash
374
375
0
static inline void buffer_clear(buffer *b) {
376
0
  b->used = 0;
377
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_clear
Unexecuted instantiation: burl.c:buffer_clear
Unexecuted instantiation: buffer.c:buffer_clear
Unexecuted instantiation: base64.c:buffer_clear
378
379
0
static inline void buffer_reset(buffer *b) {
380
0
  b->used = 0;
381
0
  /* release buffer larger than BUFFER_MAX_REUSE_SIZE bytes */
382
0
  if (b->size > BUFFER_MAX_REUSE_SIZE) buffer_free_ptr(b);
383
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_reset
Unexecuted instantiation: burl.c:buffer_reset
Unexecuted instantiation: buffer.c:buffer_reset
Unexecuted instantiation: base64.c:buffer_reset
384
385
0
static inline int buffer_has_slash_suffix (const buffer * const b) {
386
0
    return (b->used > 1 && b->ptr[b->used-2] == '/');
387
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_has_slash_suffix
Unexecuted instantiation: burl.c:buffer_has_slash_suffix
Unexecuted instantiation: buffer.c:buffer_has_slash_suffix
Unexecuted instantiation: base64.c:buffer_has_slash_suffix
388
389
0
static inline int buffer_has_pathsep_suffix (const buffer * const b) {
390
0
    return (b->used > 1 && b->ptr[b->used-2] == '/');
391
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_has_pathsep_suffix
Unexecuted instantiation: burl.c:buffer_has_pathsep_suffix
Unexecuted instantiation: buffer.c:buffer_has_pathsep_suffix
Unexecuted instantiation: base64.c:buffer_has_pathsep_suffix
392
393
394
/* backwards compat (deprecated; older interfaces) */
395
396
#define buffer_append_string_buffer buffer_append_buffer
397
#define buffer_is_equal_caseless_string buffer_eq_icase_slen
398
#define buffer_is_equal_string buffer_eq_slen
399
400
#define BUFFER_APPEND_STRING_CONST(x, y) \
401
  buffer_append_string_len(x, y, sizeof(y) - 1)
402
403
#define BUFFER_COPY_STRING_CONST(x, y) \
404
  buffer_copy_string_len(x, y, sizeof(y) - 1)
405
406
#define CONST_BUF_LEN(x) ((x) ? (x)->ptr : NULL), buffer_string_length(x)
407
408
/* NULL buffer or empty buffer (used == 0);
409
 * unset "string" (buffer) config options are initialized to used == 0,
410
 * while setting an empty string leads to used == 1
411
 */
412
__attribute_pure__
413
static inline int buffer_is_empty(const buffer *b);
414
0
static inline int buffer_is_empty(const buffer *b) {
415
0
  return NULL == b || buffer_is_unset(b);
416
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_is_empty
Unexecuted instantiation: burl.c:buffer_is_empty
Unexecuted instantiation: buffer.c:buffer_is_empty
Unexecuted instantiation: base64.c:buffer_is_empty
417
/* NULL buffer, empty buffer (used == 0) or empty string (used == 1) */
418
__attribute_pure__
419
static inline int buffer_string_is_empty(const buffer *b);
420
0
static inline int buffer_string_is_empty(const buffer *b) {
421
0
  return NULL == b || buffer_is_blank(b);
422
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_string_is_empty
Unexecuted instantiation: burl.c:buffer_string_is_empty
Unexecuted instantiation: buffer.c:buffer_string_is_empty
Unexecuted instantiation: base64.c:buffer_string_is_empty
423
424
/* buffer string length without terminating 0 */
425
__attribute_pure__
426
static inline uint32_t buffer_string_length(const buffer *b);
427
0
static inline uint32_t buffer_string_length(const buffer *b) {
428
0
  return NULL != b ? buffer_clen(b) : 0;
429
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_string_length
Unexecuted instantiation: burl.c:buffer_string_length
Unexecuted instantiation: buffer.c:buffer_string_length
Unexecuted instantiation: base64.c:buffer_string_length
430
431
/* sets string length:
432
 * - deprecated; use buffer_truncate() or buffer_extend() instead
433
 * - always stores a terminating zero to terminate the "new" string
434
 * - does not modify the string data apart from terminating zero
435
 * - reallocates the buffer iff needed
436
 */
437
__attribute_nonnull__()
438
static inline void buffer_string_set_length(buffer *b, uint32_t len);
439
0
static inline void buffer_string_set_length(buffer *b, uint32_t len) {
440
0
    if (len < b->size)
441
0
        buffer_truncate(b, len);
442
0
    else
443
0
        buffer_extend(b, len - buffer_clen(b));
444
0
}
Unexecuted instantiation: fuzz_burl.c:buffer_string_set_length
Unexecuted instantiation: burl.c:buffer_string_set_length
Unexecuted instantiation: buffer.c:buffer_string_set_length
Unexecuted instantiation: base64.c:buffer_string_set_length
445
446
447
#include "ck.h"
448
10.6k
#define force_assert(x) ck_assert(x)
449
#define log_failed_assert(file,line,msg) ck_bt_abort((file),(line),(msg))
450
#define SEGFAULT() ck_bt_abort(__FILE__, __LINE__, "aborted")
451
452
453
#endif