Bug Summary

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

Annotated Source Code

1/*LINTLIBRARY*/
2
3/***********************************************************
4Copyright (c) 1993, Oracle and/or its affiliates. All rights reserved.
5
6Permission is hereby granted, free of charge, to any person obtaining a
7copy of this software and associated documentation files (the "Software"),
8to deal in the Software without restriction, including without limitation
9the rights to use, copy, modify, merge, publish, distribute, sublicense,
10and/or sell copies of the Software, and to permit persons to whom the
11Software is furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice (including the next
14paragraph) shall be included in all copies or substantial portions of the
15Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23DEALINGS IN THE SOFTWARE.
24
25Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
26
27 All Rights Reserved
28
29Permission to use, copy, modify, and distribute this software and its
30documentation for any purpose and without fee is hereby granted,
31provided that the above copyright notice appear in all copies and that
32both that copyright notice and this permission notice appear in
33supporting documentation, and that the name of Digital not be
34used in advertising or publicity pertaining to distribution of the
35software without specific, written prior permission.
36
37DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43SOFTWARE.
44
45******************************************************************/
46
47/*
48
49Copyright 1987, 1988, 1998 The Open Group
50
51Permission to use, copy, modify, distribute, and sell this software and its
52documentation for any purpose is hereby granted without fee, provided that
53the above copyright notice appear in all copies and that both that
54copyright notice and this permission notice appear in supporting
55documentation.
56
57The above copyright notice and this permission notice shall be included in
58all copies or substantial portions of the Software.
59
60THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
61IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
62FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
63OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
64AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
65CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
66
67Except as contained in this notice, the name of The Open Group shall not be
68used in advertising or otherwise to promote the sale, use or other dealings
69in this Software without prior written authorization from The Open Group.
70
71*/
72
73/*
74 * Contains XtAppAddActionHook, XtRemoveActionHook
75 */
76
77#ifdef HAVE_CONFIG_H1
78#include <config.h>
79#endif
80#include "IntrinsicI.h"
81
82
83/*ARGSUSED*/
84static void FreeActionHookList(
85 Widget widget, /* unused (and invalid) */
86 XtPointer closure, /* ActionHook* */
87 XtPointer call_data) /* unused */
88{
89 ActionHook list = *(ActionHook*)closure;
90 while (list != NULL((void*)0)) {
91 ActionHook next = list->next;
92 XtFree( (XtPointer)list );
93 list = next;
94 }
95}
96
97
98XtActionHookId XtAppAddActionHook(
99 XtAppContext app,
100 XtActionHookProc proc,
101 XtPointer closure)
102{
103 ActionHook hook = XtNew(ActionHookRec)((ActionHookRec *) XtMalloc((unsigned) sizeof(ActionHookRec))
)
;
104 LOCK_APP(app)if(app && app->lock)(*app->lock)(app);
105 hook->next = app->action_hook_list;
Access to field 'action_hook_list' results in a dereference of a null pointer (loaded from variable 'app')
106 hook->app = app;
107 hook->proc = proc;
108 hook->closure = closure;
109 if (app->action_hook_list == NULL((void*)0)) {
110 _XtAddCallback( &app->destroy_callbacks,
111 FreeActionHookList,
112 (XtPointer)&app->action_hook_list
113 );
114 }
115 app->action_hook_list = hook;
116 UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app);
117 return (XtActionHookId)hook;
118}
119
120
121void XtRemoveActionHook(
122 XtActionHookId id)
123{
124 ActionHook *p, hook = (ActionHook)id;
125 XtAppContext app = hook->app;
126 LOCK_APP(app)if(app && app->lock)(*app->lock)(app);
127 for (p = &app->action_hook_list; p != NULL((void*)0) && *p != hook; p = &(*p)->next);
128 if (p) {
129 *p = hook->next;
130 XtFree( (XtPointer)hook );
131 if (app->action_hook_list == NULL((void*)0))
132 _XtRemoveCallback(&app->destroy_callbacks, FreeActionHookList,
133 (XtPointer) &app->action_hook_list);
134 }
135#ifdef DEBUG
136 else {
137 XtAppWarningMsg(app, "badId", "xtRemoveActionHook", XtCXtToolkitError,
138 "XtRemoveActionHook called with bad or old hook id",
139 (String*)NULL((void*)0), (Cardinal*)NULL((void*)0));
140 }
141#endif /*DEBUG*/
142 UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app);
143}