Coverage Report

Created: 2026-01-17 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/lighttpd1.4/src/ck.h
Line
Count
Source
1
/*
2
 * ck - C11 Annex K wrappers  (selected functions; not complete)
3
 *
4
 * ck is also an abbreviation for "check".
5
 * These are validating, checking functions.
6
 *
7
 * Copyright(c) 2016,2021 Glenn Strauss gstrauss()gluelogic.com  All rights reserved
8
 * License: BSD 3-clause (same as lighttpd)
9
 */
10
#ifndef INCLUDED_CK_H
11
#define INCLUDED_CK_H
12
#ifndef __STDC_WANT_LIB_EXT1__ /*(enable C11 Annex K ext1 *_s functions)*/
13
#define __STDC_WANT_LIB_EXT1__ 1
14
#endif
15
#if defined(__APPLE__) && defined(__MACH__)
16
#ifndef _DARWIN_C_SOURCE
17
#define _DARWIN_C_SOURCE
18
#endif
19
#endif
20
#include "first.h"
21
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__sun)
22
#ifndef _RSIZE_T_DEFINED /* expecting __EXT1_VISIBLE 1 and _RSIZE_T_DEFINED */
23
#define _RSIZE_T_DEFINED
24
typedef size_t rsize_t;
25
#endif
26
#include <errno.h>
27
#if defined(__DragonFly__)
28
typedef int errno_t;
29
#endif
30
#endif
31
32
__BEGIN_DECLS
33
34
35
#ifndef RSIZE_MAX
36
0
#define RSIZE_MAX (SIZE_MAX >> 1)
37
typedef size_t rsize_t;
38
typedef int errno_t;
39
#endif
40
41
42
errno_t ck_getenv_s (size_t * restrict len, char * restrict value, rsize_t maxsize, const char * restrict name);
43
44
/*(ck_memclear_s() is not from C11 Annex K
45
 * ck_memclear_s() is similar to memset_s() using constant byte 0 for fill)*/
46
errno_t ck_memclear_s (void *s, rsize_t smax, rsize_t n);
47
48
/*(ck_memzero() is not from C11 Annex K
49
 * ck_memzero() is a convenience wrapper around ck_memclear_s())*/
50
static inline errno_t ck_memzero(void *s, rsize_t n);
51
0
static inline errno_t ck_memzero(void *s, rsize_t n) {
52
0
    return ck_memclear_s(s, n, n);
53
0
}
Unexecuted instantiation: fuzz_burl.c:ck_memzero
Unexecuted instantiation: burl.c:ck_memzero
Unexecuted instantiation: buffer.c:ck_memzero
Unexecuted instantiation: base64.c:ck_memzero
Unexecuted instantiation: ck.c:ck_memzero
54
55
errno_t ck_strerror_s (char *s, rsize_t maxsize, errno_t errnum);
56
57
/*(ck_memeq_const_time() is not from C11 Annex K)
58
 * constant time memory compare for equality
59
 * rounds to next multiple of 64 to avoid potentially leaking exact
60
 * string lengths when subject to high precision timing attacks */
61
__attribute_nonnull__()
62
int ck_memeq_const_time (const void *a, size_t alen, const void *b, size_t blen);
63
64
/*(ck_memeq_const_time_fixed_len() is not from C11 Annex K)
65
 * constant time memory compare for equality for fixed len (e.g. digests)
66
 * (padding not necessary for digests, which have fixed, defined lengths) */
67
__attribute_nonnull__()
68
int ck_memeq_const_time_fixed_len (const void *a, const void *b, size_t len);
69
70
71
/*(ck_malloc() is not from C11 Annex K)
72
 * ck_malloc() performs malloc() on args and aborts if malloc() fails */
73
__attribute_malloc__
74
__attribute_returns_nonnull__
75
void * ck_malloc (size_t nbytes);
76
77
/*(ck_calloc() is not from C11 Annex K)
78
 * ck_calloc() performs calloc() on args and aborts if calloc() fails */
79
__attribute_malloc__
80
__attribute_returns_nonnull__
81
void * ck_calloc (size_t nmemb, size_t elt_sz);
82
83
/*(ck_realloc_u32() is not from C11 Annex K)
84
 * ck_realloc_u32() performs realloc() on *list or aborts
85
 * extends *list with n used elements by x elements of elt_sz
86
 * and ensures n + x <= UINT32_MAX */
87
__attribute_nonnull__()
88
__attribute_returns_nonnull__
89
void * ck_realloc_u32 (void **list, size_t n, size_t x, size_t elt_sz);
90
91
92
/*(ck_bt() is not from C11 Annex K)
93
 * ck_bt() prints backtrace to stderr */
94
__attribute_cold__
95
__attribute_nonnull__()
96
void ck_bt(const char *filename, unsigned int line, const char *msg);
97
98
/*(ck_bt_abort() is not from C11 Annex K)
99
 * ck_bt_abort() prints backtrace to stderr and calls abort() */
100
__attribute_cold__
101
__attribute_nonnull__()
102
__attribute_noreturn__
103
void ck_bt_abort(const char *filename, unsigned int line, const char *msg);
104
105
/*(ck_assert() and ck_assert_failed() are not from C11 Annex K)
106
 * ck_assert() executes a runtime assertion test or aborts
107
 * ck_assert() *is not* optimized away if defined(NDEBUG)
108
 * (unlike standard assert(), which *is* optimized away if defined(NDEBUG)) */
109
__attribute_cold__
110
__attribute_nonnull__()
111
__attribute_noreturn__
112
void ck_assert_failed(const char *filename, unsigned int line, const char *msg);
113
114
#define ck_assert(x) \
115
10.2k
        do { if (!(x)) ck_assert_failed(__FILE__, __LINE__, #x); } while (0)
116
117
118
__END_DECLS
119
120
121
#include <assert.h>     /* C11 static_assert() and _Static_assert() */
122
#ifndef static_assert
123
#define static_assert(x,str) ck_assert(x)
124
#endif
125
#define ck_static_assert(x) static_assert((x),#x)
126
127
128
#endif