Bug Summary

File:SetWMCW.c
Location:line 92, column 11
Description:Dereference of null pointer

Annotated Source Code

1/*
2 *
3 * Author: Chris D. Peterson, MIT X Consortium
4 */
5
6/************************************************************
7
8Copyright (c) 1993, Oracle and/or its affiliates. All rights reserved.
9
10Permission is hereby granted, free of charge, to any person obtaining a
11copy of this software and associated documentation files (the "Software"),
12to deal in the Software without restriction, including without limitation
13the rights to use, copy, modify, merge, publish, distribute, sublicense,
14and/or sell copies of the Software, and to permit persons to whom the
15Software is furnished to do so, subject to the following conditions:
16
17The above copyright notice and this permission notice (including the next
18paragraph) shall be included in all copies or substantial portions of the
19Software.
20
21THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27DEALINGS IN THE SOFTWARE.
28
29********************************************************/
30
31/*
32
33Copyright 1989, 1994, 1998 The Open Group
34
35Permission to use, copy, modify, distribute, and sell this software and its
36documentation for any purpose is hereby granted without fee, provided that
37the above copyright notice appear in all copies and that both that
38copyright notice and this permission notice appear in supporting
39documentation.
40
41The above copyright notice and this permission notice shall be included in
42all copies or substantial portions of the Software.
43
44THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
48AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
49CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
50
51Except as contained in this notice, the name of The Open Group shall not be
52used in advertising or otherwise to promote the sale, use or other dealings
53in this Software without prior written authorization from The Open Group.
54
55*/
56
57#ifdef HAVE_CONFIG_H1
58#include <config.h>
59#endif
60#include "IntrinsicI.h"
61#include <X11/Xatom.h>
62
63/* Function Name: XtSetWMColormapWindows
64 *
65 * Description: Sets the value of the WM_COLORMAP_WINDOWS
66 * property on a widget's window.
67 *
68 * Arguments: widget - specifies the widget on whose window the
69 * - WM_COLORMAP_WINDOWS property will be stored.
70 *
71 * list - Specifies a list of widgets whose windows are to be
72 * listed in the WM_COLORMAP_WINDOWS property.
73 * count - Specifies the number of widgets in list.
74 *
75 * Returns: none.
76 */
77
78void
79XtSetWMColormapWindows(
80 Widget widget,
81 Widget *list,
82 Cardinal count)
83{
84 Window *data;
85 Widget *checked, *top, *temp, hookobj;
86 Cardinal i, j, checked_count;
87 Boolean match;
88 Atom xa_wm_colormap_windows;
89 WIDGET_TO_APPCON(widget)XtAppContext app = (widget && _XtProcessLock ? XtWidgetToApplicationContext
(widget) : ((void*)0))
;
90
91 LOCK_APP(app)if(app && app->lock)(*app->lock)(app);
92 if ( !XtIsRealized(widget)((((((Object)(widget))->object.widget_class->core_class
.class_inited & 0x04) ? (widget) : _XtWindowedAncestor(widget
)) ->core.window) != 0L)
|| (count == 0) ) {
Within the expansion of the macro 'XtIsRealized':
a
Dereference of null pointer
93 UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app);
94 return;
95 }
96
97 top = checked = (Widget *) __XtMalloc( (Cardinal) sizeof(Widget) * count);
98
99
100/*
101 * The specification calls for only adding the windows that have unique
102 * colormaps to the property to this function, so we will make a pass through
103 * the widget list removing all the widgets with non-unique colormaps.
104 *
105 * We will also remove any unrealized widgets from the list at this time.
106 */
107
108 for (checked_count = 0, i = 0; i < count; i++) {
109 if (!XtIsRealized(list[i])((((((Object)(list[i]))->object.widget_class->core_class
.class_inited & 0x04) ? (list[i]) : _XtWindowedAncestor(list
[i])) ->core.window) != 0L)
) continue;
110
111 *checked = list[i];
112 match = FALSE0;
113
114/*
115 * Don't check first element for matching colormap since there is nothing
116 * to check it against.
117 */
118
119 if (checked != top)
120 for (j = 0, temp = top; j < checked_count ; j++, temp++)
121 if ( (*temp)->core.colormap == (*checked)->core.colormap) {
122 match = TRUE1;
123 break;
124 }
125
126/*
127 * If no colormap was found to match then add this widget to the linked list.
128 */
129
130 if (!match) {
131 checked++;
132 checked_count++;
133 }
134 }
135
136/*
137 * Now that we have the list of widgets we need to convert it to a list of
138 * windows and set the property.
139 */
140
141 data = (Window *) __XtMalloc( (Cardinal) sizeof(Window) * checked_count);
142
143 for ( i = 0 ; i < checked_count ; i++)
144 data[i] = XtWindow(top[i])((top[i])->core.window);
145
146 xa_wm_colormap_windows = XInternAtom(XtDisplay(widget)(((widget)->core.screen)->display),
147 "WM_COLORMAP_WINDOWS", FALSE0);
148
149 XChangeProperty(XtDisplay(widget)(((widget)->core.screen)->display), XtWindow(widget)((widget)->core.window),
150 xa_wm_colormap_windows, XA_WINDOW((Atom) 33), 32,
151 PropModeReplace0, (unsigned char *) data, (int) i);
152
153 hookobj = XtHooksOfDisplay(XtDisplay(widget)(((widget)->core.screen)->display));
154 if (XtHasCallbacks(hookobj, XtNchangeHook((char*)&XtStrings[2061])) == XtCallbackHasSome) {
155 XtChangeHookDataRec call_data;
156
157 call_data.type = XtHsetWMColormapWindows((char*)&XtStrings[2488]);
158 call_data.widget = widget;
159 call_data.event_data = (XtPointer) list;
160 call_data.num_event_data = count;
161 XtCallCallbackList(hookobj,
162 ((HookObject)hookobj)->hooks.changehook_callbacks,
163 (XtPointer)&call_data);
164 }
165
166 XtFree( (char *) data);
167 XtFree( (char *) top);
168 UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app);
169}