File: | plugins/clipboard/xutils.c |
Warning: | line 87, column 25 Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright © 2004 Red Hat, Inc. |
3 | * |
4 | * Permission to use, copy, modify, distribute, and sell this software and its |
5 | * documentation for any purpose is hereby granted without fee, provided that |
6 | * the above copyright notice appear in all copies and that both that |
7 | * copyright notice and this permission notice appear in supporting |
8 | * documentation, and that the name of Red Hat not be used in advertising or |
9 | * publicity pertaining to distribution of the software without specific, |
10 | * written prior permission. Red Hat makes no representations about the |
11 | * suitability of this software for any purpose. It is provided "as is" |
12 | * without express or implied warranty. |
13 | * |
14 | * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT |
16 | * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
18 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
19 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
20 | * |
21 | * Author: Matthias Clasen, Red Hat, Inc. |
22 | */ |
23 | |
24 | #include <stdlib.h> |
25 | |
26 | #include "xutils.h" |
27 | |
28 | Atom XA_ATOM_PAIR; |
29 | Atom XA_CLIPBOARD_MANAGER; |
30 | Atom XA_CLIPBOARD; |
31 | Atom XA_DELETE; |
32 | Atom XA_INCR; |
33 | Atom XA_INSERT_PROPERTY; |
34 | Atom XA_INSERT_SELECTION; |
35 | Atom XA_MANAGER; |
36 | Atom XA_MULTIPLE; |
37 | Atom XA_NULL; |
38 | Atom XA_SAVE_TARGETS; |
39 | Atom XA_TARGETS; |
40 | Atom XA_TIMESTAMP; |
41 | |
42 | unsigned long SELECTION_MAX_SIZE = 0; |
43 | |
44 | |
45 | void |
46 | init_atoms (Display *display) |
47 | { |
48 | unsigned long max_request_size; |
49 | |
50 | if (SELECTION_MAX_SIZE > 0) |
51 | return; |
52 | |
53 | XA_ATOM_PAIR = XInternAtom (display, "ATOM_PAIR", False0); |
54 | XA_CLIPBOARD_MANAGER = XInternAtom (display, "CLIPBOARD_MANAGER", False0); |
55 | XA_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False0); |
56 | XA_DELETE = XInternAtom (display, "DELETE", False0); |
57 | XA_INCR = XInternAtom (display, "INCR", False0); |
58 | XA_INSERT_PROPERTY = XInternAtom (display, "INSERT_PROPERTY", False0); |
59 | XA_INSERT_SELECTION = XInternAtom (display, "INSERT_SELECTION", False0); |
60 | XA_MANAGER = XInternAtom (display, "MANAGER", False0); |
61 | XA_MULTIPLE = XInternAtom (display, "MULTIPLE", False0); |
62 | XA_NULL = XInternAtom (display, "NULL", False0); |
63 | XA_SAVE_TARGETS = XInternAtom (display, "SAVE_TARGETS", False0); |
64 | XA_TARGETS = XInternAtom (display, "TARGETS", False0); |
65 | XA_TIMESTAMP = XInternAtom (display, "TIMESTAMP", False0); |
66 | |
67 | max_request_size = XExtendedMaxRequestSize (display); |
68 | if (max_request_size == 0) |
69 | max_request_size = XMaxRequestSize (display); |
70 | |
71 | SELECTION_MAX_SIZE = max_request_size - 100; |
72 | if (SELECTION_MAX_SIZE > 262144) |
73 | SELECTION_MAX_SIZE = 262144; |
74 | } |
75 | |
76 | typedef struct |
77 | { |
78 | Window window; |
79 | Atom timestamp_prop_atom; |
80 | } TimeStampInfo; |
81 | |
82 | static Boolint |
83 | timestamp_predicate (Display *display, |
84 | XEvent *xevent, |
85 | XPointer arg) |
86 | { |
87 | TimeStampInfo *info = (TimeStampInfo *)arg; |
Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption | |
88 | |
89 | if (xevent->type == PropertyNotify28 && |
90 | xevent->xproperty.window == info->window && |
91 | xevent->xproperty.atom == info->timestamp_prop_atom) |
92 | return True1; |
93 | |
94 | return False0; |
95 | } |
96 | |
97 | Time |
98 | get_server_time (Display *display, |
99 | Window window) |
100 | { |
101 | unsigned char c = 'a'; |
102 | XEvent xevent; |
103 | TimeStampInfo info; |
104 | |
105 | info.timestamp_prop_atom = XInternAtom (display, "_TIMESTAMP_PROP", False0); |
106 | info.window = window; |
107 | |
108 | XChangeProperty (display, window, |
109 | info.timestamp_prop_atom, info.timestamp_prop_atom, |
110 | 8, PropModeReplace0, &c, 1); |
111 | |
112 | XIfEvent (display, &xevent, |
113 | timestamp_predicate, (XPointer)&info); |
114 | |
115 | return xevent.xproperty.time; |
116 | } |
117 |