1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#define NULL ((void *)0)
33
34typedef unsigned char uint8_t;
35typedef char int8_t;
36typedef unsigned int uint32_t;
37typedef int int32_t;
38typedef long ssize_t;
39typedef unsigned long long uint64_t;
40typedef long long int64_t;
41typedef _Bool bool;
42
43typedef struct va_list_str *va_list;
44
45
46
47typedef struct AddressSpace AddressSpace;
48typedef uint64_t hwaddr;
49
50static void __write(uint8_t *buf, ssize_t len)
51{
52 int first, last;
53 __coverity_negative_sink__(len);
54 if (len == 0) return;
55 buf[0] = first;
56 buf[len-1] = last;
57 __coverity_writeall__(buf);
58}
59
60static void __read(uint8_t *buf, ssize_t len)
61{
62 __coverity_negative_sink__(len);
63 if (len == 0) return;
64 int first = buf[0];
65 int last = buf[len-1];
66}
67
68bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
69 int len, bool is_write)
70{
71 bool result;
72
73
74
75 if (is_write) __write(buf, len); else __read(buf, len);
76
77 return result;
78}
79
80
81
82typedef struct {} name2keysym_t;
83static int get_keysym(const name2keysym_t *table,
84 const char *name)
85{
86 int result;
87 if (result > 0) {
88 __coverity_tainted_string_sanitize_content__(name);
89 return result;
90 } else {
91 return 0;
92 }
93}
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118void *g_malloc_n(size_t nmemb, size_t size)
119{
120 size_t sz;
121 void *ptr;
122
123 __coverity_negative_sink__(nmemb);
124 __coverity_negative_sink__(size);
125 sz = nmemb * size;
126 ptr = __coverity_alloc__(sz);
127 __coverity_mark_as_uninitialized_buffer__(ptr);
128 __coverity_mark_as_afm_allocated__(ptr, "g_free");
129 return ptr;
130}
131
132void *g_malloc0_n(size_t nmemb, size_t size)
133{
134 size_t sz;
135 void *ptr;
136
137 __coverity_negative_sink__(nmemb);
138 __coverity_negative_sink__(size);
139 sz = nmemb * size;
140 ptr = __coverity_alloc__(sz);
141 __coverity_writeall0__(ptr);
142 __coverity_mark_as_afm_allocated__(ptr, "g_free");
143 return ptr;
144}
145
146void *g_realloc_n(void *ptr, size_t nmemb, size_t size)
147{
148 size_t sz;
149
150 __coverity_negative_sink__(nmemb);
151 __coverity_negative_sink__(size);
152 sz = nmemb * size;
153 __coverity_escape__(ptr);
154 ptr = __coverity_alloc__(sz);
155
156
157
158
159 __coverity_writeall__(ptr);
160 __coverity_mark_as_afm_allocated__(ptr, "g_free");
161 return ptr;
162}
163
164void g_free(void *ptr)
165{
166 __coverity_free__(ptr);
167 __coverity_mark_as_afm_freed__(ptr, "g_free");
168}
169
170
171
172
173
174
175void *g_try_malloc_n(size_t nmemb, size_t size)
176{
177 int nomem;
178
179 if (nomem) {
180 return NULL;
181 }
182 return g_malloc_n(nmemb, size);
183}
184
185void *g_try_malloc0_n(size_t nmemb, size_t size)
186{
187 int nomem;
188
189 if (nomem) {
190 return NULL;
191 }
192 return g_malloc0_n(nmemb, size);
193}
194
195void *g_try_realloc_n(void *ptr, size_t nmemb, size_t size)
196{
197 int nomem;
198
199 if (nomem) {
200 return NULL;
201 }
202 return g_realloc_n(ptr, nmemb, size);
203}
204
205
206
207void *g_malloc(size_t size)
208{
209 return g_malloc_n(1, size);
210}
211
212void *g_malloc0(size_t size)
213{
214 return g_malloc0_n(1, size);
215}
216
217void *g_realloc(void *ptr, size_t size)
218{
219 return g_realloc_n(ptr, 1, size);
220}
221
222void *g_try_malloc(size_t size)
223{
224 return g_try_malloc_n(1, size);
225}
226
227void *g_try_malloc0(size_t size)
228{
229 return g_try_malloc0_n(1, size);
230}
231
232void *g_try_realloc(void *ptr, size_t size)
233{
234 return g_try_realloc_n(ptr, 1, size);
235}
236
237
238
239
240
241char *g_strdup(const char *s)
242{
243 char *dup;
244 size_t i;
245
246 if (!s) {
247 return NULL;
248 }
249
250 __coverity_string_null_sink__(s);
251 __coverity_string_size_sink__(s);
252 dup = __coverity_alloc_nosize__();
253 __coverity_mark_as_afm_allocated__(dup, "g_free");
254 for (i = 0; (dup[i] = s[i]); i++) ;
255 return dup;
256}
257
258char *g_strndup(const char *s, size_t n)
259{
260 char *dup;
261 size_t i;
262
263 __coverity_negative_sink__(n);
264
265 if (!s) {
266 return NULL;
267 }
268
269 dup = g_malloc(n + 1);
270 for (i = 0; i < n && (dup[i] = s[i]); i++) ;
271 dup[i] = 0;
272 return dup;
273}
274
275char *g_strdup_printf(const char *format, ...)
276{
277 char ch, *s;
278 size_t len;
279
280 __coverity_string_null_sink__(format);
281 __coverity_string_size_sink__(format);
282
283 ch = *format;
284
285 s = __coverity_alloc_nosize__();
286 __coverity_writeall__(s);
287 __coverity_mark_as_afm_allocated__(s, "g_free");
288 return s;
289}
290
291char *g_strdup_vprintf(const char *format, va_list ap)
292{
293 char ch, *s;
294 size_t len;
295
296 __coverity_string_null_sink__(format);
297 __coverity_string_size_sink__(format);
298
299 ch = *format;
300 ch = *(char *)ap;
301
302 s = __coverity_alloc_nosize__();
303 __coverity_writeall__(s);
304 __coverity_mark_as_afm_allocated__(s, "g_free");
305
306 return len;
307}
308
309char *g_strconcat(const char *s, ...)
310{
311 char *s;
312
313
314
315
316
317
318 s = __coverity_alloc_nosize__();
319 __coverity_writeall__(s);
320 __coverity_mark_as_afm_allocated__(s, "g_free");
321 return s;
322}
323
324
325
326typedef struct _GIOChannel GIOChannel;
327GIOChannel *g_io_channel_unix_new(int fd)
328{
329 GIOChannel *c = g_malloc0(sizeof(GIOChannel));
330 __coverity_escape__(fd);
331 return c;
332}
333
334void g_assertion_message_expr(const char *domain,
335 const char *file,
336 int line,
337 const char *func,
338 const char *expr)
339{
340 __coverity_panic__();
341}
342