Bug Summary

File:src/PolyTxt16.c
Location:line 192, column 7
Description:Value stored to 'FirstTimeThrough' is never read

Annotated Source Code

1/*
2
3Copyright 1986, 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#ifdef HAVE_CONFIG_H1
28#include <config.h>
29#endif
30#include "Xlibint.h"
31
32int
33XDrawText16(
34 register Display *dpy,
35 Drawable d,
36 GC gc,
37 int x,
38 int y,
39 XTextItem16 *items,
40 int nitems)
41{
42 register int i;
43 register XTextItem16 *item;
44 int length = 0;
45 register xPolyText16Req *req;
46
47 LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display
)(dpy)
;
48 FlushGC(dpy, gc)if ((gc)->dirty) _XFlushGCCache((dpy), (gc));
49 GetReq (PolyText16, req)req = (xPolyText16Req *) _XGetRequest(dpy, 75, 16);
50 req->drawable = d;
51 req->gc = gc->gid;
52 req->x = x;
53 req->y = y;
54
55 item = items;
56 for (i=0; i < nitems; i++) {
57 if (item->font)
58 length += 5; /* a 255 byte, plus size of Font id */
59 if (item->delta)
60 {
61 if (item->delta > 0)
62 {
63 length += SIZEOF(xTextElt)2 * ((item->delta + 126) / 127);
64 }
65 else
66 {
67 length += SIZEOF(xTextElt)2 * ((-item->delta + 127) / 128);
68 }
69 }
70 if (item->nchars > 0)
71 {
72 length += SIZEOF(xTextElt)2 * ((item->nchars + 253) / 254 - 1);
73 if (!item->delta) length += SIZEOF(xTextElt)2;
74 length += item->nchars << 1;
75 }
76 item++;
77 }
78
79 req->length += (length + 3)>>2; /* convert to number of 32-bit words */
80
81
82 /*
83 * If the entire request does not fit into the remaining space in the
84 * buffer, flush the buffer first. If the request does fit into the
85 * empty buffer, then we won't have to flush it at the end to keep
86 * the buffer 32-bit aligned.
87 */
88
89 if (dpy->bufptr + length > dpy->bufmax)
90 _XFlush (dpy);
91
92 item = items;
93 for (i=0; i< nitems; i++) {
94
95 if (item->font) {
96 /* to mark a font shift, write a 255 byte followed by
97 the 4 bytes of font ID, big-end first */
98 register unsigned char *f;
99 BufAlloc (unsigned char *, f, 5)if (dpy->bufptr + (5) > dpy->bufmax) _XFlush (dpy); f
= (unsigned char *) dpy->bufptr; memset(f, '\0', 5); dpy->
bufptr += (5);
;
100
101 f[0] = 255;
102 f[1] = (item->font & 0xff000000) >> 24;
103 f[2] = (item->font & 0x00ff0000) >> 16;
104 f[3] = (item->font & 0x0000ff00) >> 8;
105 f[4] = item->font & 0x000000ff;
106
107 /* update GC shadow */
108 gc->values.font = item->font;
109 }
110
111 {
112 int nbytes = SIZEOF(xTextElt)2;
113 int PartialNChars = item->nchars;
114 int PartialDelta = item->delta;
115 register xTextElt *elt = NULL((void*)0);
116 int FirstTimeThrough = True1;
117 XChar2b *CharacterOffset = item->chars;
118
119 while((PartialDelta < -128) || (PartialDelta > 127))
120 {
121 int nb = SIZEOF(xTextElt)2;
122
123 BufAlloc (xTextElt *, elt, nb)if (dpy->bufptr + (nb) > dpy->bufmax) _XFlush (dpy);
elt = (xTextElt *) dpy->bufptr; memset(elt, '\0', nb); dpy
->bufptr += (nb);
;
124 elt->len = 0;
125 if (PartialDelta > 0 )
126 {
127 elt->delta = 127;
128 PartialDelta = PartialDelta - 127;
129 }
130 else
131 {
132 elt->delta = -128;
133 PartialDelta = PartialDelta + 128;
134 }
135 }
136 if (PartialDelta)
137 {
138 BufAlloc (xTextElt *, elt, nbytes)if (dpy->bufptr + (nbytes) > dpy->bufmax) _XFlush (dpy
); elt = (xTextElt *) dpy->bufptr; memset(elt, '\0', nbytes
); dpy->bufptr += (nbytes);
;
139 elt->len = 0;
140 elt->delta = PartialDelta;
141 }
142 while(PartialNChars > 254)
143 {
144 nbytes = 254 * 2;
145 if (FirstTimeThrough)
146 {
147 FirstTimeThrough = False0;
148 if (!item->delta)
149 {
150 nbytes += SIZEOF(xTextElt)2;
151 BufAlloc (xTextElt *, elt, nbytes)if (dpy->bufptr + (nbytes) > dpy->bufmax) _XFlush (dpy
); elt = (xTextElt *) dpy->bufptr; memset(elt, '\0', nbytes
); dpy->bufptr += (nbytes);
;
152 elt->delta = 0;
153 }
154 else
155 {
156 char *DummyChar;
157 BufAlloc(char *, DummyChar, nbytes)if (dpy->bufptr + (nbytes) > dpy->bufmax) _XFlush (dpy
); DummyChar = (char *) dpy->bufptr; memset(DummyChar, '\0'
, nbytes); dpy->bufptr += (nbytes);
;
158#ifdef lint
159 DummyChar = DummyChar;
160#endif
161 }
162 }
163 else
164 {
165 nbytes += SIZEOF(xTextElt)2;
166 BufAlloc (xTextElt *, elt, nbytes)if (dpy->bufptr + (nbytes) > dpy->bufmax) _XFlush (dpy
); elt = (xTextElt *) dpy->bufptr; memset(elt, '\0', nbytes
); dpy->bufptr += (nbytes);
;
167 elt->delta = 0;
168 }
169 elt->len = 254;
170
171#if defined(MUSTCOPY) || defined(MUSTCOPY2B)
172 {
173 register int i;
174 register unsigned char *cp;
175 for (i = 0, cp = ((unsigned char *)elt) + 2; i < 254; i++) {
176 *cp++ = CharacterOffset[i].byte1;
177 *cp++ = CharacterOffset[i].byte2;
178 }
179 }
180#else
181 memcpy ((char *) (elt + 1), (char *)CharacterOffset, 254 * 2);
182#endif
183 PartialNChars = PartialNChars - 254;
184 CharacterOffset += 254;
185
186 }
187 if (PartialNChars)
188 {
189 nbytes = PartialNChars * 2;
190 if (FirstTimeThrough)
191 {
192 FirstTimeThrough = False0;
Value stored to 'FirstTimeThrough' is never read
193 if (!item->delta)
194 {
195 nbytes += SIZEOF(xTextElt)2;
196 BufAlloc (xTextElt *, elt, nbytes)if (dpy->bufptr + (nbytes) > dpy->bufmax) _XFlush (dpy
); elt = (xTextElt *) dpy->bufptr; memset(elt, '\0', nbytes
); dpy->bufptr += (nbytes);
;
197 elt->delta = 0;
198 }
199 else
200 {
201 char *DummyChar;
202 BufAlloc(char *, DummyChar, nbytes)if (dpy->bufptr + (nbytes) > dpy->bufmax) _XFlush (dpy
); DummyChar = (char *) dpy->bufptr; memset(DummyChar, '\0'
, nbytes); dpy->bufptr += (nbytes);
;
203#ifdef lint
204 DummyChar = DummyChar;
205#endif
206 }
207 }
208 else
209 {
210 nbytes += SIZEOF(xTextElt)2;
211 BufAlloc (xTextElt *, elt, nbytes)if (dpy->bufptr + (nbytes) > dpy->bufmax) _XFlush (dpy
); elt = (xTextElt *) dpy->bufptr; memset(elt, '\0', nbytes
); dpy->bufptr += (nbytes);
;
212 elt->delta = 0;
213 }
214 elt->len = PartialNChars;
215
216#if defined(MUSTCOPY) || defined(MUSTCOPY2B)
217 {
218 register int i;
219 register unsigned char *cp;
220 for (i = 0, cp = ((unsigned char *)elt) + 2; i < PartialNChars;
221 i++) {
222 *cp++ = CharacterOffset[i].byte1;
223 *cp++ = CharacterOffset[i].byte2;
224 }
225 }
226#else
227 memcpy ((char *) (elt + 1), (char *)CharacterOffset,
228 PartialNChars *
2292);
230#endif
231 }
232 }
233 item++;
234 }
235
236 /* Pad request out to a 32-bit boundary */
237
238 if (length &= 3) {
239 char *pad;
240 /*
241 * BufAlloc is a macro that uses its last argument more than
242 * once, otherwise I'd write "BufAlloc (char *, pad, 4-length)"
243 */
244 length = 4 - length;
245 BufAlloc (char *, pad, length)if (dpy->bufptr + (length) > dpy->bufmax) _XFlush (dpy
); pad = (char *) dpy->bufptr; memset(pad, '\0', length); dpy
->bufptr += (length);
;
246 /*
247 * if there are 3 bytes of padding, the first byte MUST be 0
248 * so the pad bytes aren't mistaken for a final xTextElt
249 */
250 *pad = 0;
251 }
252
253 /*
254 * If the buffer pointer is not now pointing to a 32-bit boundary,
255 * we must flush the buffer so that it does point to a 32-bit boundary
256 * at the end of this routine.
257 */
258
259 if ((dpy->bufptr - dpy->buffer) & 3)
260 _XFlush (dpy);
261
262 UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display
)(dpy)
;
263 SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy);
264 return 1;
265 }
266
267
268