File: | xrefresh.c |
Location: | line 282, column 6 |
Description: | Null pointer argument in call to string comparison function |
1 | /*********************************************************** | |||
2 | ||||
3 | Copyright 1987, 1988, 1998 The Open Group | |||
4 | ||||
5 | Permission to use, copy, modify, distribute, and sell this software and its | |||
6 | documentation for any purpose is hereby granted without fee, provided that | |||
7 | the above copyright notice appear in all copies and that both that | |||
8 | copyright notice and this permission notice appear in supporting | |||
9 | documentation. | |||
10 | ||||
11 | The above copyright notice and this permission notice shall be included in | |||
12 | all copies or substantial portions of the Software. | |||
13 | ||||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
17 | OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | |||
18 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |||
19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
20 | ||||
21 | Except as contained in this notice, the name of The Open Group shall not be | |||
22 | used in advertising or otherwise to promote the sale, use or other dealings | |||
23 | in this Software without prior written authorization from The Open Group. | |||
24 | ||||
25 | ||||
26 | Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. | |||
27 | ||||
28 | All Rights Reserved | |||
29 | ||||
30 | Permission to use, copy, modify, and distribute this software and its | |||
31 | documentation for any purpose and without fee is hereby granted, | |||
32 | provided that the above copyright notice appear in all copies and that | |||
33 | both that copyright notice and this permission notice appear in | |||
34 | supporting documentation, and that the name of Digital not be | |||
35 | used in advertising or publicity pertaining to distribution of the | |||
36 | software without specific, written prior permission. | |||
37 | ||||
38 | DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING | |||
39 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL | |||
40 | DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR | |||
41 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |||
42 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |||
43 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |||
44 | SOFTWARE. | |||
45 | ||||
46 | ******************************************************************/ | |||
47 | ||||
48 | /* | |||
49 | * Kitchen sink version, useful for clearing small areas and flashing the | |||
50 | * screen. | |||
51 | */ | |||
52 | ||||
53 | #ifdef HAVE_CONFIG_H1 | |||
54 | # include "config.h" | |||
55 | #endif | |||
56 | ||||
57 | #include <stdio.h> | |||
58 | #include <errno(*__error()).h> | |||
59 | #include <X11/Xos.h> | |||
60 | #include <X11/Xlib.h> | |||
61 | #include <X11/Xutil.h> | |||
62 | #include <stdlib.h> | |||
63 | ||||
64 | #ifndef HAVE_STRCASECMP1 | |||
65 | # include <ctype.h> | |||
66 | #endif | |||
67 | ||||
68 | static Window win; | |||
69 | ||||
70 | static char *ProgramName; | |||
71 | ||||
72 | static void _X_NORETURN__attribute((noreturn)) _X_COLD__attribute__((__cold__)) | |||
73 | Syntax(void) | |||
74 | { | |||
75 | fprintf (stderr__stderrp, "usage: %s [-options] [geometry] [display]\n\n%s", | |||
76 | ProgramName, | |||
77 | "where the available options are:\n" | |||
78 | " -display host:dpy or -d\n" | |||
79 | " -geometry WxH+X+Y or -g spec\n" | |||
80 | " -black use BlackPixel\n" | |||
81 | " -white use WhitePixel\n" | |||
82 | " -solid colorname use the color indicated\n" | |||
83 | " -root use the root background\n" | |||
84 | " -none no background in window\n" | |||
85 | " -version print program version\n" | |||
86 | ); | |||
87 | fprintf (stderr__stderrp, "\nThe default is: %s -none\n\n", ProgramName); | |||
88 | exit (1); | |||
89 | } | |||
90 | ||||
91 | static void _X_NORETURN__attribute((noreturn)) _X_COLD__attribute__((__cold__)) | |||
92 | missing_arg(const char *arg) | |||
93 | { | |||
94 | fprintf (stderr__stderrp, "%s: %s requires an argument\n\n", ProgramName, arg); | |||
95 | Syntax (); | |||
96 | } | |||
97 | ||||
98 | static void _X_NORETURN__attribute((noreturn)) _X_COLD__attribute__((__cold__)) | |||
99 | unknown_arg(const char *arg) | |||
100 | { | |||
101 | fprintf (stderr__stderrp, "%s: unrecognized argument %s\n\n", ProgramName, arg); | |||
102 | Syntax (); | |||
103 | } | |||
104 | ||||
105 | /* | |||
106 | * The following parses options that should be yes or no; it returns -1, 0, 1 | |||
107 | * for error, no, yes. | |||
108 | */ | |||
109 | ||||
110 | static int | |||
111 | parse_boolean_option(char *option) | |||
112 | { | |||
113 | static const struct _booltable { | |||
114 | const char *name; | |||
115 | int value; | |||
116 | } booltable[] = { | |||
117 | { "off", 0 }, { "n", 0 }, { "no", 0 }, { "false", 0 }, | |||
118 | { "on", 1 }, { "y", 1 }, { "yes", 1 }, { "true", 1 }, | |||
119 | { NULL((void*)0), -1 }}; | |||
120 | register const struct _booltable *t; | |||
121 | ||||
122 | #ifndef HAVE_STRCASECMP1 | |||
123 | register char *cp; | |||
124 | ||||
125 | for (cp = option; *cp; cp++) { | |||
126 | if (isascii (*cp) && isupper (*cp)) *cp = tolower (*cp); | |||
127 | } | |||
128 | #endif | |||
129 | ||||
130 | for (t = booltable; t->name; t++) { | |||
131 | #ifdef HAVE_STRCASECMP1 | |||
132 | if (strcasecmp (option, t->name) == 0) return (t->value); | |||
133 | #else | |||
134 | if (strcmp (option, t->name) == 0) return (t->value); | |||
135 | #endif | |||
136 | } | |||
137 | return (-1); | |||
138 | } | |||
139 | ||||
140 | ||||
141 | /* | |||
142 | * The following is a hack until XrmParseCommand is ready. It determines | |||
143 | * whether or not the given string is an abbreviation of the arg. | |||
144 | */ | |||
145 | ||||
146 | static Boolint | |||
147 | isabbreviation(const char *arg, char *s, size_t minslen) | |||
148 | { | |||
149 | size_t arglen; | |||
150 | size_t slen; | |||
151 | ||||
152 | /* exact match */ | |||
153 | if (strcmp (arg, s) == 0) return (True1); | |||
154 | ||||
155 | arglen = strlen (arg); | |||
156 | slen = strlen (s); | |||
157 | ||||
158 | /* too long or too short */ | |||
159 | if (slen >= arglen || slen < minslen) return (False0); | |||
160 | ||||
161 | /* abbreviation */ | |||
162 | if (strncmp (arg, s, slen) == 0) return (True1); | |||
163 | ||||
164 | /* bad */ | |||
165 | return (False0); | |||
166 | } | |||
167 | ||||
168 | ||||
169 | enum e_action {doDefault, doBlack, doWhite, doSolid, doNone, doRoot}; | |||
170 | ||||
171 | static const struct s_pair { | |||
172 | const char *resource_name; | |||
173 | enum e_action action; | |||
174 | } pair_table[] = { | |||
175 | { "Black", doBlack }, | |||
176 | { "White", doWhite }, | |||
177 | { "None", doNone }, | |||
178 | { "Root", doRoot }, | |||
179 | { NULL((void*)0), doDefault }}; | |||
180 | ||||
181 | int | |||
182 | main(int argc, char *argv[]) | |||
183 | { | |||
184 | Visual visual; | |||
185 | XSetWindowAttributes xswa; | |||
186 | int i; | |||
187 | char *displayname = NULL((void*)0); | |||
188 | Display *dpy; | |||
189 | Colormap cmap; | |||
190 | enum e_action action = doDefault; | |||
191 | unsigned long mask; | |||
192 | int screen; | |||
193 | int x, y, width, height; | |||
194 | char *geom = NULL((void*)0); | |||
195 | int geom_result; | |||
196 | int display_width, display_height; | |||
197 | char *solidcolor = NULL((void*)0); | |||
| ||||
198 | XColor cdef; | |||
199 | ||||
200 | ProgramName = argv[0]; | |||
201 | ||||
202 | for (i = 1; i < argc; i++) { | |||
203 | char *arg = argv[i]; | |||
204 | ||||
205 | if (arg[0] == '-') { | |||
206 | if (isabbreviation ("-display", arg, 2)) { | |||
207 | if (++i >= argc) missing_arg (arg); | |||
208 | displayname = argv[i]; | |||
209 | continue; | |||
210 | } else if (isabbreviation ("-geometry", arg, 2)) { | |||
211 | if (++i >= argc) missing_arg (arg); | |||
212 | geom = argv[i]; | |||
213 | continue; | |||
214 | } else if (isabbreviation ("-black", arg, 2)) { | |||
215 | action = doBlack; | |||
216 | continue; | |||
217 | } else if (isabbreviation ("-white", arg, 2)) { | |||
218 | action = doWhite; | |||
219 | continue; | |||
220 | } else if (isabbreviation ("-solid", arg, 2)) { | |||
221 | if (++i >= argc) missing_arg (arg); | |||
222 | solidcolor = argv[i]; | |||
223 | action = doSolid; | |||
224 | continue; | |||
225 | } else if (isabbreviation ("-none", arg, 2)) { | |||
226 | action = doNone; | |||
227 | continue; | |||
228 | } else if (isabbreviation ("-root", arg, 2)) { | |||
229 | action = doRoot; | |||
230 | continue; | |||
231 | } else if (isabbreviation ("-version", arg, 1)) { | |||
232 | puts(PACKAGE_STRING"xrefresh 1.0.5"); | |||
233 | exit(0); | |||
234 | } else | |||
235 | unknown_arg (arg); | |||
236 | } else if (arg[0] == '=') /* obsolete */ | |||
237 | geom = arg; | |||
238 | else | |||
239 | unknown_arg (arg); | |||
240 | } | |||
241 | ||||
242 | if ((dpy = XOpenDisplay(displayname)) == NULL((void*)0)) { | |||
243 | fprintf (stderr__stderrp, "%s: unable to open display '%s'\n", | |||
244 | ProgramName, XDisplayName (displayname)); | |||
245 | exit (1); | |||
246 | } | |||
247 | ||||
248 | if (action == doDefault) { | |||
249 | char *def; | |||
250 | ||||
251 | if ((def = XGetDefault (dpy, ProgramName, "Solid")) != NULL((void*)0)) { | |||
252 | solidcolor = strdup (def); | |||
253 | if (solidcolor == NULL((void*)0)) { | |||
254 | fprintf (stderr__stderrp, | |||
255 | "%s: unable to allocate memory for string.\n", | |||
256 | ProgramName); | |||
257 | exit (1); | |||
258 | } | |||
259 | action = doSolid; | |||
260 | } else { | |||
261 | const struct s_pair *pp; | |||
262 | ||||
263 | for (pp = pair_table; pp->resource_name != NULL((void*)0); pp++) { | |||
264 | def = XGetDefault (dpy, ProgramName, pp->resource_name); | |||
265 | if (def && parse_boolean_option (def) == 1) { | |||
266 | action = pp->action; | |||
267 | } | |||
268 | } | |||
269 | } | |||
270 | } | |||
271 | ||||
272 | if (geom == NULL((void*)0)) geom = XGetDefault (dpy, ProgramName, "Geometry"); | |||
273 | ||||
274 | screen = DefaultScreen (dpy)(((_XPrivDisplay)(dpy))->default_screen); | |||
275 | display_width = DisplayWidth (dpy, screen)((&((_XPrivDisplay)(dpy))->screens[screen])->width); | |||
276 | display_height = DisplayHeight (dpy, screen)((&((_XPrivDisplay)(dpy))->screens[screen])->height ); | |||
277 | x = y = 0; | |||
278 | width = display_width; | |||
279 | height = display_height; | |||
280 | ||||
281 | if (DisplayCells (dpy, screen)(((&((_XPrivDisplay)(dpy))->screens[screen])->root_visual )->map_entries) <= 2 && action == doSolid) { | |||
282 | if (strcmp (solidcolor, "black") == 0) | |||
| ||||
283 | action = doBlack; | |||
284 | else if (strcmp (solidcolor, "white") == 0) | |||
285 | action = doWhite; | |||
286 | else { | |||
287 | fprintf (stderr__stderrp, | |||
288 | "%s: can't use colors on a monochrome display.\n", | |||
289 | ProgramName); | |||
290 | action = doNone; | |||
291 | } | |||
292 | } | |||
293 | ||||
294 | if (geom) | |||
295 | geom_result = XParseGeometry (geom, &x, &y, | |||
296 | (unsigned int *)&width, | |||
297 | (unsigned int *)&height); | |||
298 | else | |||
299 | geom_result = NoValue0x0000; | |||
300 | ||||
301 | /* | |||
302 | * For parsing geometry, we want to have the following | |||
303 | * | |||
304 | * = (0,0) for (display_width,display_height) | |||
305 | * =WxH+X+Y (X,Y) for (W,H) | |||
306 | * =WxH-X-Y (display_width-W-X,display_height-H-Y) for (W,H) | |||
307 | * =+X+Y (X,Y) for (display_width-X,display_height-Y) | |||
308 | * =WxH (0,0) for (W,H) | |||
309 | * =-X-Y (0,0) for (display_width-X,display_height-Y) | |||
310 | * | |||
311 | * If we let any missing values be taken from (0,0) for | |||
312 | * (display_width,display_height) we just have to deal with the | |||
313 | * negative offsets. | |||
314 | */ | |||
315 | ||||
316 | if (geom_result & XNegative0x0010) { | |||
317 | if (geom_result & WidthValue0x0004) { | |||
318 | x = display_width - width + x; | |||
319 | } else { | |||
320 | width = display_width + x; | |||
321 | x = 0; | |||
322 | } | |||
323 | } | |||
324 | if (geom_result & YNegative0x0020) { | |||
325 | if (geom_result & HeightValue0x0008) { | |||
326 | y = display_height - height + y; | |||
327 | } else { | |||
328 | height = display_height + y; | |||
329 | y = 0; | |||
330 | } | |||
331 | } | |||
332 | ||||
333 | mask = 0; | |||
334 | switch (action) { | |||
335 | case doBlack: | |||
336 | xswa.background_pixel = BlackPixel (dpy, screen)((&((_XPrivDisplay)(dpy))->screens[screen])->black_pixel ); | |||
337 | mask |= CWBackPixel(1L<<1); | |||
338 | break; | |||
339 | case doWhite: | |||
340 | xswa.background_pixel = WhitePixel (dpy, screen)((&((_XPrivDisplay)(dpy))->screens[screen])->white_pixel ); | |||
341 | mask |= CWBackPixel(1L<<1); | |||
342 | break; | |||
343 | case doSolid: | |||
344 | cmap = DefaultColormap (dpy, screen)((&((_XPrivDisplay)(dpy))->screens[screen])->cmap); | |||
345 | if (XParseColor (dpy, cmap, solidcolor, &cdef) && | |||
346 | XAllocColor (dpy, cmap, &cdef)) { | |||
347 | xswa.background_pixel = cdef.pixel; | |||
348 | mask |= CWBackPixel(1L<<1); | |||
349 | } else { | |||
350 | fprintf (stderr__stderrp,"%s: unable to allocate color '%s'.\n", | |||
351 | ProgramName, solidcolor); | |||
352 | xswa.background_pixmap = None0L; | |||
353 | mask |= CWBackPixmap(1L<<0); | |||
354 | } | |||
355 | break; | |||
356 | case doDefault: | |||
357 | case doNone: | |||
358 | xswa.background_pixmap = None0L; | |||
359 | mask |= CWBackPixmap(1L<<0); | |||
360 | break; | |||
361 | case doRoot: | |||
362 | xswa.background_pixmap = ParentRelative1L; | |||
363 | mask |= CWBackPixmap(1L<<0); | |||
364 | break; | |||
365 | } | |||
366 | xswa.override_redirect = True1; | |||
367 | xswa.backing_store = NotUseful0; | |||
368 | xswa.save_under = False0; | |||
369 | mask |= (CWOverrideRedirect(1L<<9) | CWBackingStore(1L<<6) | CWSaveUnder(1L<<10)); | |||
370 | visual.visualid = CopyFromParent0L; | |||
371 | win = XCreateWindow(dpy, DefaultRootWindow(dpy)((&((_XPrivDisplay)(dpy))->screens[(((_XPrivDisplay)(dpy ))->default_screen)])->root), x, y, width, height, | |||
372 | 0, DefaultDepth(dpy, screen)((&((_XPrivDisplay)(dpy))->screens[screen])->root_depth ), InputOutput1, &visual, mask, &xswa); | |||
373 | ||||
374 | /* | |||
375 | * at some point, we really ought to go walk the tree and turn off | |||
376 | * backing store; or do a ClearArea generating exposures on all windows | |||
377 | */ | |||
378 | XMapWindow (dpy, win); | |||
379 | /* the following will free the color that we might have allocated */ | |||
380 | XCloseDisplay (dpy); | |||
381 | exit (0); | |||
382 | } | |||
383 |