Bug Summary

File:src/WrBitF.c
Location:line 146, column 7
Description:Assigned value is garbage or undefined

Annotated Source Code

1/*
2
3Copyright 1987, 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
12in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of The Open Group shall
23not be used in advertising or otherwise to promote the sale, use or
24other dealings in this Software without prior written authorization
25from The Open Group.
26
27*/
28
29#ifdef HAVE_CONFIG_H1
30#include <config.h>
31#endif
32#include "Xlibint.h"
33#include <X11/Xos.h>
34#include "Xutil.h"
35#include <stdio.h>
36
37#define ERR_RETURN((void*)0) NULL((void*)0)
38
39static char *Format_Image(
40 XImage *image,
41 int *resultsize)
42{
43 register int x, c, b;
44 register char *ptr;
45 int y;
46 char *data;
47 int width, height;
48 int bytes_per_line;
49
50 width = image->width;
51 height = image->height;
52
53 bytes_per_line = (width+7)/8;
54 *resultsize = bytes_per_line * height; /* Calculate size of data */
55
56 data = Xmalloc( *resultsize )malloc(((*resultsize) == 0 ? 1 : (*resultsize))); /* Get space for data */
57 if (!data)
58 return(ERR_RETURN((void*)0));
59
60 /*
61 * The slow but robust brute force method of converting the image:
62 */
63 ptr = data;
64 c = 0; b=1;
65 for (y=0; y<height; y++) {
66 for (x=0; x<width;) {
67 if (XGetPixel(image, x, y)((*((image)->f.get_pixel))((image), (x), (y))))
68 c |= b;
69 b <<= 1;
70 if (!(++x & 7)) {
71 *(ptr++)=c;
72 c=0; b=1;
73 }
74 }
75 if (x & 7) {
76 *(ptr++)=c;
77 c=0; b=1;
78 }
79 }
80
81 return(data);
82}
83
84#define BYTES_PER_OUTPUT_LINE12 12
85
86int
87XWriteBitmapFile(
88 Display *display,
89 _Xconstconst char *filename,
90 Pixmap bitmap,
91 unsigned int width,
92 unsigned int height,
93 int x_hot,
94 int y_hot)
95{
96 char *data, *ptr;
97 int size, byte;
98 int c;
99 XImage *image;
100 FILE *stream;
101 char *name;
102
103 if (!(name = strrchr(filename, '/')))
1
Assuming 'name' is not null
2
Taking false branch
104 name = (char *)filename;
105 else
106 name++;
107
108#ifdef __UNIXOS2__
109 filename = (char*)__XOS2RedirRoot(filename);
110#endif
111 if (!(stream = fopen(filename, "w")))
3
Assuming 'stream' is not null
4
Taking false branch
112 return(BitmapOpenFailed1);
113
114 /* Convert bitmap to an image */
115 image = XGetImage(display, bitmap, 0,0,width, height, 1L, XYPixmap1);
116 if (!image) {
5
Assuming 'image' is non-null
6
Taking false branch
117 fclose(stream);
118 return(4); /* XXX spec does not say what to return */
119 }
120
121 /* Get standard format for data */
122 data = Format_Image(image, &size);
123 XDestroyImage(image)((*((image)->f.destroy_image))((image)));
124 if (!data) {
7
Taking false branch
125 fclose(stream);
126 return(BitmapNoMemory3);
127 }
128
129 /* Write out standard header */
130 fprintf(stream, "#define %s_width %d\n", name, width);
131 fprintf(stream, "#define %s_height %d\n", name, height);
132 if (x_hot != -1) {
8
Taking false branch
133 fprintf(stream, "#define %s_x_hot %d\n", name, x_hot);
134 fprintf(stream, "#define %s_y_hot %d\n", name, y_hot);
135 }
136
137 /* Print out the data itself */
138 fprintf(stream, "static unsigned char %s_bits[] = {", name);
139 for (byte=0, ptr=data; byte<size; byte++, ptr++) {
9
Assuming 'byte' is < 'size'
10
Loop condition is true. Entering loop body
140 if (!byte)
11
Taking true branch
141 fprintf(stream, "\n ");
142 else if (!(byte % BYTES_PER_OUTPUT_LINE12))
143 fprintf(stream, ",\n ");
144 else
145 fprintf(stream, ", ");
146 c = *ptr;
12
Assigned value is garbage or undefined
147 if (c<0)
148 c += 256;
149 fprintf(stream, "0x%02x", c);
150 }
151 fprintf(stream, "};\n");
152
153 Xfree(data)free((data));
154 fclose(stream);
155 return(BitmapSuccess0);
156}