| File: | src/VarGet.c |
| Location: | line 269, column 23 |
| Description: | Dereference of null pointer |
| 1 | /* | |||
| 2 | ||||
| 3 | Copyright (c) 1993, Oracle and/or its affiliates. All rights reserved. | |||
| 4 | ||||
| 5 | Permission is hereby granted, free of charge, to any person obtaining a | |||
| 6 | copy of this software and associated documentation files (the "Software"), | |||
| 7 | to deal in the Software without restriction, including without limitation | |||
| 8 | the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||
| 9 | and/or sell copies of the Software, and to permit persons to whom the | |||
| 10 | Software is furnished to do so, subject to the following conditions: | |||
| 11 | ||||
| 12 | The above copyright notice and this permission notice (including the next | |||
| 13 | paragraph) shall be included in all copies or substantial portions of the | |||
| 14 | Software. | |||
| 15 | ||||
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
| 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |||
| 19 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
| 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |||
| 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
| 22 | DEALINGS IN THE SOFTWARE. | |||
| 23 | ||||
| 24 | */ | |||
| 25 | ||||
| 26 | /* | |||
| 27 | ||||
| 28 | Copyright 1985, 1986, 1987, 1988, 1989, 1998 The Open Group | |||
| 29 | ||||
| 30 | Permission to use, copy, modify, distribute, and sell this software and its | |||
| 31 | documentation for any purpose is hereby granted without fee, provided that | |||
| 32 | the above copyright notice appear in all copies and that both that | |||
| 33 | copyright notice and this permission notice appear in supporting | |||
| 34 | documentation. | |||
| 35 | ||||
| 36 | The above copyright notice and this permission notice shall be included in | |||
| 37 | all copies or substantial portions of the Software. | |||
| 38 | ||||
| 39 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
| 40 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
| 41 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
| 42 | OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | |||
| 43 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |||
| 44 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
| 45 | ||||
| 46 | Except as contained in this notice, the name of The Open Group shall not be | |||
| 47 | used in advertising or otherwise to promote the sale, use or other dealings | |||
| 48 | in this Software without prior written authorization from The Open Group. | |||
| 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 | /* note we presume that the XtResourceList to be un-compiled */ | |||
| 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); /* for lint; really unused */ | |||
| 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); | |||
| 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; | |||
| ||||
| 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 | } |