Bug Summary

File:Composite.c
Location:line 197, column 3
Description:Access to field 'geometry_manager' results in a dereference of a null pointer (loaded from variable 'superPtr')

Annotated Source Code

1/***********************************************************
2Copyright (c) 1993, Oracle and/or its affiliates. All rights reserved.
3
4Permission is hereby granted, free of charge, to any person obtaining a
5copy of this software and associated documentation files (the "Software"),
6to deal in the Software without restriction, including without limitation
7the rights to use, copy, modify, merge, publish, distribute, sublicense,
8and/or sell copies of the Software, and to permit persons to whom the
9Software is furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice (including the next
12paragraph) shall be included in all copies or substantial portions of the
13Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21DEALINGS IN THE SOFTWARE.
22
23Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
24
25 All Rights Reserved
26
27Permission to use, copy, modify, and distribute this software and its
28documentation for any purpose and without fee is hereby granted,
29provided that the above copyright notice appear in all copies and that
30both that copyright notice and this permission notice appear in
31supporting documentation, and that the name of Digital not be
32used in advertising or publicity pertaining to distribution of the
33software without specific, written prior permission.
34
35DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
36ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
37DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
38ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
40ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
41SOFTWARE.
42
43******************************************************************/
44
45/*
46
47Copyright 1987, 1988, 1998 The Open Group
48
49Permission to use, copy, modify, distribute, and sell this software and its
50documentation for any purpose is hereby granted without fee, provided that
51the above copyright notice appear in all copies and that both that
52copyright notice and this permission notice appear in supporting
53documentation.
54
55The above copyright notice and this permission notice shall be included in
56all copies or substantial portions of the Software.
57
58THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
62AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
63CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
64
65Except as contained in this notice, the name of The Open Group shall not be
66used in advertising or otherwise to promote the sale, use or other dealings
67in this Software without prior written authorization from The Open Group.
68
69*/
70
71#ifdef HAVE_CONFIG_H1
72#include <config.h>
73#endif
74#include "IntrinsicI.h"
75#include "StringDefs.h"
76
77static XtResource resources[] = {
78 {XtNchildren((char*)&XtStrings[145]), XtCReadOnly((char*)&XtStrings[1244]), XtRWidgetList((char*)&XtStrings[1884]), sizeof(WidgetList),
79 XtOffsetOf(CompositeRec, composite.children)__builtin_offsetof(CompositeRec, composite.children), XtRImmediate((char*)&XtStrings[1695]), NULL((void*)0)},
80 {XtNnumChildren((char*)&XtStrings[493]), XtCReadOnly((char*)&XtStrings[1244]), XtRCardinal((char*)&XtStrings[1587]), sizeof(Cardinal),
81 XtOffsetOf(CompositeRec, composite.num_children)__builtin_offsetof(CompositeRec, composite.num_children), XtRImmediate((char*)&XtStrings[1695]), NULL((void*)0)},
82 {XtNinsertPosition((char*)&XtStrings[326]), XtCInsertPosition((char*)&XtStrings[1098]), XtRFunction((char*)&XtStrings[1677]), sizeof(XtOrderProc),
83 XtOffsetOf(CompositeRec, composite.insert_position)__builtin_offsetof(CompositeRec, composite.insert_position), XtRImmediate((char*)&XtStrings[1695]), NULL((void*)0)},
84};
85
86static void CompositeClassPartInitialize(WidgetClass);
87static void CompositeInitialize(Widget, Widget, ArgList, Cardinal *);
88static void CompositeInsertChild(Widget);
89static void CompositeDeleteChild(Widget);
90static void CompositeDestroy(Widget);
91
92externaldef(compositeclassrec) CompositeClassRec compositeClassRec = {
93 { /******* CorePart *******/
94 /* superclass */ &widgetClassRec,
95 /* class_name */ "Composite",
96 /* widget_size */ sizeof(CompositeRec),
97 /* class_initialize */ NULL((void*)0),
98 /* class_part_initialize*/ CompositeClassPartInitialize,
99 /* class_inited */ FALSE0,
100 /* initialize */ CompositeInitialize,
101 /* initialize_hook */ NULL((void*)0),
102 /* realize */ XtInheritRealize((XtRealizeProc) _XtInherit),
103 /* actions */ NULL((void*)0),
104 /* num_actions */ 0,
105 /* resources */ resources,
106 /* num_resources */ XtNumber(resources)((Cardinal) (sizeof(resources) / sizeof(resources[0]))),
107 /* xrm_class */ NULLQUARK((XrmQuark) 0),
108 /* compress_motion */ FALSE0,
109 /* compress_exposure */ TRUE1,
110 /* compress_enterleave */ FALSE0,
111 /* visible_interest */ FALSE0,
112 /* destroy */ CompositeDestroy,
113 /* resize */ NULL((void*)0),
114 /* expose */ NULL((void*)0),
115 /* set_values */ NULL((void*)0),
116 /* set_values_hook */ NULL((void*)0),
117 /* set_values_almost */ XtInheritSetValuesAlmost((XtAlmostProc) _XtInherit),
118 /* get_values_hook */ NULL((void*)0),
119 /* accept_focus */ NULL((void*)0),
120 /* version */ XtVersion(11 * 1000 + 6),
121 /* callback_offsets */ NULL((void*)0),
122 /* tm_table */ NULL((void*)0),
123 /* query_geometry */ NULL((void*)0),
124 /* display_accelerator */ NULL((void*)0),
125 /* extension */ NULL((void*)0)
126 },
127 { /**** CompositePart *****/
128 /* geometry_handler */ NULL((void*)0),
129 /* change_managed */ NULL((void*)0),
130 /* insert_child */ CompositeInsertChild,
131 /* delete_child */ CompositeDeleteChild,
132 /* extension */ NULL((void*)0)
133 }
134};
135
136externaldef(compositewidgetclass) WidgetClass compositeWidgetClass = (WidgetClass) &compositeClassRec;
137
138static void InheritAllowsChangeManagedSet(
139 WidgetClass widget_class)
140{
141 CompositeWidgetClass cc = (CompositeWidgetClass) widget_class;
142 CompositeClassExtension ext, super_ext, new_ext;
143
144 ext = (CompositeClassExtension)
145 XtGetClassExtension(widget_class,
146 XtOffsetOf(CompositeClassRec, composite_class.extension)__builtin_offsetof(CompositeClassRec, composite_class.extension
)
,
147 NULLQUARK((XrmQuark) 0), 1L, 0);
148
149 if (ext && ext->version == XtCompositeExtensionVersion2L)
150 return;
151
152 super_ext = (CompositeClassExtension)
153 XtGetClassExtension(cc->core_class.superclass,
154 XtOffsetOf(CompositeClassRec, composite_class.extension)__builtin_offsetof(CompositeClassRec, composite_class.extension
)
,
155 NULLQUARK((XrmQuark) 0), 1L, 0);
156
157 LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)();
158 if (super_ext && super_ext->version == XtCompositeExtensionVersion2L &&
159 super_ext->record_size == sizeof(CompositeClassExtensionRec) &&
160 super_ext->allows_change_managed_set) {
161
162 new_ext = (CompositeClassExtension)
163 __XtCalloc(1, sizeof(CompositeClassExtensionRec));
164
165 /* Be careful to inherit only what is appropriate */
166 new_ext->next_extension = cc->composite_class.extension;
167 new_ext->record_type = NULLQUARK((XrmQuark) 0);
168 new_ext->version = XtCompositeExtensionVersion2L;
169 new_ext->record_size = sizeof(CompositeClassExtensionRec);
170 new_ext->accepts_objects = (ext ? ext->accepts_objects : False0);
171 new_ext->allows_change_managed_set = True1;
172 cc->composite_class.extension = (XtPointer) new_ext;
173 }
174 UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)();
175}
176
177static void CompositeClassPartInitialize(
178 WidgetClass widgetClass)
179{
180 register CompositePartPtr wcPtr;
181 register CompositePartPtr superPtr = NULL((void*)0);
182
183 wcPtr = (CompositePartPtr)
184 &(((CompositeWidgetClass)widgetClass)->composite_class);
185
186 if (widgetClass != compositeWidgetClass)
1
Taking false branch
187 /* don't compute possible bogus pointer */
188 superPtr = (CompositePartPtr)&(((CompositeWidgetClass)widgetClass
189 ->core_class.superclass)->composite_class);
190
191 /* We don't need to check for null super since we'll get to composite
192 eventually, and it had better define them! */
193
194 LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)();
2
Within the expansion of the macro 'LOCK_PROCESS':
a
Assuming '_XtProcessLock' is null
195 if (wcPtr->geometry_manager == XtInheritGeometryManager((XtGeometryHandler) _XtInherit)) {
3
Taking true branch
196 wcPtr->geometry_manager =
197 superPtr->geometry_manager;
4
Access to field 'geometry_manager' results in a dereference of a null pointer (loaded from variable 'superPtr')
198 }
199
200 if (wcPtr->change_managed == XtInheritChangeManaged((XtWidgetProc) _XtInherit)) {
201 wcPtr->change_managed =
202 superPtr->change_managed;
203 InheritAllowsChangeManagedSet(widgetClass);
204 }
205
206 if (wcPtr->insert_child == XtInheritInsertChild((XtWidgetProc) _XtInherit)) {
207 wcPtr->insert_child = superPtr->insert_child;
208 }
209
210 if (wcPtr->delete_child == XtInheritDeleteChild((XtWidgetProc) _XtInherit)) {
211 wcPtr->delete_child = superPtr->delete_child;
212 }
213 UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)();
214}
215
216static void CompositeDestroy(
217 Widget w)
218{
219 register CompositeWidget cw = (CompositeWidget) w;
220
221 XtFree((char *) cw->composite.children);
222}
223
224static void CompositeInsertChild(
225 Widget w)
226{
227 register Cardinal position;
228 register Cardinal i;
229 register CompositeWidget cw;
230 register WidgetList children;
231
232 cw = (CompositeWidget) w->core.parent;
233 children = cw->composite.children;
234
235 if (cw->composite.insert_position != NULL((void*)0))
236 position = (*(cw->composite.insert_position))(w);
237 else
238 position = cw->composite.num_children;
239
240 if (cw->composite.num_children == cw->composite.num_slots) {
241 /* Allocate more space */
242 cw->composite.num_slots += (cw->composite.num_slots / 2) + 2;
243 cw->composite.children = children =
244 (WidgetList) XtRealloc((XtPointer) children,
245 (unsigned) (cw->composite.num_slots) * sizeof(Widget));
246 }
247 /* Ripple children up one space from "position" */
248 for (i = cw->composite.num_children; i > position; i--) {
249 children[i] = children[i-1];
250 }
251 children[position] = w;
252 cw->composite.num_children++;
253}
254
255static void CompositeDeleteChild(
256 Widget w)
257{
258 register Cardinal position;
259 register Cardinal i;
260 register CompositeWidget cw;
261
262 cw = (CompositeWidget) w->core.parent;
263
264 for (position = 0; position < cw->composite.num_children; position++) {
265 if (cw->composite.children[position] == w) {
266 break;
267 }
268 }
269 if (position == cw->composite.num_children) return;
270
271 /* Ripple children down one space from "position" */
272 cw->composite.num_children--;
273 for (i = position; i < cw->composite.num_children; i++) {
274 cw->composite.children[i] = cw->composite.children[i+1];
275 }
276}
277
278/* ARGSUSED */
279static void CompositeInitialize(
280 Widget requested_widget,
281 Widget new_widget,
282 ArgList args,
283 Cardinal *num_args)
284{
285 register CompositeWidget cw;
286
287 cw = (CompositeWidget) new_widget;
288 cw->composite.num_children = 0;
289 cw->composite.children = NULL((void*)0);
290 cw->composite.num_slots = 0;
291}