Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssh/src/xmalloc.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | void | - | ||||||||||||||||||
10 | ssh_malloc_init(void) | - | ||||||||||||||||||
11 | { | - | ||||||||||||||||||
12 | - | |||||||||||||||||||
13 | - | |||||||||||||||||||
14 | - | |||||||||||||||||||
15 | - | |||||||||||||||||||
16 | - | |||||||||||||||||||
17 | } | - | ||||||||||||||||||
18 | - | |||||||||||||||||||
19 | void * | - | ||||||||||||||||||
20 | xmalloc(size_t size) | - | ||||||||||||||||||
21 | { | - | ||||||||||||||||||
22 | void *ptr; | - | ||||||||||||||||||
23 | - | |||||||||||||||||||
24 | if (size == 0
| 0-7981 | ||||||||||||||||||
25 | fatal("xmalloc: zero size"); never executed: fatal("xmalloc: zero size"); | 0 | ||||||||||||||||||
26 | ptr = malloc(size); | - | ||||||||||||||||||
27 | if (ptr ==
| 0-7981 | ||||||||||||||||||
28 | ((void *)0)
| 0-7981 | ||||||||||||||||||
29 | ) | - | ||||||||||||||||||
30 | fatal("xmalloc: out of memory (allocating %zu bytes)", size); never executed: fatal("xmalloc: out of memory (allocating %zu bytes)", size); | 0 | ||||||||||||||||||
31 | return executed 7981 times by 4 tests: ptr;return ptr; Executed by:
executed 7981 times by 4 tests: return ptr; Executed by:
| 7981 | ||||||||||||||||||
32 | } | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | void * | - | ||||||||||||||||||
35 | xcalloc(size_t nmemb, size_t size) | - | ||||||||||||||||||
36 | { | - | ||||||||||||||||||
37 | void *ptr; | - | ||||||||||||||||||
38 | - | |||||||||||||||||||
39 | if (size == 0
| 0-10 | ||||||||||||||||||
40 | fatal("xcalloc: zero size"); never executed: fatal("xcalloc: zero size"); | 0 | ||||||||||||||||||
41 | if ( | - | ||||||||||||||||||
42 | (
| 0-10 | ||||||||||||||||||
43 | / nmemb < size
| 0-10 | ||||||||||||||||||
44 | fatal("xcalloc: nmemb * size > SIZE_MAX"); never executed: fatal("xcalloc: nmemb * size > SIZE_MAX"); | 0 | ||||||||||||||||||
45 | ptr = calloc(nmemb, size); | - | ||||||||||||||||||
46 | if (ptr ==
| 0-10 | ||||||||||||||||||
47 | ((void *)0)
| 0-10 | ||||||||||||||||||
48 | ) | - | ||||||||||||||||||
49 | fatal("xcalloc: out of memory (allocating %zu bytes)", never executed: fatal("xcalloc: out of memory (allocating %zu bytes)", size * nmemb); | 0 | ||||||||||||||||||
50 | size * nmemb); never executed: fatal("xcalloc: out of memory (allocating %zu bytes)", size * nmemb); | 0 | ||||||||||||||||||
51 | return executed 10 times by 1 test: ptr;return ptr; Executed by:
executed 10 times by 1 test: return ptr; Executed by:
| 10 | ||||||||||||||||||
52 | } | - | ||||||||||||||||||
53 | - | |||||||||||||||||||
54 | void * | - | ||||||||||||||||||
55 | xreallocarray(void *ptr, size_t nmemb, size_t size) | - | ||||||||||||||||||
56 | { | - | ||||||||||||||||||
57 | void *new_ptr; | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | new_ptr = reallocarray(ptr, nmemb, size); | - | ||||||||||||||||||
60 | if (new_ptr ==
| 0-1 | ||||||||||||||||||
61 | ((void *)0)
| 0-1 | ||||||||||||||||||
62 | ) | - | ||||||||||||||||||
63 | fatal("xreallocarray: out of memory (%zu elements of %zu bytes)", never executed: fatal("xreallocarray: out of memory (%zu elements of %zu bytes)", nmemb, size); | 0 | ||||||||||||||||||
64 | nmemb, size); never executed: fatal("xreallocarray: out of memory (%zu elements of %zu bytes)", nmemb, size); | 0 | ||||||||||||||||||
65 | return executed 1 time by 1 test: new_ptr;return new_ptr; Executed by:
executed 1 time by 1 test: return new_ptr; Executed by:
| 1 | ||||||||||||||||||
66 | } | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | void * | - | ||||||||||||||||||
69 | xrecallocarray(void *ptr, size_t onmemb, size_t nmemb, size_t size) | - | ||||||||||||||||||
70 | { | - | ||||||||||||||||||
71 | void *new_ptr; | - | ||||||||||||||||||
72 | - | |||||||||||||||||||
73 | new_ptr = recallocarray(ptr, onmemb, nmemb, size); | - | ||||||||||||||||||
74 | if (new_ptr ==
| 0-14 | ||||||||||||||||||
75 | ((void *)0)
| 0-14 | ||||||||||||||||||
76 | ) | - | ||||||||||||||||||
77 | fatal("xrecallocarray: out of memory (%zu elements of %zu bytes)", never executed: fatal("xrecallocarray: out of memory (%zu elements of %zu bytes)", nmemb, size); | 0 | ||||||||||||||||||
78 | nmemb, size); never executed: fatal("xrecallocarray: out of memory (%zu elements of %zu bytes)", nmemb, size); | 0 | ||||||||||||||||||
79 | return executed 14 times by 1 test: new_ptr;return new_ptr; Executed by:
executed 14 times by 1 test: return new_ptr; Executed by:
| 14 | ||||||||||||||||||
80 | } | - | ||||||||||||||||||
81 | - | |||||||||||||||||||
82 | char * | - | ||||||||||||||||||
83 | xstrdup(const char *str) | - | ||||||||||||||||||
84 | { | - | ||||||||||||||||||
85 | size_t len; | - | ||||||||||||||||||
86 | char *cp; | - | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | len = strlen(str) + 1; | - | ||||||||||||||||||
89 | cp = xmalloc(len); | - | ||||||||||||||||||
90 | strlcpy(cp, str, len); | - | ||||||||||||||||||
91 | return executed 7563 times by 4 tests: cp;return cp; Executed by:
executed 7563 times by 4 tests: return cp; Executed by:
| 7563 | ||||||||||||||||||
92 | } | - | ||||||||||||||||||
93 | - | |||||||||||||||||||
94 | int | - | ||||||||||||||||||
95 | xasprintf(char **ret, const char *fmt, ...) | - | ||||||||||||||||||
96 | { | - | ||||||||||||||||||
97 | va_list ap; | - | ||||||||||||||||||
98 | int i; | - | ||||||||||||||||||
99 | - | |||||||||||||||||||
100 | - | |||||||||||||||||||
101 | __builtin_va_start( | - | ||||||||||||||||||
102 | ap | - | ||||||||||||||||||
103 | , | - | ||||||||||||||||||
104 | fmt | - | ||||||||||||||||||
105 | ) | - | ||||||||||||||||||
106 | ; | - | ||||||||||||||||||
107 | i = vasprintf(ret, fmt, ap); | - | ||||||||||||||||||
108 | - | |||||||||||||||||||
109 | __builtin_va_end( | - | ||||||||||||||||||
110 | ap | - | ||||||||||||||||||
111 | ) | - | ||||||||||||||||||
112 | ; | - | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | if (i < 0
| 0 | ||||||||||||||||||
115 | ((void *)0)
| 0 | ||||||||||||||||||
116 | ) | - | ||||||||||||||||||
117 | fatal("xasprintf: could not allocate memory"); never executed: fatal("xasprintf: could not allocate memory"); | 0 | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | return never executed: (i);return (i); never executed: return (i); | 0 | ||||||||||||||||||
120 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |