Bug Summary

File:core/async-getprop.c
Warning:line 385, column 39
Out of bound memory access (access exceeds upper limit of memory block)

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name async-getprop.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/src -resource-dir /usr/lib/llvm-16/lib/clang/16 -D HAVE_CONFIG_H -I . -I .. -I ./include -D CROMA_LIBEXECDIR="/usr/libexec" -D HOST_ALIAS="" -D CROMA_LOCALEDIR="/usr/share/locale" -D CROMA_PKGDATADIR="/usr/share/croma" -D CROMA_DATADIR="/usr/share" -D G_LOG_DOMAIN="croma" -D SN_API_NOT_YET_FROZEN=1 -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -D _REENTRANT -D _REENTRANT -I /usr/include/startup-notification-1.0 -I /usr/include/libgtop-2.0 -D PIC -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/rootdir/src -ferror-limit 19 -fgnuc-version=4.2.1 -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-08-05-233600-31145-1 -x c core/async-getprop.c
1/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2
3/* Asynchronous X property getting hack */
4
5/*
6 * Copyright (C) 2002 Havoc Pennington
7 * Copyright (C) 1986, 1998 The Open Group
8 *
9 * Permission to use, copy, modify, distribute, and sell this software
10 * and its documentation for any purpose is hereby granted without
11 * fee, provided that the above copyright notice appear in all copies
12 * and that both that copyright notice and this permission notice
13 * appear in supporting documentation.
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 * Except as contained in this notice, the name of The Open Group shall not be
27 * used in advertising or otherwise to promote the sale, use or other dealings
28 * in this Software without prior written authorization from The Open Group.
29 */
30
31#include <assert.h>
32
33#undef DEBUG_SPEW
34#ifdef DEBUG_SPEW
35#include <stdio.h>
36#endif
37
38#include "async-getprop.h"
39
40#define NEED_REPLIES
41#include <X11/Xlibint.h>
42
43#ifndef NULL((void*)0)
44#define NULL((void*)0) ((void*)0)
45#endif
46
47typedef struct _ListNode ListNode;
48typedef struct _AgPerDisplayData AgPerDisplayData;
49
50struct _ListNode
51{
52 ListNode *next;
53};
54
55struct _AgGetPropertyTask
56{
57 ListNode node;
58
59 AgPerDisplayData *dd;
60 Window window;
61 Atom property;
62
63 unsigned long request_seq;
64 int error;
65
66 Atom actual_type;
67 int actual_format;
68
69 unsigned long n_items;
70 unsigned long bytes_after;
71 char *data;
72
73 Boolint have_reply;
74};
75
76struct _AgPerDisplayData
77{
78 ListNode node;
79 _XAsyncHandler async;
80
81 Display *display;
82 ListNode *pending_tasks;
83 ListNode *pending_tasks_tail;
84 ListNode *completed_tasks;
85 ListNode *completed_tasks_tail;
86 int n_tasks_pending;
87 int n_tasks_completed;
88};
89
90static ListNode *display_datas = NULL((void*)0);
91static ListNode *display_datas_tail = NULL((void*)0);
92
93static void
94append_to_list (ListNode **head,
95 ListNode **tail,
96 ListNode *task)
97{
98 task->next = NULL((void*)0);
99
100 if (*tail == NULL((void*)0))
101 {
102 assert (*head == NULL)((void) sizeof ((*head == ((void*)0)) ? 1 : 0), __extension__
({ if (*head == ((void*)0)) ; else __assert_fail ("*head == NULL"
, "core/async-getprop.c", 102, __extension__ __PRETTY_FUNCTION__
); }))
;
103 *head = task;
104 *tail = task;
105 }
106 else
107 {
108 (*tail)->next = task;
109 *tail = task;
110 }
111}
112
113static void
114remove_from_list (ListNode **head,
115 ListNode **tail,
116 ListNode *task)
117{
118 ListNode *prev;
119 ListNode *node;
120
121 prev = NULL((void*)0);
122 node = *head;
123 while (node != NULL((void*)0))
124 {
125 if (node == task)
126 {
127 if (prev)
128 prev->next = node->next;
129 else
130 *head = node->next;
131
132 if (node == *tail)
133 *tail = prev;
134
135 break;
136 }
137
138 prev = node;
139 node = node->next;
140 }
141
142 /* can't remove what's not there */
143 assert (node != NULL)((void) sizeof ((node != ((void*)0)) ? 1 : 0), __extension__ (
{ if (node != ((void*)0)) ; else __assert_fail ("node != NULL"
, "core/async-getprop.c", 143, __extension__ __PRETTY_FUNCTION__
); }))
;
144
145 node->next = NULL((void*)0);
146}
147
148static void
149move_to_completed (AgPerDisplayData *dd,
150 AgGetPropertyTask *task)
151{
152 remove_from_list (&dd->pending_tasks,
153 &dd->pending_tasks_tail,
154 &task->node);
155
156 append_to_list (&dd->completed_tasks,
157 &dd->completed_tasks_tail,
158 &task->node);
159
160 dd->n_tasks_pending -= 1;
161 dd->n_tasks_completed += 1;
162}
163
164static AgGetPropertyTask*
165find_pending_by_request_sequence (AgPerDisplayData *dd,
166 unsigned long request_seq)
167{
168 ListNode *node;
169
170 /* if the sequence is after our last pending task, we
171 * aren't going to find a match
172 */
173 {
174 AgGetPropertyTask *task = (AgGetPropertyTask*) dd->pending_tasks_tail;
175 if (task != NULL((void*)0))
176 {
177 if (task->request_seq < request_seq)
178 return NULL((void*)0);
179 else if (task->request_seq == request_seq)
180 return task; /* why not check this */
181 }
182 }
183
184 /* Generally we should get replies in the order we sent
185 * requests, so we should usually be using the task
186 * at the head of the list, if we use any task at all.
187 * I'm not sure this is 100% guaranteed, if it is,
188 * it would be a big speedup.
189 */
190
191 node = dd->pending_tasks;
192 while (node != NULL((void*)0))
193 {
194 AgGetPropertyTask *task = (AgGetPropertyTask*) node;
195
196 if (task->request_seq == request_seq)
197 return task;
198
199 node = node->next;
200 }
201
202 return NULL((void*)0);
203}
204
205static Boolint
206async_get_property_handler (Display *dpy,
207 xReply *rep,
208 char *buf,
209 int len,
210 XPointer data)
211{
212 xGetPropertyReply replbuf;
213 xGetPropertyReply *reply;
214 AgGetPropertyTask *task;
215 AgPerDisplayData *dd;
216 int bytes_read;
217
218 dd = (void*) data;
219
220#if 0
221 printf ("%s: seeing request seq %ld buflen %d\n", __FUNCTION__,
222 dpy->last_request_read, len);
223#endif
224
225 task = find_pending_by_request_sequence (dd, dpy->last_request_read);
226
227 if (task == NULL((void*)0))
1
Assuming 'task' is not equal to NULL
2
Taking false branch
228 return False0;
229
230 assert (dpy->last_request_read == task->request_seq)((void) sizeof ((dpy->last_request_read == task->request_seq
) ? 1 : 0), __extension__ ({ if (dpy->last_request_read ==
task->request_seq) ; else __assert_fail ("dpy->last_request_read == task->request_seq"
, "core/async-getprop.c", 230, __extension__ __PRETTY_FUNCTION__
); }))
;
3
Assuming field 'last_request_read' is equal to field 'request_seq'
4
Taking true branch
231
232 task->have_reply = True1;
233 move_to_completed (dd, task);
234
235 /* read bytes so far */
236 bytes_read = SIZEOF (xReply)32;
237
238 if (rep->generic.type == X_Error0)
5
Assuming field 'type' is not equal to X_Error
6
Taking false branch
239 {
240 xError errbuf;
241
242 task->error = rep->error.errorCode;
243
244#ifdef DEBUG_SPEW
245 printf ("%s: error code = %d (ignoring error, eating %d bytes, generic.length = %ld)\n",
246 __FUNCTION__, task->error, (SIZEOF (xError)32 - bytes_read),
247 rep->generic.length);
248#endif
249
250 /* We return True (meaning we consumed the reply)
251 * because otherwise it would invoke the X error handler,
252 * and an async API is useless if you have to synchronously
253 * trap X errors. Also GetProperty can always fail, pretty
254 * much, so trapping errors is always what you want.
255 *
256 * We have to eat all the error reply data here.
257 * (kind of a charade as we know sizeof(xError) == sizeof(xReply))
258 *
259 * Passing discard = True seems to break things; I don't understand
260 * why, because there should be no extra data in an error reply,
261 * right?
262 */
263 _XGetAsyncReply (dpy, (char *)&errbuf, rep, buf, len,
264 (SIZEOF (xError)32 - bytes_read) >> 2, /* in 32-bit words */
265 False0); /* really seems like it should be True */
266
267 return True1;
268 }
269
270#ifdef DEBUG_SPEW
271 printf ("%s: already read %d bytes reading %d more for total of %d; generic.length = %ld\n",
272 __FUNCTION__, bytes_read, (SIZEOF (xGetPropertyReply)32 - bytes_read) >> 2,
273 SIZEOF (xGetPropertyReply)32, rep->generic.length);
274#endif
275
276 /* (kind of a silly as we know sizeof(xGetPropertyReply) == sizeof(xReply)) */
277 reply = (xGetPropertyReply *) (void *)
278 _XGetAsyncReply (dpy, (char *)&replbuf, rep, buf, len,
279 (SIZEOF (xGetPropertyReply)32 - bytes_read) >> 2, /* in 32-bit words */
280 False0); /* False means expecting more data to follow,
281 * don't eat the rest of the reply
282 */
283
284 bytes_read = SIZEOF (xGetPropertyReply)32;
285
286#ifdef DEBUG_SPEW
287 printf ("%s: have reply propertyType = %ld format = %d n_items = %ld\n",
288 __FUNCTION__, reply->propertyType, reply->format, reply->nItems);
289#endif
290
291 assert (task->data == NULL)((void) sizeof ((task->data == ((void*)0)) ? 1 : 0), __extension__
({ if (task->data == ((void*)0)) ; else __assert_fail ("task->data == NULL"
, "core/async-getprop.c", 291, __extension__ __PRETTY_FUNCTION__
); }))
;
7
Assuming field 'data' is equal to null
8
Taking true branch
292
293 /* This is all copied from XGetWindowProperty(). Not sure we should
294 * LockDisplay(). Not sure I'm passing the right args to
295 * XGetAsyncData(). Not sure about a lot of things.
296 */
297
298 /* LockDisplay (dpy); */
299
300 if (reply->propertyType != None0L)
9
Assuming field 'propertyType' is not equal to None
10
Taking true branch
301 {
302 long nbytes, netbytes;
303
304 /* this alignment macro from cafecorba2 */
305#define ALIGN_VALUE(this, boundary)(( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)
) & (~(((unsigned long)(boundary))-1)))
\
306 (( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1)))
307
308 switch (reply->format)
11
Control jumps to 'case 32:' at line 351
309 {
310 /*
311 * One extra byte is malloced than is needed to contain the property
312 * data, but this last byte is null terminated and convenient for
313 * returning string properties, so the client doesn't then have to
314 * recopy the string to make it null terminated.
315 */
316 case 8:
317 nbytes = reply->nItems;
318 /* there's padding to word boundary */
319 netbytes = ALIGN_VALUE (nbytes, 4)(( ((unsigned long)(nbytes)) + (((unsigned long)(4)) -1)) &
(~(((unsigned long)(4))-1)))
;
320 if (nbytes + 1 > 0 &&
321 (task->data = (char *) Xmalloc ((unsigned)nbytes + 1)malloc((size_t)(((unsigned)nbytes + 1) == 0 ? 1 : ((unsigned)
nbytes + 1)))
))
322 {
323#ifdef DEBUG_SPEW
324 printf ("%s: already read %d bytes using %ld, more eating %ld more\n",
325 __FUNCTION__, bytes_read, nbytes, netbytes);
326#endif
327 /* _XReadPad (dpy, (char *) task->data, netbytes); */
328 _XGetAsyncData (dpy, task->data, buf, len,
329 bytes_read, nbytes,
330 netbytes);
331 }
332 break;
333
334 case 16:
335 nbytes = reply->nItems * sizeof (short);
336 netbytes = reply->nItems << 1;
337 netbytes = ALIGN_VALUE (netbytes, 4)(( ((unsigned long)(netbytes)) + (((unsigned long)(4)) -1)) &
(~(((unsigned long)(4))-1)))
; /* align to word boundary */
338 if (nbytes + 1 > 0 &&
339 (task->data = (char *) Xmalloc ((unsigned)nbytes + 1)malloc((size_t)(((unsigned)nbytes + 1) == 0 ? 1 : ((unsigned)
nbytes + 1)))
))
340 {
341#ifdef DEBUG_SPEW
342 printf ("%s: already read %d bytes using %ld more, eating %ld more\n",
343 __FUNCTION__, bytes_read, nbytes, netbytes);
344#endif
345 /* _XRead16Pad (dpy, (short *) task->data, netbytes); */
346 _XGetAsyncData (dpy, task->data, buf, len,
347 bytes_read, nbytes, netbytes);
348 }
349 break;
350
351 case 32:
352 /* NOTE buffer is in longs to match XGetWindowProperty() */
353 nbytes = reply->nItems * sizeof (long);
354 netbytes = reply->nItems << 2; /* wire size is always 32 bits though */
355 if (nbytes + 1 > 0 &&
12
Assuming the condition is true
16
Taking true branch
356 (task->data = (char *) Xmalloc ((unsigned)nbytes + 1)malloc((size_t)(((unsigned)nbytes + 1) == 0 ? 1 : ((unsigned)
nbytes + 1)))
))
13
Assuming the condition is true
14
'?' condition is true
15
Assuming field 'data' is non-null
357 {
358#ifdef DEBUG_SPEW
359 printf ("%s: already read %d bytes using %ld more, eating %ld more\n",
360 __FUNCTION__, bytes_read, nbytes, netbytes);
361#endif
362
363 /* We have to copy the XGetWindowProperty() crackrock
364 * and get format 32 as long even on 64-bit platforms.
365 */
366 if (sizeof (long) == 8)
17
Taking true branch
367 {
368 char *netdata;
369 char *lptr;
370 char *end_lptr;
371
372 /* Store the 32-bit values in the end of the array */
373 netdata = task->data + nbytes / 2;
374
375 _XGetAsyncData (dpy, netdata, buf, len,
376 bytes_read, netbytes,
377 netbytes);
378
379 /* Now move the 32-bit values to the front */
380
381 lptr = task->data;
382 end_lptr = task->data + nbytes;
383 while (lptr != end_lptr)
18
Loop condition is true. Entering loop body
384 {
385 *(long*) lptr = *(CARD32*) netdata;
19
Out of bound memory access (access exceeds upper limit of memory block)
386 lptr += sizeof (long);
387 netdata += sizeof (CARD32);
388 }
389 }
390 else
391 {
392 /* Here the wire format matches our actual format */
393 _XGetAsyncData (dpy, task->data, buf, len,
394 bytes_read, netbytes,
395 netbytes);
396 }
397 }
398 break;
399
400 default:
401 /*
402 * This part of the code should never be reached. If it is,
403 * the server sent back a property with an invalid format.
404 * This is a BadImplementation error.
405 *
406 * However this async GetProperty API doesn't report errors
407 * via the standard X mechanism, so don't do anything about
408 * it, other than store it in task->error.
409 */
410 {
411#if 0
412 xError error;
413#endif
414
415 task->error = BadImplementation17;
416
417#if 0
418 error.sequenceNumber = task->request_seq;
419 error.type = X_Error0;
420 error.majorCode = X_GetProperty20;
421 error.minorCode = 0;
422 error.errorCode = BadImplementation17;
423
424 _XError (dpy, &error);
425#endif
426 }
427
428 nbytes = netbytes = 0L;
429 break;
430 }
431
432 if (task->data == NULL((void*)0))
433 {
434 task->error = BadAlloc11;
435
436#ifdef DEBUG_SPEW
437 printf ("%s: already read %d bytes eating %ld\n",
438 __FUNCTION__, bytes_read, netbytes);
439#endif
440 /* _XEatData (dpy, (unsigned long) netbytes); */
441 _XGetAsyncData (dpy, NULL((void*)0), buf, len,
442 bytes_read, 0, netbytes);
443
444 /* UnlockDisplay (dpy); */
445 return BadAlloc11; /* not Success */
446 }
447
448 (task->data)[nbytes] = '\0';
449 }
450
451#ifdef DEBUG_SPEW
452 printf ("%s: have data\n", __FUNCTION__);
453#endif
454
455 task->actual_type = reply->propertyType;
456 task->actual_format = reply->format;
457 task->n_items = reply->nItems;
458 task->bytes_after = reply->bytesAfter;
459
460 /* UnlockDisplay (dpy); */
461
462 return True1;
463}
464
465static AgPerDisplayData*
466get_display_data (Display *display,
467 Boolint create)
468{
469 ListNode *node;
470 AgPerDisplayData *dd;
471
472 node = display_datas;
473 while (node != NULL((void*)0))
474 {
475 dd = (AgPerDisplayData*) node;
476
477 if (dd->display == display)
478 return dd;
479
480 node = node->next;
481 }
482
483 if (!create)
484 return NULL((void*)0);
485
486 dd = Xcalloc (1, sizeof (AgPerDisplayData))calloc((size_t)((1) == 0 ? 1 : (1)), (size_t)(sizeof (AgPerDisplayData
)))
;
487 if (dd == NULL((void*)0))
488 return NULL((void*)0);
489
490 dd->display = display;
491 dd->async.next = display->async_handlers;
492 dd->async.handler = async_get_property_handler;
493 dd->async.data = (XPointer) dd;
494 dd->display->async_handlers = &dd->async;
495
496 append_to_list (&display_datas,
497 &display_datas_tail,
498 &dd->node);
499
500 return dd;
501}
502
503static void
504maybe_free_display_data (AgPerDisplayData *dd)
505{
506 if (dd->pending_tasks == NULL((void*)0) &&
507 dd->completed_tasks == NULL((void*)0))
508 {
509 DeqAsyncHandler (dd->display, &dd->async){ if (dd->display->async_handlers == (&dd->async
)) dd->display->async_handlers = (&dd->async)->
next; else _XDeqAsyncHandler(dd->display, &dd->async
); }
;
510 remove_from_list (&display_datas, &display_datas_tail,
511 &dd->node);
512 XFree (dd);
513 }
514}
515
516AgGetPropertyTask*
517ag_task_create (Display *dpy,
518 Window window,
519 Atom property,
520 long offset,
521 long length,
522 Boolint delete,
523 Atom req_type)
524{
525 AgGetPropertyTask *task;
526 xGetPropertyReq *req;
527 AgPerDisplayData *dd;
528
529 /* Fire up our request */
530 LockDisplay (dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
531
532 dd = get_display_data (dpy, True1);
533 if (dd == NULL((void*)0))
534 {
535 UnlockDisplay (dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
536 return NULL((void*)0);
537 }
538
539 GetReq (GetProperty, req)req = (xGetPropertyReq *) _XGetRequest(dpy, 20, 24);
540 req->window = window;
541 req->property = property;
542 req->type = req_type;
543 req->delete = delete;
544 req->longOffset = offset;
545 req->longLength = length;
546
547 /* Queue up our async task */
548 task = Xcalloc (1, sizeof (AgGetPropertyTask))calloc((size_t)((1) == 0 ? 1 : (1)), (size_t)(sizeof (AgGetPropertyTask
)))
;
549 if (task == NULL((void*)0))
550 {
551 UnlockDisplay (dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
552 return NULL((void*)0);
553 }
554
555 task->dd = dd;
556 task->window = window;
557 task->property = property;
558 task->request_seq = dpy->request;
559
560 append_to_list (&dd->pending_tasks,
561 &dd->pending_tasks_tail,
562 &task->node);
563 dd->n_tasks_pending += 1;
564
565 UnlockDisplay (dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
566
567 SyncHandle ()if (dpy->synchandler) (*dpy->synchandler)(dpy);
568
569 return task;
570}
571
572static void
573free_task (AgGetPropertyTask *task)
574{
575 remove_from_list (&task->dd->completed_tasks,
576 &task->dd->completed_tasks_tail,
577 &task->node);
578 task->dd->n_tasks_completed -= 1;
579 maybe_free_display_data (task->dd);
580 XFree (task);
581}
582
583Statusint
584ag_task_get_reply_and_free (AgGetPropertyTask *task,
585 Atom *actual_type,
586 int *actual_format,
587 unsigned long *nitems,
588 unsigned long *bytesafter,
589 unsigned char **prop)
590{
591 Display *dpy;
592
593 *prop = NULL((void*)0);
594
595 dpy = task->dd->display; /* Xlib macros require a variable named "dpy" */
596
597 if (task->error != Success0)
598 {
599 Statusint s = task->error;
600
601 free_task (task);
602
603 return s;
604 }
605
606 if (!task->have_reply)
607 {
608 free_task (task);
609
610 return BadAlloc11; /* not Success */
611 }
612
613 *actual_type = task->actual_type;
614 *actual_format = task->actual_format;
615 *nitems = task->n_items;
616 *bytesafter = task->bytes_after;
617
618 *prop = (unsigned char*) task->data; /* pass out ownership of task->data */
619
620 SyncHandle ()if (dpy->synchandler) (*dpy->synchandler)(dpy);
621
622 free_task (task);
623
624 return Success0;
625}
626
627Boolint
628ag_task_have_reply (AgGetPropertyTask *task)
629{
630 return task->have_reply;
631}
632
633Atom
634ag_task_get_property (AgGetPropertyTask *task)
635{
636 return task->property;
637}
638
639Window
640ag_task_get_window (AgGetPropertyTask *task)
641{
642 return task->window;
643}
644
645Display*
646ag_task_get_display (AgGetPropertyTask *task)
647{
648 return task->dd->display;
649}
650
651AgGetPropertyTask*
652ag_get_next_completed_task (Display *display)
653{
654 AgPerDisplayData *dd;
655
656 dd = get_display_data (display, False0);
657
658 if (dd == NULL((void*)0))
659 return NULL((void*)0);
660
661#ifdef DEBUG_SPEW
662 printf ("%d pending %d completed\n",
663 dd->n_tasks_pending,
664 dd->n_tasks_completed);
665#endif
666
667 return (AgGetPropertyTask*) dd->completed_tasks;
668}
669
670void*
671ag_Xmalloc (unsigned long bytes)
672{
673 return (void*) Xmalloc (bytes)malloc((size_t)((bytes) == 0 ? 1 : (bytes)));
674}
675
676void*
677ag_Xmalloc0 (unsigned long bytes)
678{
679 return (void*) Xcalloc (bytes, 1)calloc((size_t)((bytes) == 0 ? 1 : (bytes)), (size_t)(1));
680}