File: | src/xkb/XKBList.c |
Location: | line 175, column 3 |
Description: | Value stored to 'str' is never read |
1 | /************************************************************ |
2 | Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc. |
3 | |
4 | Permission to use, copy, modify, and distribute this |
5 | software and its documentation for any purpose and without |
6 | fee is hereby granted, provided that the above copyright |
7 | notice appear in all copies and that both that copyright |
8 | notice and this permission notice appear in supporting |
9 | documentation, and that the name of Silicon Graphics not be |
10 | used in advertising or publicity pertaining to distribution |
11 | of the software without specific prior written permission. |
12 | Silicon Graphics makes no representation about the suitability |
13 | of this software for any purpose. It is provided "as is" |
14 | without any express or implied warranty. |
15 | |
16 | SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS |
17 | SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
18 | AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON |
19 | GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
20 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
21 | DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE |
22 | OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH |
23 | THE USE OR PERFORMANCE OF THIS SOFTWARE. |
24 | |
25 | ********************************************************/ |
26 | |
27 | #define NEED_MAP_READERS |
28 | #ifdef HAVE_CONFIG_H1 |
29 | #include <config.h> |
30 | #endif |
31 | #include "Xlibint.h" |
32 | #include <X11/extensions/XKBproto.h> |
33 | #include "XKBlibint.h" |
34 | |
35 | /***====================================================================***/ |
36 | |
37 | static void |
38 | _FreeComponentNames(int num,XkbComponentNamePtr names) |
39 | { |
40 | int i; |
41 | XkbComponentNamePtr tmp; |
42 | |
43 | if ((num<1)||(names==NULL((void*)0))) |
44 | return; |
45 | for (i=0,tmp=names;i<num;i++,tmp++) { |
46 | if (tmp->name) { |
47 | _XkbFree(tmp->name)free((tmp->name)); |
48 | tmp->name= NULL((void*)0); |
49 | } |
50 | } |
51 | _XkbFree(names)free((names)); |
52 | return; |
53 | } |
54 | |
55 | /***====================================================================***/ |
56 | |
57 | static XkbComponentNamePtr |
58 | _ReadListing(XkbReadBufferPtr buf,int count,Statusint *status_rtrn) |
59 | { |
60 | XkbComponentNamePtr first,this; |
61 | register int i; |
62 | CARD16 * flags; |
63 | int slen,wlen; |
64 | char * str; |
65 | |
66 | if (count<1) |
67 | return NULL((void*)0); |
68 | first= _XkbTypedCalloc(count,XkbComponentNameRec)((XkbComponentNameRec *)calloc((((count)) == 0 ? 1 : ((count) )), (sizeof(XkbComponentNameRec)))); |
69 | if (!first) |
70 | return NULL((void*)0); |
71 | for (this=first,i=0;i<count;i++,this++) { |
72 | flags= (CARD16 *)_XkbGetReadBufferPtr(buf,2*sizeof(CARD16)); |
73 | if (!flags) |
74 | goto BAILOUT; |
75 | this->flags= flags[0]; |
76 | slen= flags[1]; |
77 | wlen= ((slen+1)/2)*2; /* pad to 2 byte boundary */ |
78 | this->name= _XkbTypedCalloc(slen+1,char)((char *)calloc((((slen+1)) == 0 ? 1 : ((slen+1))), (sizeof(char )))); |
79 | if (!this->name) |
80 | goto BAILOUT; |
81 | str= (char *)_XkbGetReadBufferPtr(buf,wlen); |
82 | if (!str) |
83 | goto BAILOUT; |
84 | memcpy(this->name,str,slen); |
85 | } |
86 | return first; |
87 | BAILOUT: |
88 | *status_rtrn= BadAlloc11; |
89 | _FreeComponentNames(i,first); |
90 | return NULL((void*)0); |
91 | } |
92 | |
93 | /***====================================================================***/ |
94 | |
95 | XkbComponentListPtr |
96 | XkbListComponents( Display * dpy, |
97 | unsigned deviceSpec, |
98 | XkbComponentNamesPtr ptrns, |
99 | int * max_inout) |
100 | { |
101 | register xkbListComponentsReq* req; |
102 | xkbListComponentsReply rep; |
103 | XkbInfoPtr xkbi; |
104 | XkbComponentListPtr list; |
105 | XkbReadBufferRec buf; |
106 | int left; |
107 | char * str; |
108 | int extraLen,len,mapLen,codesLen,typesLen,compatLen,symsLen,geomLen; |
109 | |
110 | if ( (dpy==NULL((void*)0)) || (dpy->flags & XlibDisplayNoXkb(1L << 2)) || |
111 | (!dpy->xkb_info && !XkbUseExtension(dpy,NULL((void*)0),NULL((void*)0))) || |
112 | (ptrns==NULL((void*)0)) || (max_inout==NULL((void*)0))) |
113 | return NULL((void*)0); |
114 | |
115 | xkbi= dpy->xkb_info; |
116 | LockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->lock_display )(dpy); |
117 | GetReq(kbListComponents, req)req = (xkbListComponentsReq *) _XGetRequest(dpy, 22, 8); |
118 | req->reqType = xkbi->codes->major_opcode; |
119 | req->xkbReqType = X_kbListComponents22; |
120 | req->deviceSpec = deviceSpec; |
121 | req->maxNames = *max_inout; |
122 | |
123 | mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0; |
124 | if (ptrns->keymap) |
125 | mapLen= (int)strlen(ptrns->keymap); |
126 | if (ptrns->keycodes) |
127 | codesLen= (int)strlen(ptrns->keycodes); |
128 | if (ptrns->types) |
129 | typesLen= (int)strlen(ptrns->types); |
130 | if (ptrns->compat) |
131 | compatLen= (int)strlen(ptrns->compat); |
132 | if (ptrns->symbols) |
133 | symsLen= (int)strlen(ptrns->symbols); |
134 | if (ptrns->geometry) |
135 | geomLen= (int)strlen(ptrns->geometry); |
136 | if (mapLen>255) mapLen= 255; |
137 | if (codesLen>255) codesLen= 255; |
138 | if (typesLen>255) typesLen= 255; |
139 | if (compatLen>255) compatLen= 255; |
140 | if (symsLen>255) symsLen= 255; |
141 | if (geomLen>255) geomLen= 255; |
142 | |
143 | len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6; |
144 | len= XkbPaddedSize(len)((((unsigned int)(len)+3) >> 2) << 2); |
145 | req->length+= len/4; |
146 | BufAlloc(char *,str,len)if (dpy->bufptr + (len) > dpy->bufmax) _XFlush (dpy) ; str = (char *) dpy->bufptr; memset(str, '\0', len); dpy-> bufptr += (len);; |
147 | *str++= mapLen; |
148 | if (mapLen>0) { |
149 | memcpy(str,ptrns->keymap,mapLen); |
150 | str+= mapLen; |
151 | } |
152 | *str++= codesLen; |
153 | if (codesLen>0) { |
154 | memcpy(str,ptrns->keycodes,codesLen); |
155 | str+= codesLen; |
156 | } |
157 | *str++= typesLen; |
158 | if (typesLen>0) { |
159 | memcpy(str,ptrns->types,typesLen); |
160 | str+= typesLen; |
161 | } |
162 | *str++= compatLen; |
163 | if (compatLen>0) { |
164 | memcpy(str,ptrns->compat,compatLen); |
165 | str+= compatLen; |
166 | } |
167 | *str++= symsLen; |
168 | if (symsLen>0) { |
169 | memcpy(str,ptrns->symbols,symsLen); |
170 | str+= symsLen; |
171 | } |
172 | *str++= geomLen; |
173 | if (geomLen>0) { |
174 | memcpy(str,ptrns->geometry,geomLen); |
175 | str+= geomLen; |
Value stored to 'str' is never read | |
176 | } |
177 | if (!_XReply(dpy, (xReply *)&rep, 0, xFalse0)) |
178 | goto BAILOUT; |
179 | extraLen= (int)rep.length*4; |
180 | *max_inout= rep.extra; |
181 | if (extraLen==0) { /* no matches, but we don't want to report a failure */ |
182 | list= _XkbTypedCalloc(1,XkbComponentListRec)((XkbComponentListRec *)calloc((((1)) == 0 ? 1 : ((1))), (sizeof (XkbComponentListRec)))); |
183 | UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display )(dpy); |
184 | SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy); |
185 | return list; |
186 | } |
187 | if (_XkbInitReadBuffer(dpy,&buf,extraLen)) { |
188 | Statusint status; |
189 | |
190 | status= Success0; |
191 | list= _XkbTypedCalloc(1,XkbComponentListRec)((XkbComponentListRec *)calloc((((1)) == 0 ? 1 : ((1))), (sizeof (XkbComponentListRec)))); |
192 | if (!list) { |
193 | _XkbFreeReadBuffer(&buf); |
194 | goto BAILOUT; |
195 | } |
196 | list->num_keymaps= rep.nKeymaps; |
197 | list->num_keycodes= rep.nKeycodes; |
198 | list->num_types= rep.nTypes; |
199 | list->num_compat= rep.nCompatMaps; |
200 | list->num_symbols= rep.nSymbols; |
201 | list->num_geometry= rep.nGeometries; |
202 | if ((status==Success0)&&(list->num_keymaps>0)) |
203 | list->keymaps= _ReadListing(&buf,list->num_keymaps,&status); |
204 | if ((status==Success0)&&(list->num_keycodes>0)) |
205 | list->keycodes= _ReadListing(&buf,list->num_keycodes,&status); |
206 | if ((status==Success0)&&(list->num_types>0)) |
207 | list->types= _ReadListing(&buf,list->num_types,&status); |
208 | if ((status==Success0)&&(list->num_compat>0)) |
209 | list->compat= _ReadListing(&buf,list->num_compat,&status); |
210 | if ((status==Success0)&&(list->num_symbols>0)) |
211 | list->symbols= _ReadListing(&buf,list->num_symbols,&status); |
212 | if ((status==Success0)&&(list->num_geometry>0)) |
213 | list->geometry= _ReadListing(&buf,list->num_geometry,&status); |
214 | left= _XkbFreeReadBuffer(&buf); |
215 | if ((status!=Success0)||(buf.error)||(left>2)) { |
216 | XkbFreeComponentList(list); |
217 | goto BAILOUT; |
218 | } |
219 | UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display )(dpy); |
220 | SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy); |
221 | return list; |
222 | } |
223 | BAILOUT: |
224 | UnlockDisplay(dpy)if ((dpy)->lock_fns) (*(dpy)->lock_fns->unlock_display )(dpy); |
225 | SyncHandle()if (dpy->synchandler) (*dpy->synchandler)(dpy); |
226 | return NULL((void*)0); |
227 | } |
228 | |
229 | void |
230 | XkbFreeComponentList(XkbComponentListPtr list) |
231 | { |
232 | if (list) { |
233 | if (list->keymaps) |
234 | _FreeComponentNames(list->num_keymaps,list->keymaps); |
235 | if (list->keycodes) |
236 | _FreeComponentNames(list->num_keycodes,list->keycodes); |
237 | if (list->types) |
238 | _FreeComponentNames(list->num_types,list->types); |
239 | if (list->compat) |
240 | _FreeComponentNames(list->num_compat,list->compat); |
241 | if (list->symbols) |
242 | _FreeComponentNames(list->num_symbols,list->symbols); |
243 | if (list->geometry) |
244 | _FreeComponentNames(list->num_geometry,list->geometry); |
245 | bzero((char *)list,sizeof(XkbComponentListRec))memset((char *)list,0,sizeof(XkbComponentListRec)); |
246 | _XkbFree(list)free((list)); |
247 | } |
248 | return; |
249 | } |