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;
49typedef uint32_t MemTxResult;
50typedef uint64_t MemTxAttrs;
51
52static void __bufwrite(uint8_t *buf, ssize_t len)
53{
54 int first, last;
55 __coverity_negative_sink__(len);
56 if (len == 0) return;
57 buf[0] = first;
58 buf[len-1] = last;
59 __coverity_writeall__(buf);
60}
61
62static void __bufread(uint8_t *buf, ssize_t len)
63{
64 __coverity_negative_sink__(len);
65 if (len == 0) return;
66 int first = buf[0];
67 int last = buf[len-1];
68}
69
70MemTxResult address_space_read(AddressSpace *as, hwaddr addr,
71 MemTxAttrs attrs,
72 uint8_t *buf, int len)
73{
74 MemTxResult result;
75
76
77 __bufwrite(buf, len);
78 return result;
79}
80
81MemTxResult address_space_write(AddressSpace *as, hwaddr addr,
82 MemTxAttrs attrs,
83 const uint8_t *buf, int len)
84{
85 MemTxResult result;
86 __bufread(buf, len);
87 return result;
88}
89
90
91
92
93typedef struct {} name2keysym_t;
94static int get_keysym(const name2keysym_t *table,
95 const char *name)
96{
97 int result;
98 if (result > 0) {
99 __coverity_tainted_string_sanitize_content__(name);
100 return result;
101 } else {
102 return 0;
103 }
104}
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129void *g_malloc_n(size_t nmemb, size_t size)
130{
131 size_t sz;
132 void *ptr;
133
134 __coverity_negative_sink__(nmemb);
135 __coverity_negative_sink__(size);
136 sz = nmemb * size;
137 ptr = __coverity_alloc__(sz);
138 __coverity_mark_as_uninitialized_buffer__(ptr);
139 __coverity_mark_as_afm_allocated__(ptr, "g_free");
140 return ptr;
141}
142
143void *g_malloc0_n(size_t nmemb, size_t size)
144{
145 size_t sz;
146 void *ptr;
147
148 __coverity_negative_sink__(nmemb);
149 __coverity_negative_sink__(size);
150 sz = nmemb * size;
151 ptr = __coverity_alloc__(sz);
152 __coverity_writeall0__(ptr);
153 __coverity_mark_as_afm_allocated__(ptr, "g_free");
154 return ptr;
155}
156
157void *g_realloc_n(void *ptr, size_t nmemb, size_t size)
158{
159 size_t sz;
160
161 __coverity_negative_sink__(nmemb);
162 __coverity_negative_sink__(size);
163 sz = nmemb * size;
164 __coverity_escape__(ptr);
165 ptr = __coverity_alloc__(sz);
166
167
168
169
170 __coverity_writeall__(ptr);
171 __coverity_mark_as_afm_allocated__(ptr, "g_free");
172 return ptr;
173}
174
175void g_free(void *ptr)
176{
177 __coverity_free__(ptr);
178 __coverity_mark_as_afm_freed__(ptr, "g_free");
179}
180
181
182
183
184
185
186void *g_try_malloc_n(size_t nmemb, size_t size)
187{
188 int nomem;
189
190 if (nomem) {
191 return NULL;
192 }
193 return g_malloc_n(nmemb, size);
194}
195
196void *g_try_malloc0_n(size_t nmemb, size_t size)
197{
198 int nomem;
199
200 if (nomem) {
201 return NULL;
202 }
203 return g_malloc0_n(nmemb, size);
204}
205
206void *g_try_realloc_n(void *ptr, size_t nmemb, size_t size)
207{
208 int nomem;
209
210 if (nomem) {
211 return NULL;
212 }
213 return g_realloc_n(ptr, nmemb, size);
214}
215
216
217
218void *g_malloc(size_t size)
219{
220 return g_malloc_n(1, size);
221}
222
223void *g_malloc0(size_t size)
224{
225 return g_malloc0_n(1, size);
226}
227
228void *g_realloc(void *ptr, size_t size)
229{
230 return g_realloc_n(ptr, 1, size);
231}
232
233void *g_try_malloc(size_t size)
234{
235 return g_try_malloc_n(1, size);
236}
237
238void *g_try_malloc0(size_t size)
239{
240 return g_try_malloc0_n(1, size);
241}
242
243void *g_try_realloc(void *ptr, size_t size)
244{
245 return g_try_realloc_n(ptr, 1, size);
246}
247
248
249
250void *g_memdup(const void *ptr, unsigned size)
251{
252 unsigned char *dup;
253 unsigned i;
254
255 if (!ptr) {
256 return NULL;
257 }
258
259 dup = g_malloc(size);
260 for (i = 0; i < size; i++)
261 dup[i] = ((unsigned char *)ptr)[i];
262 return dup;
263}
264
265
266
267
268
269char *g_strdup(const char *s)
270{
271 char *dup;
272 size_t i;
273
274 if (!s) {
275 return NULL;
276 }
277
278 __coverity_string_null_sink__(s);
279 __coverity_string_size_sink__(s);
280 dup = __coverity_alloc_nosize__();
281 __coverity_mark_as_afm_allocated__(dup, "g_free");
282 for (i = 0; (dup[i] = s[i]); i++) ;
283 return dup;
284}
285
286char *g_strndup(const char *s, size_t n)
287{
288 char *dup;
289 size_t i;
290
291 __coverity_negative_sink__(n);
292
293 if (!s) {
294 return NULL;
295 }
296
297 dup = g_malloc(n + 1);
298 for (i = 0; i < n && (dup[i] = s[i]); i++) ;
299 dup[i] = 0;
300 return dup;
301}
302
303char *g_strdup_printf(const char *format, ...)
304{
305 char ch, *s;
306 size_t len;
307
308 __coverity_string_null_sink__(format);
309 __coverity_string_size_sink__(format);
310
311 ch = *format;
312
313 s = __coverity_alloc_nosize__();
314 __coverity_writeall__(s);
315 __coverity_mark_as_afm_allocated__(s, "g_free");
316 return s;
317}
318
319char *g_strdup_vprintf(const char *format, va_list ap)
320{
321 char ch, *s;
322 size_t len;
323
324 __coverity_string_null_sink__(format);
325 __coverity_string_size_sink__(format);
326
327 ch = *format;
328 ch = *(char *)ap;
329
330 s = __coverity_alloc_nosize__();
331 __coverity_writeall__(s);
332 __coverity_mark_as_afm_allocated__(s, "g_free");
333
334 return len;
335}
336
337char *g_strconcat(const char *s, ...)
338{
339 char *s;
340
341
342
343
344
345
346 s = __coverity_alloc_nosize__();
347 __coverity_writeall__(s);
348 __coverity_mark_as_afm_allocated__(s, "g_free");
349 return s;
350}
351
352
353
354typedef struct pollfd GPollFD;
355
356int poll();
357
358int g_poll (GPollFD *fds, unsigned nfds, int timeout)
359{
360 return poll(fds, nfds, timeout);
361}
362
363typedef struct _GIOChannel GIOChannel;
364GIOChannel *g_io_channel_unix_new(int fd)
365{
366 GIOChannel *c = g_malloc0(sizeof(GIOChannel));
367 __coverity_escape__(fd);
368 return c;
369}
370
371void g_assertion_message_expr(const char *domain,
372 const char *file,
373 int line,
374 const char *func,
375 const char *expr)
376{
377 __coverity_panic__();
378}
379