Bug Summary

File:Hooks.c
Location:line 56, column 18
Description:Access to field 'block_hook_list' results in a dereference of a null pointer (loaded from variable 'app')

Annotated Source Code

1/*
2
3Copyright 1994, 1998 The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24
25*/
26
27/*LINTLIBRARY*/
28
29#ifdef HAVE_CONFIG_H1
30#include <config.h>
31#endif
32#include "IntrinsicI.h"
33#include "CreateI.h"
34
35static void FreeBlockHookList(
36 Widget widget, /* unused (and invalid) */
37 XtPointer closure, /* ActionHook* */
38 XtPointer call_data) /* unused */
39{
40 BlockHook list = *(BlockHook*)closure;
41 while (list != NULL((void*)0)) {
42 BlockHook next = list->next;
43 XtFree( (XtPointer)list );
44 list = next;
45 }
46}
47
48
49XtBlockHookId XtAppAddBlockHook(
50 XtAppContext app,
51 XtBlockHookProc proc,
52 XtPointer closure)
53{
54 BlockHook hook = XtNew(BlockHookRec)((BlockHookRec *) XtMalloc((unsigned) sizeof(BlockHookRec)));
55 LOCK_APP(app)if(app && app->lock)(*app->lock)(app);
56 hook->next = app->block_hook_list;
Access to field 'block_hook_list' results in a dereference of a null pointer (loaded from variable 'app')
57 hook->app = app;
58 hook->proc = proc;
59 hook->closure = closure;
60 if (app->block_hook_list == NULL((void*)0)) {
61 _XtAddCallback( &app->destroy_callbacks,
62 FreeBlockHookList,
63 (XtPointer)&app->block_hook_list
64 );
65 }
66 app->block_hook_list = hook;
67 UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app);
68 return (XtBlockHookId)hook;
69}
70
71
72void XtRemoveBlockHook(
73 XtBlockHookId id)
74{
75 BlockHook *p, hook = (BlockHook)id;
76 XtAppContext app = hook->app;
77 LOCK_APP(app)if(app && app->lock)(*app->lock)(app);
78 for (p = &app->block_hook_list; p != NULL((void*)0) && *p != hook; p = &(*p)->next);
79 if (p == NULL((void*)0)) {
80#ifdef DEBUG
81 XtAppWarningMsg(app, "badId", "xtRemoveBlockHook", XtCXtToolkitError,
82 "XtRemoveBlockHook called with bad or old hook id",
83 (String*)NULL((void*)0), (Cardinal*)NULL((void*)0));
84#endif /*DEBUG*/
85 UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app);
86 return;
87 }
88 *p = hook->next;
89 XtFree( (XtPointer)hook );
90 UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app);
91}
92
93static void DeleteShellFromHookObj(
94 Widget shell,
95 XtPointer closure,
96 XtPointer call_data)
97{
98 /* app_con is locked when this function is called */
99 Cardinal ii, jj;
100 HookObject ho = (HookObject) closure;
101
102 for (ii = 0; ii < ho->hooks.num_shells; ii++)
103 if (ho->hooks.shells[ii] == shell) {
104 /* collapse the list */
105 for (jj = ii; jj < ho->hooks.num_shells; jj++) {
106 if ((jj+1) < ho->hooks.num_shells)
107 ho->hooks.shells[jj] = ho->hooks.shells[jj+1];
108 }
109 break;
110 }
111 ho->hooks.num_shells--;
112}
113
114#define SHELL_INCR4 4
115
116void _XtAddShellToHookObj(
117 Widget shell)
118{
119 /* app_con is locked when this function is called */
120 HookObject ho = (HookObject) XtHooksOfDisplay(XtDisplay(shell)(((shell)->core.screen)->display));
121
122 if (ho->hooks.num_shells == ho->hooks.max_shells) {
123 ho->hooks.max_shells += SHELL_INCR4;
124 ho->hooks.shells =
125 (WidgetList)XtRealloc((char*)ho->hooks.shells,
126 ho->hooks.max_shells * sizeof (Widget));
127 }
128 ho->hooks.shells[ho->hooks.num_shells++] = shell;
129
130 XtAddCallback(shell, XtNdestroyCallback((char*)&XtStrings[169]), DeleteShellFromHookObj,
131 (XtPointer)ho);
132}
133
134Boolean _XtIsHookObject(
135 Widget widget)
136{
137 return (widget->core.widget_class == hookObjectClass);
138}
139
140Widget XtHooksOfDisplay(
141 Display* dpy)
142{
143 Widget retval;
144 XtPerDisplay pd;
145 DPY_TO_APPCON(dpy)XtAppContext app = (_XtProcessLock ? XtDisplayToApplicationContext
(dpy): ((void*)0))
;
146
147 LOCK_APP(app)if(app && app->lock)(*app->lock)(app);
148 pd = _XtGetPerDisplay(dpy);
149 if (pd->hook_object == NULL((void*)0))
150 pd->hook_object =
151 _XtCreateHookObj((Screen*)DefaultScreenOfDisplay(dpy)(&((_XPrivDisplay)dpy)->screens[(((_XPrivDisplay)dpy)->
default_screen)])
);
152 retval = pd->hook_object;
153 UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app);
154 return retval;
155}