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 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | #ifdef HAVE_CONFIG_H1 |
53 | #include <config.h> |
54 | #endif |
55 | #include "IntrinsicI.h" |
56 | #include "VarargsI.h" |
57 | #include "StringDefs.h" |
58 | |
59 | static String XtNxtGetTypedArg = "xtGetTypedArg"; |
60 | |
61 | void |
62 | XtVaGetSubresources( |
63 | Widget widget, |
64 | XtPointer base, |
65 | _Xconstconst char* name, |
66 | _Xconstconst char* class, |
67 | XtResourceList resources, |
68 | Cardinal num_resources, |
69 | ...) |
70 | { |
71 | va_list var; |
72 | XtTypedArgList args; |
73 | Cardinal num_args; |
74 | int total_count, typed_count; |
75 | WIDGET_TO_APPCON(widget)XtAppContext app = (widget && _XtProcessLock ? XtWidgetToApplicationContext (widget) : ((void*)0)); |
76 | |
77 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); |
78 | va_start(var, num_resources)__builtin_va_start(var, num_resources); |
79 | _XtCountVaList(var, &total_count, &typed_count); |
80 | va_end(var)__builtin_va_end(var); |
81 | |
82 | va_start(var, num_resources)__builtin_va_start(var, num_resources); |
83 | |
84 | _XtVaToTypedArgList(var, total_count, &args, &num_args); |
85 | |
86 | _XtGetSubresources(widget, base, name, class, resources, num_resources, |
87 | NULL((void*)0), 0, args, num_args); |
88 | |
89 | if (num_args != 0) { |
90 | XtFree((XtPointer)args); |
91 | } |
92 | |
93 | va_end(var)__builtin_va_end(var); |
94 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
95 | } |
96 | |
97 | |
98 | void |
99 | XtVaGetApplicationResources(Widget widget, XtPointer base, XtResourceList resources, Cardinal num_resources, ...) |
100 | { |
101 | va_list var; |
102 | XtTypedArgList args; |
103 | Cardinal num_args; |
104 | int total_count, typed_count; |
105 | WIDGET_TO_APPCON(widget)XtAppContext app = (widget && _XtProcessLock ? XtWidgetToApplicationContext (widget) : ((void*)0)); |
106 | |
107 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); |
108 | va_start(var,num_resources)__builtin_va_start(var, num_resources); |
109 | _XtCountVaList(var, &total_count, &typed_count); |
110 | va_end(var)__builtin_va_end(var); |
111 | |
112 | va_start(var,num_resources)__builtin_va_start(var, num_resources); |
113 | |
114 | _XtVaToTypedArgList(var, total_count, &args, &num_args); |
115 | |
116 | _XtGetApplicationResources(widget, base, resources, num_resources, |
117 | NULL((void*)0), 0, args, num_args); |
118 | |
119 | if (num_args != 0) { |
120 | XtFree((XtPointer)args); |
121 | } |
122 | |
123 | va_end(var)__builtin_va_end(var); |
124 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
125 | } |
126 | |
127 | |
128 | static void |
129 | GetTypedArg( |
130 | Widget widget, |
131 | XtTypedArgList typed_arg, |
132 | XtResourceList resources, |
133 | Cardinal num_resources) |
134 | { |
135 | String from_type = NULL((void*)0); |
136 | Cardinal from_size = 0; |
137 | XrmValue from_val, to_val; |
138 | register Cardinal i; |
139 | Arg arg; |
140 | XtPointer value; |
141 | |
142 | |
143 | |
144 | for (i = 0; i < num_resources; i++) { |
145 | if (StringToName(typed_arg->name)XrmStringToQuark(typed_arg->name) == StringToName(resources[i].resource_name)XrmStringToQuark(resources[i].resource_name)) { |
146 | from_type = resources[i].resource_type; |
147 | from_size = resources[i].resource_size; |
148 | break; |
149 | } |
150 | } |
151 | |
152 | if (i == num_resources) { |
153 | XtAppWarningMsg(XtWidgetToApplicationContext(widget), |
154 | "unknownType", XtNxtGetTypedArg, XtCXtToolkitError, |
155 | "Unable to find type of resource for conversion", |
156 | (String *)NULL((void*)0), (Cardinal *)NULL((void*)0)); |
157 | return; |
158 | } |
159 | |
160 | value = ALLOCATE_LOCAL(from_size)__builtin_alloca ((int)(from_size)); |
161 | if (value == NULL((void*)0)) _XtAllocError(NULL((void*)0)); |
162 | XtSetArg(arg, typed_arg->name, value)((void)( (arg).name = (typed_arg->name), (arg).value = (XtArgVal )(value) )); |
163 | XtGetValues(widget, &arg, 1); |
164 | |
165 | from_val.size = from_size; |
166 | from_val.addr = (XPointer)value; |
167 | to_val.addr = (XPointer)typed_arg->value; |
168 | to_val.size = typed_arg->size; |
169 | |
170 | if (!XtConvertAndStore(widget, from_type, &from_val, |
171 | typed_arg->type, &to_val)) { |
172 | if (to_val.size > (unsigned) typed_arg->size) { |
173 | String params[2]; |
174 | Cardinal num_params = 2; |
175 | params[0] = typed_arg->type; |
176 | params[1] = XtName(widget); |
177 | XtAppWarningMsg(XtWidgetToApplicationContext(widget), |
178 | "insufficientSpace", XtNxtGetTypedArg, XtCXtToolkitError, |
179 | "Insufficient space for converted type '%s' in widget '%s'", |
180 | params, &num_params); |
181 | } |
182 | else { |
183 | String params[3]; |
184 | Cardinal num_params = 3; |
185 | params[0] = from_type; |
186 | params[1] = typed_arg->type; |
187 | params[2] = XtName(widget); |
188 | XtAppWarningMsg(XtWidgetToApplicationContext(widget), |
189 | "conversionFailed", XtNxtGetTypedArg, XtCXtToolkitError, |
190 | "Type conversion (%s to %s) failed for widget '%s'", |
191 | params, &num_params); |
192 | } |
193 | } |
194 | DEALLOCATE_LOCAL(value)do {} while(0); |
195 | } |
196 | |
197 | static int |
198 | GetNestedArg( |
199 | Widget widget, |
200 | XtTypedArgList avlist, |
201 | ArgList args, |
202 | XtResourceList resources, |
203 | Cardinal num_resources) |
204 | { |
205 | int count = 0; |
206 | |
207 | for (; avlist->name != NULL((void*)0); avlist++) { |
208 | if (avlist->type != NULL((void*)0)) { |
209 | GetTypedArg(widget, avlist, resources, num_resources); |
210 | } else if(strcmp(avlist->name, XtVaNestedList"XtVaNestedList") == 0) { |
211 | count += GetNestedArg(widget, (XtTypedArgList)avlist->value, |
212 | args, resources, num_resources); |
213 | } else { |
214 | (args+count)->name = avlist->name; |
215 | (args+count)->value = avlist->value; |
216 | ++count; |
217 | } |
218 | } |
219 | |
220 | return(count); |
221 | } |
222 | |
223 | void |
224 | XtVaGetValues(Widget widget, ...) |
225 | { |
226 | va_list var; |
227 | String attr; |
228 | ArgList args; |
229 | XtTypedArg typed_arg; |
230 | XtResourceList resources = (XtResourceList)NULL((void*)0); |
231 | Cardinal num_resources; |
232 | int count, total_count, typed_count; |
233 | WIDGET_TO_APPCON(widget)XtAppContext app = (widget && _XtProcessLock ? XtWidgetToApplicationContext (widget) : ((void*)0)); |
234 | |
235 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); |
236 | va_start(var,widget)__builtin_va_start(var, widget); |
237 | |
238 | _XtCountVaList(var, &total_count, &typed_count); |
239 | |
240 | if (total_count != typed_count) { |
| |
241 | args = (ArgList)__XtMalloc((unsigned)((total_count - typed_count) |
242 | * sizeof(Arg))); |
243 | } |
244 | else args = NULL((void*)0); |
245 | va_end(var)__builtin_va_end(var); |
246 | |
247 | va_start(var,widget)__builtin_va_start(var, widget); |
248 | for(attr = va_arg(var, String)__builtin_va_arg(var, String), count = 0 ; attr != NULL((void*)0); |
| 2 | Assuming 'attr' is not equal to null |
|
| 3 | Loop condition is true. Entering loop body |
|
249 | attr = va_arg(var, String)__builtin_va_arg(var, String)) { |
250 | if (strcmp(attr, XtVaTypedArg"XtVaTypedArg") == 0) { |
| |
251 | typed_arg.name = va_arg(var, String)__builtin_va_arg(var, String); |
252 | typed_arg.type = va_arg(var, String)__builtin_va_arg(var, String); |
253 | typed_arg.value = va_arg(var, XtArgVal)__builtin_va_arg(var, XtArgVal); |
254 | typed_arg.size = va_arg(var, int)__builtin_va_arg(var, int); |
255 | |
256 | if (resources == NULL((void*)0)) { |
257 | XtGetResourceList(XtClass(widget)((widget)->core.widget_class), &resources,&num_resources); |
258 | } |
259 | |
260 | GetTypedArg(widget, &typed_arg, resources, num_resources); |
261 | } else if (strcmp(attr, XtVaNestedList"XtVaNestedList") == 0) { |
| |
262 | if (resources == NULL((void*)0)) { |
263 | XtGetResourceList(XtClass(widget)((widget)->core.widget_class),&resources, &num_resources); |
264 | } |
265 | |
266 | count += GetNestedArg(widget, va_arg(var, XtTypedArgList)__builtin_va_arg(var, XtTypedArgList), |
267 | (args+count), resources, num_resources); |
268 | } else { |
269 | args[count].name = attr; |
| 6 | Dereference of null pointer |
|
270 | args[count].value = va_arg(var, XtArgVal)__builtin_va_arg(var, XtArgVal); |
271 | count ++; |
272 | } |
273 | } |
274 | va_end(var)__builtin_va_end(var); |
275 | |
276 | if (resources != (XtResourceList)NULL((void*)0)) { |
277 | XtFree((XtPointer)resources); |
278 | } |
279 | |
280 | if (total_count != typed_count) { |
281 | XtGetValues(widget, args, count); |
282 | XtFree((XtPointer)args); |
283 | } |
284 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
285 | } |
286 | |
287 | void |
288 | XtVaGetSubvalues(XtPointer base,XtResourceList resources, Cardinal num_resources, ...) |
289 | { |
290 | va_list var; |
291 | ArgList args; |
292 | Cardinal num_args; |
293 | int total_count, typed_count; |
294 | |
295 | va_start(var,num_resources)__builtin_va_start(var, num_resources); |
296 | |
297 | _XtCountVaList(var, &total_count, &typed_count); |
298 | |
299 | if (typed_count != 0) { |
300 | XtWarning("XtVaTypedArg is an invalid argument to XtVaGetSubvalues()\n"); |
301 | } |
302 | va_end(var)__builtin_va_end(var); |
303 | |
304 | va_start(var,num_resources)__builtin_va_start(var, num_resources); |
305 | _XtVaToArgList((Widget)NULL((void*)0), var, total_count, &args, &num_args); |
306 | va_end(var)__builtin_va_end(var); |
307 | |
308 | XtGetSubvalues(base, resources, num_resources, args, num_args); |
309 | |
310 | if (num_args != 0) { |
311 | XtFree((XtPointer)args); |
312 | } |
313 | } |