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