Bug Summary

File:glx/singlepix.c
Location:line 232, column 5
Description:Call to 'realloc' has an allocation size of 0 bytes

Annotated Source Code

1/*
2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. 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 including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
29 */
30
31#ifdef HAVE_DIX_CONFIG_H1
32#include <dix-config.h>
33#endif
34
35#include "glxserver.h"
36#include "glxext.h"
37#include "singlesize.h"
38#include "unpack.h"
39#include "indirect_size_get.h"
40#include "indirect_dispatch.h"
41
42int
43__glXDisp_ReadPixels(__GLXclientState * cl, GLbyte * pc)
44{
45 GLsizei width, height;
46 GLenum format, type;
47 GLboolean swapBytes, lsbFirst;
48 GLint compsize;
49 __GLXcontext *cx;
50 ClientPtr client = cl->client;
51 int error;
52 char *answer, answerBuffer[200];
53
54 REQUEST_FIXED_SIZE(xGLXSingleReq, 28)if (((sizeof(xGLXSingleReq) >> 2) > client->req_len
) || (((28) >> 2) >= client->req_len) || ((((uint64_t
) sizeof(xGLXSingleReq) + (28) + 3) >> 2) != (uint64_t)
client->req_len)) return(16)
;
55
56 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc)(((xGLXSingleReq*)pc)->contextTag), &error);
57 if (!cx) {
58 return error;
59 }
60
61 pc += __GLX_SINGLE_HDR_SIZE8;
62 width = *(GLsizei *) (pc + 8);
63 height = *(GLsizei *) (pc + 12);
64 format = *(GLenum *) (pc + 16);
65 type = *(GLenum *) (pc + 20);
66 swapBytes = *(GLboolean *) (pc + 24);
67 lsbFirst = *(GLboolean *) (pc + 25);
68 compsize = __glReadPixels_size(format, type, width, height);
69 if (compsize < 0)
70 return BadLength16;
71
72 glPixelStorei(GL_PACK_SWAP_BYTES0x0D00, swapBytes);
73 glPixelStorei(GL_PACK_LSB_FIRST0x0D01, lsbFirst);
74 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1)if (compsize < 0) return 16; else if ((compsize) > sizeof
(answerBuffer)) { int bump; if ((cl)->returnBufSize < (
compsize)+(1)) { (cl)->returnBuf = (GLbyte*)realloc((cl)->
returnBuf, (compsize)+(1)); if (!(cl)->returnBuf) { return
11; } (cl)->returnBufSize = (compsize)+(1); } answer = (char
*)cl->returnBuf; bump = (long)(answer) % (1); if (bump) answer
+= (1) - (bump); } else { answer = (char *)answerBuffer; }
;
75 __glXClearErrorOccured();
76 glReadPixels(*(GLint *) (pc + 0), *(GLint *) (pc + 4),
77 *(GLsizei *) (pc + 8), *(GLsizei *) (pc + 12),
78 *(GLenum *) (pc + 16), *(GLenum *) (pc + 20), answer);
79
80 if (__glXErrorOccured()) {
81 __GLX_BEGIN_REPLY(0)__glXReply.length = (((0)+3) & (GLuint)~3) >> 2; __glXReply
.type = 1; __glXReply.sequenceNumber = client->sequence;
;
82 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
83 }
84 else {
85 __GLX_BEGIN_REPLY(compsize)__glXReply.length = (((compsize)+3) & (GLuint)~3) >>
2; __glXReply.type = 1; __glXReply.sequenceNumber = client->
sequence;
;
86 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
87 __GLX_SEND_VOID_ARRAY(compsize)WriteToClient(client, ((((compsize)*1)+3) & (GLuint)~3), answer
)
;
88 }
89 cx->hasUnflushedCommands = GL_FALSE0x0;
90 return Success0;
91}
92
93int
94__glXDisp_GetTexImage(__GLXclientState * cl, GLbyte * pc)
95{
96 GLint level, compsize;
97 GLenum format, type, target;
98 GLboolean swapBytes;
99 __GLXcontext *cx;
100 ClientPtr client = cl->client;
101 int error;
102 char *answer, answerBuffer[200];
103 GLint width = 0, height = 0, depth = 1;
104
105 REQUEST_FIXED_SIZE(xGLXSingleReq, 20)if (((sizeof(xGLXSingleReq) >> 2) > client->req_len
) || (((20) >> 2) >= client->req_len) || ((((uint64_t
) sizeof(xGLXSingleReq) + (20) + 3) >> 2) != (uint64_t)
client->req_len)) return(16)
;
106
107 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc)(((xGLXSingleReq*)pc)->contextTag), &error);
108 if (!cx) {
109 return error;
110 }
111
112 pc += __GLX_SINGLE_HDR_SIZE8;
113 level = *(GLint *) (pc + 4);
114 format = *(GLenum *) (pc + 8);
115 type = *(GLenum *) (pc + 12);
116 target = *(GLenum *) (pc + 0);
117 swapBytes = *(GLboolean *) (pc + 16);
118
119 glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH0x1000, &width);
120 glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT0x1001, &height);
121 if (target == GL_TEXTURE_3D0x806F) {
122 glGetTexLevelParameteriv(target, level, GL_TEXTURE_DEPTH0x8071, &depth);
123 }
124 /*
125 * The three queries above might fail if we're in a state where queries
126 * are illegal, but then width, height, and depth would still be zero anyway.
127 */
128 compsize =
129 __glGetTexImage_size(target, level, format, type, width, height, depth);
130 if (compsize < 0)
131 return BadLength16;
132
133 glPixelStorei(GL_PACK_SWAP_BYTES0x0D00, swapBytes);
134 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1)if (compsize < 0) return 16; else if ((compsize) > sizeof
(answerBuffer)) { int bump; if ((cl)->returnBufSize < (
compsize)+(1)) { (cl)->returnBuf = (GLbyte*)realloc((cl)->
returnBuf, (compsize)+(1)); if (!(cl)->returnBuf) { return
11; } (cl)->returnBufSize = (compsize)+(1); } answer = (char
*)cl->returnBuf; bump = (long)(answer) % (1); if (bump) answer
+= (1) - (bump); } else { answer = (char *)answerBuffer; }
;
135 __glXClearErrorOccured();
136 glGetTexImage(*(GLenum *) (pc + 0), *(GLint *) (pc + 4),
137 *(GLenum *) (pc + 8), *(GLenum *) (pc + 12), answer);
138
139 if (__glXErrorOccured()) {
140 __GLX_BEGIN_REPLY(0)__glXReply.length = (((0)+3) & (GLuint)~3) >> 2; __glXReply
.type = 1; __glXReply.sequenceNumber = client->sequence;
;
141 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
142 }
143 else {
144 __GLX_BEGIN_REPLY(compsize)__glXReply.length = (((compsize)+3) & (GLuint)~3) >>
2; __glXReply.type = 1; __glXReply.sequenceNumber = client->
sequence;
;
145 ((xGLXGetTexImageReply *) &__glXReply)->width = width;
146 ((xGLXGetTexImageReply *) &__glXReply)->height = height;
147 ((xGLXGetTexImageReply *) &__glXReply)->depth = depth;
148 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
149 __GLX_SEND_VOID_ARRAY(compsize)WriteToClient(client, ((((compsize)*1)+3) & (GLuint)~3), answer
)
;
150 }
151 return Success0;
152}
153
154int
155__glXDisp_GetPolygonStipple(__GLXclientState * cl, GLbyte * pc)
156{
157 GLboolean lsbFirst;
158 __GLXcontext *cx;
159 ClientPtr client = cl->client;
160 int error;
161 GLubyte answerBuffer[200];
162 char *answer;
163
164 REQUEST_FIXED_SIZE(xGLXSingleReq, 4)if (((sizeof(xGLXSingleReq) >> 2) > client->req_len
) || (((4) >> 2) >= client->req_len) || ((((uint64_t
) sizeof(xGLXSingleReq) + (4) + 3) >> 2) != (uint64_t) client
->req_len)) return(16)
;
165
166 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc)(((xGLXSingleReq*)pc)->contextTag), &error);
167 if (!cx) {
168 return error;
169 }
170
171 pc += __GLX_SINGLE_HDR_SIZE8;
172 lsbFirst = *(GLboolean *) (pc + 0);
173
174 glPixelStorei(GL_PACK_LSB_FIRST0x0D01, lsbFirst);
175 __GLX_GET_ANSWER_BUFFER(answer, cl, 128, 1)if (128 < 0) return 16; else if ((128) > sizeof(answerBuffer
)) { int bump; if ((cl)->returnBufSize < (128)+(1)) { (
cl)->returnBuf = (GLbyte*)realloc((cl)->returnBuf, (128
)+(1)); if (!(cl)->returnBuf) { return 11; } (cl)->returnBufSize
= (128)+(1); } answer = (char*)cl->returnBuf; bump = (long
)(answer) % (1); if (bump) answer += (1) - (bump); } else { answer
= (char *)answerBuffer; }
;
176
177 __glXClearErrorOccured();
178 glGetPolygonStipple((GLubyte *) answer);
179
180 if (__glXErrorOccured()) {
181 __GLX_BEGIN_REPLY(0)__glXReply.length = (((0)+3) & (GLuint)~3) >> 2; __glXReply
.type = 1; __glXReply.sequenceNumber = client->sequence;
;
182 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
183 }
184 else {
185 __GLX_BEGIN_REPLY(128)__glXReply.length = (((128)+3) & (GLuint)~3) >> 2; __glXReply
.type = 1; __glXReply.sequenceNumber = client->sequence;
;
186 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
187 __GLX_SEND_BYTE_ARRAY(128)WriteToClient(client, ((((128)*1)+3) & (GLuint)~3), answer
)
;
188 }
189 return Success0;
190}
191
192static int
193GetSeparableFilter(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
194{
195 GLint compsize, compsize2;
196 GLenum format, type, target;
197 GLboolean swapBytes;
198 __GLXcontext *cx;
199 ClientPtr client = cl->client;
200 int error;
201 char *answer, answerBuffer[200];
202 GLint width = 0, height = 0;
203
204 cx = __glXForceCurrent(cl, tag, &error);
205 if (!cx) {
2
Assuming 'cx' is non-null
3
Taking false branch
206 return error;
207 }
208
209 format = *(GLenum *) (pc + 4);
210 type = *(GLenum *) (pc + 8);
211 target = *(GLenum *) (pc + 0);
212 swapBytes = *(GLboolean *) (pc + 12);
213
214 /* target must be SEPARABLE_2D, however I guess we can let the GL
215 barf on this one.... */
216
217 glGetConvolutionParameteriv(target, GL_CONVOLUTION_WIDTH0x8018, &width);
218 glGetConvolutionParameteriv(target, GL_CONVOLUTION_HEIGHT0x8019, &height);
219 /*
220 * The two queries above might fail if we're in a state where queries
221 * are illegal, but then width and height would still be zero anyway.
222 */
223 compsize = __glGetTexImage_size(target, 1, format, type, width, 1, 1);
224 compsize2 = __glGetTexImage_size(target, 1, format, type, height, 1, 1);
225
226 if ((compsize = safe_pad(compsize)) < 0)
4
Taking false branch
227 return BadLength16;
228 if ((compsize2 = safe_pad(compsize2)) < 0)
5
Taking false branch
229 return BadLength16;
230
231 glPixelStorei(GL_PACK_SWAP_BYTES0x0D00, swapBytes);
232 __GLX_GET_ANSWER_BUFFER(answer, cl, safe_add(compsize, compsize2), 1)if (safe_add(compsize, compsize2) < 0) return 16; else if (
(safe_add(compsize, compsize2)) > sizeof(answerBuffer)) { int
bump; if ((cl)->returnBufSize < (safe_add(compsize, compsize2
))+(1)) { (cl)->returnBuf = (GLbyte*)realloc((cl)->returnBuf
, (safe_add(compsize, compsize2))+(1)); if (!(cl)->returnBuf
) { return 11; } (cl)->returnBufSize = (safe_add(compsize,
compsize2))+(1); } answer = (char*)cl->returnBuf; bump = (
long)(answer) % (1); if (bump) answer += (1) - (bump); } else
{ answer = (char *)answerBuffer; }
;
6
Within the expansion of the macro '__GLX_GET_ANSWER_BUFFER':
a
Call to 'realloc' has an allocation size of 0 bytes
233 __glXClearErrorOccured();
234 glGetSeparableFilter(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
235 *(GLenum *) (pc + 8), answer, answer + compsize, NULL((void*)0));
236
237 if (__glXErrorOccured()) {
238 __GLX_BEGIN_REPLY(0)__glXReply.length = (((0)+3) & (GLuint)~3) >> 2; __glXReply
.type = 1; __glXReply.sequenceNumber = client->sequence;
;
239 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
240 }
241 else {
242 __GLX_BEGIN_REPLY(compsize + compsize2)__glXReply.length = (((compsize + compsize2)+3) & (GLuint
)~3) >> 2; __glXReply.type = 1; __glXReply.sequenceNumber
= client->sequence;
;
243 ((xGLXGetSeparableFilterReply *) &__glXReply)->width = width;
244 ((xGLXGetSeparableFilterReply *) &__glXReply)->height = height;
245 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
246 __GLX_SEND_VOID_ARRAY(compsize + compsize2)WriteToClient(client, ((((compsize + compsize2)*1)+3) & (
GLuint)~3), answer)
;
247 }
248
249 return Success0;
250}
251
252int
253__glXDisp_GetSeparableFilter(__GLXclientState * cl, GLbyte * pc)
254{
255 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc)(((xGLXSingleReq*)pc)->contextTag);
256 ClientPtr client = cl->client;
257 REQUEST_FIXED_SIZE(xGLXSingleReq, 16)if (((sizeof(xGLXSingleReq) >> 2) > client->req_len
) || (((16) >> 2) >= client->req_len) || ((((uint64_t
) sizeof(xGLXSingleReq) + (16) + 3) >> 2) != (uint64_t)
client->req_len)) return(16)
;
258 return GetSeparableFilter(cl, pc + __GLX_SINGLE_HDR_SIZE8, tag);
259}
260
261int
262__glXDisp_GetSeparableFilterEXT(__GLXclientState * cl, GLbyte * pc)
263{
264 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc)(((xGLXVendorPrivateReq*)pc)->contextTag);
265 ClientPtr client = cl->client;
266 REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16)if (((sizeof(xGLXVendorPrivateReq) >> 2) > client->
req_len) || (((16) >> 2) >= client->req_len) || (
(((uint64_t) sizeof(xGLXVendorPrivateReq) + (16) + 3) >>
2) != (uint64_t) client->req_len)) return(16)
;
267 return GetSeparableFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE12, tag);
1
Calling 'GetSeparableFilter'
268}
269
270static int
271GetConvolutionFilter(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
272{
273 GLint compsize;
274 GLenum format, type, target;
275 GLboolean swapBytes;
276 __GLXcontext *cx;
277 ClientPtr client = cl->client;
278 int error;
279 char *answer, answerBuffer[200];
280 GLint width = 0, height = 0;
281
282 cx = __glXForceCurrent(cl, tag, &error);
283 if (!cx) {
284 return error;
285 }
286
287 format = *(GLenum *) (pc + 4);
288 type = *(GLenum *) (pc + 8);
289 target = *(GLenum *) (pc + 0);
290 swapBytes = *(GLboolean *) (pc + 12);
291
292 glGetConvolutionParameteriv(target, GL_CONVOLUTION_WIDTH0x8018, &width);
293 if (target == GL_CONVOLUTION_1D0x8010) {
294 height = 1;
295 }
296 else {
297 glGetConvolutionParameteriv(target, GL_CONVOLUTION_HEIGHT0x8019, &height);
298 }
299 /*
300 * The two queries above might fail if we're in a state where queries
301 * are illegal, but then width and height would still be zero anyway.
302 */
303 compsize = __glGetTexImage_size(target, 1, format, type, width, height, 1);
304 if (compsize < 0)
305 return BadLength16;
306
307 glPixelStorei(GL_PACK_SWAP_BYTES0x0D00, swapBytes);
308 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1)if (compsize < 0) return 16; else if ((compsize) > sizeof
(answerBuffer)) { int bump; if ((cl)->returnBufSize < (
compsize)+(1)) { (cl)->returnBuf = (GLbyte*)realloc((cl)->
returnBuf, (compsize)+(1)); if (!(cl)->returnBuf) { return
11; } (cl)->returnBufSize = (compsize)+(1); } answer = (char
*)cl->returnBuf; bump = (long)(answer) % (1); if (bump) answer
+= (1) - (bump); } else { answer = (char *)answerBuffer; }
;
309 __glXClearErrorOccured();
310 glGetConvolutionFilter(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
311 *(GLenum *) (pc + 8), answer);
312
313 if (__glXErrorOccured()) {
314 __GLX_BEGIN_REPLY(0)__glXReply.length = (((0)+3) & (GLuint)~3) >> 2; __glXReply
.type = 1; __glXReply.sequenceNumber = client->sequence;
;
315 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
316 }
317 else {
318 __GLX_BEGIN_REPLY(compsize)__glXReply.length = (((compsize)+3) & (GLuint)~3) >>
2; __glXReply.type = 1; __glXReply.sequenceNumber = client->
sequence;
;
319 ((xGLXGetConvolutionFilterReply *) &__glXReply)->width = width;
320 ((xGLXGetConvolutionFilterReply *) &__glXReply)->height = height;
321 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
322 __GLX_SEND_VOID_ARRAY(compsize)WriteToClient(client, ((((compsize)*1)+3) & (GLuint)~3), answer
)
;
323 }
324
325 return Success0;
326}
327
328int
329__glXDisp_GetConvolutionFilter(__GLXclientState * cl, GLbyte * pc)
330{
331 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc)(((xGLXSingleReq*)pc)->contextTag);
332 ClientPtr client = cl->client;
333 REQUEST_FIXED_SIZE(xGLXSingleReq, 16)if (((sizeof(xGLXSingleReq) >> 2) > client->req_len
) || (((16) >> 2) >= client->req_len) || ((((uint64_t
) sizeof(xGLXSingleReq) + (16) + 3) >> 2) != (uint64_t)
client->req_len)) return(16)
;
334 return GetConvolutionFilter(cl, pc + __GLX_SINGLE_HDR_SIZE8, tag);
335}
336
337int
338__glXDisp_GetConvolutionFilterEXT(__GLXclientState * cl, GLbyte * pc)
339{
340 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc)(((xGLXVendorPrivateReq*)pc)->contextTag);
341 ClientPtr client = cl->client;
342 REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16)if (((sizeof(xGLXVendorPrivateReq) >> 2) > client->
req_len) || (((16) >> 2) >= client->req_len) || (
(((uint64_t) sizeof(xGLXVendorPrivateReq) + (16) + 3) >>
2) != (uint64_t) client->req_len)) return(16)
;
343 return GetConvolutionFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE12, tag);
344}
345
346static int
347GetHistogram(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
348{
349 GLint compsize;
350 GLenum format, type, target;
351 GLboolean swapBytes, reset;
352 __GLXcontext *cx;
353 ClientPtr client = cl->client;
354 int error;
355 char *answer, answerBuffer[200];
356 GLint width = 0;
357
358 cx = __glXForceCurrent(cl, tag, &error);
359 if (!cx) {
360 return error;
361 }
362
363 format = *(GLenum *) (pc + 4);
364 type = *(GLenum *) (pc + 8);
365 target = *(GLenum *) (pc + 0);
366 swapBytes = *(GLboolean *) (pc + 12);
367 reset = *(GLboolean *) (pc + 13);
368
369 glGetHistogramParameteriv(target, GL_HISTOGRAM_WIDTH0x8026, &width);
370 /*
371 * The one query above might fail if we're in a state where queries
372 * are illegal, but then width would still be zero anyway.
373 */
374 compsize = __glGetTexImage_size(target, 1, format, type, width, 1, 1);
375 if (compsize < 0)
376 return BadLength16;
377
378 glPixelStorei(GL_PACK_SWAP_BYTES0x0D00, swapBytes);
379 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1)if (compsize < 0) return 16; else if ((compsize) > sizeof
(answerBuffer)) { int bump; if ((cl)->returnBufSize < (
compsize)+(1)) { (cl)->returnBuf = (GLbyte*)realloc((cl)->
returnBuf, (compsize)+(1)); if (!(cl)->returnBuf) { return
11; } (cl)->returnBufSize = (compsize)+(1); } answer = (char
*)cl->returnBuf; bump = (long)(answer) % (1); if (bump) answer
+= (1) - (bump); } else { answer = (char *)answerBuffer; }
;
380 __glXClearErrorOccured();
381 glGetHistogram(target, reset, format, type, answer);
382
383 if (__glXErrorOccured()) {
384 __GLX_BEGIN_REPLY(0)__glXReply.length = (((0)+3) & (GLuint)~3) >> 2; __glXReply
.type = 1; __glXReply.sequenceNumber = client->sequence;
;
385 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
386 }
387 else {
388 __GLX_BEGIN_REPLY(compsize)__glXReply.length = (((compsize)+3) & (GLuint)~3) >>
2; __glXReply.type = 1; __glXReply.sequenceNumber = client->
sequence;
;
389 ((xGLXGetHistogramReply *) &__glXReply)->width = width;
390 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
391 __GLX_SEND_VOID_ARRAY(compsize)WriteToClient(client, ((((compsize)*1)+3) & (GLuint)~3), answer
)
;
392 }
393
394 return Success0;
395}
396
397int
398__glXDisp_GetHistogram(__GLXclientState * cl, GLbyte * pc)
399{
400 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc)(((xGLXSingleReq*)pc)->contextTag);
401 ClientPtr client = cl->client;
402 REQUEST_FIXED_SIZE(xGLXSingleReq, 16)if (((sizeof(xGLXSingleReq) >> 2) > client->req_len
) || (((16) >> 2) >= client->req_len) || ((((uint64_t
) sizeof(xGLXSingleReq) + (16) + 3) >> 2) != (uint64_t)
client->req_len)) return(16)
;
403 return GetHistogram(cl, pc + __GLX_SINGLE_HDR_SIZE8, tag);
404}
405
406int
407__glXDisp_GetHistogramEXT(__GLXclientState * cl, GLbyte * pc)
408{
409 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc)(((xGLXVendorPrivateReq*)pc)->contextTag);
410 ClientPtr client = cl->client;
411 REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16)if (((sizeof(xGLXVendorPrivateReq) >> 2) > client->
req_len) || (((16) >> 2) >= client->req_len) || (
(((uint64_t) sizeof(xGLXVendorPrivateReq) + (16) + 3) >>
2) != (uint64_t) client->req_len)) return(16)
;
412 return GetHistogram(cl, pc + __GLX_VENDPRIV_HDR_SIZE12, tag);
413}
414
415static int
416GetMinmax(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
417{
418 GLint compsize;
419 GLenum format, type, target;
420 GLboolean swapBytes, reset;
421 __GLXcontext *cx;
422 ClientPtr client = cl->client;
423 int error;
424 char *answer, answerBuffer[200];
425
426 cx = __glXForceCurrent(cl, tag, &error);
427 if (!cx) {
428 return error;
429 }
430
431 format = *(GLenum *) (pc + 4);
432 type = *(GLenum *) (pc + 8);
433 target = *(GLenum *) (pc + 0);
434 swapBytes = *(GLboolean *) (pc + 12);
435 reset = *(GLboolean *) (pc + 13);
436
437 compsize = __glGetTexImage_size(target, 1, format, type, 2, 1, 1);
438 if (compsize < 0)
439 return BadLength16;
440
441 glPixelStorei(GL_PACK_SWAP_BYTES0x0D00, swapBytes);
442 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1)if (compsize < 0) return 16; else if ((compsize) > sizeof
(answerBuffer)) { int bump; if ((cl)->returnBufSize < (
compsize)+(1)) { (cl)->returnBuf = (GLbyte*)realloc((cl)->
returnBuf, (compsize)+(1)); if (!(cl)->returnBuf) { return
11; } (cl)->returnBufSize = (compsize)+(1); } answer = (char
*)cl->returnBuf; bump = (long)(answer) % (1); if (bump) answer
+= (1) - (bump); } else { answer = (char *)answerBuffer; }
;
443 __glXClearErrorOccured();
444 glGetMinmax(target, reset, format, type, answer);
445
446 if (__glXErrorOccured()) {
447 __GLX_BEGIN_REPLY(0)__glXReply.length = (((0)+3) & (GLuint)~3) >> 2; __glXReply
.type = 1; __glXReply.sequenceNumber = client->sequence;
;
448 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
449 }
450 else {
451 __GLX_BEGIN_REPLY(compsize)__glXReply.length = (((compsize)+3) & (GLuint)~3) >>
2; __glXReply.type = 1; __glXReply.sequenceNumber = client->
sequence;
;
452 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
453 __GLX_SEND_VOID_ARRAY(compsize)WriteToClient(client, ((((compsize)*1)+3) & (GLuint)~3), answer
)
;
454 }
455
456 return Success0;
457}
458
459int
460__glXDisp_GetMinmax(__GLXclientState * cl, GLbyte * pc)
461{
462 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc)(((xGLXSingleReq*)pc)->contextTag);
463 ClientPtr client = cl->client;
464 REQUEST_FIXED_SIZE(xGLXSingleReq, 16)if (((sizeof(xGLXSingleReq) >> 2) > client->req_len
) || (((16) >> 2) >= client->req_len) || ((((uint64_t
) sizeof(xGLXSingleReq) + (16) + 3) >> 2) != (uint64_t)
client->req_len)) return(16)
;
465 return GetMinmax(cl, pc + __GLX_SINGLE_HDR_SIZE8, tag);
466}
467
468int
469__glXDisp_GetMinmaxEXT(__GLXclientState * cl, GLbyte * pc)
470{
471 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc)(((xGLXVendorPrivateReq*)pc)->contextTag);
472 ClientPtr client = cl->client;
473 REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16)if (((sizeof(xGLXVendorPrivateReq) >> 2) > client->
req_len) || (((16) >> 2) >= client->req_len) || (
(((uint64_t) sizeof(xGLXVendorPrivateReq) + (16) + 3) >>
2) != (uint64_t) client->req_len)) return(16)
;
474 return GetMinmax(cl, pc + __GLX_VENDPRIV_HDR_SIZE12, tag);
475}
476
477static int
478GetColorTable(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
479{
480 GLint compsize;
481 GLenum format, type, target;
482 GLboolean swapBytes;
483 __GLXcontext *cx;
484 ClientPtr client = cl->client;
485 int error;
486 char *answer, answerBuffer[200];
487 GLint width = 0;
488
489 cx = __glXForceCurrent(cl, tag, &error);
490 if (!cx) {
491 return error;
492 }
493
494 target = *(GLenum *) (pc + 0);
495 format = *(GLenum *) (pc + 4);
496 type = *(GLenum *) (pc + 8);
497 swapBytes = *(GLboolean *) (pc + 12);
498
499 glGetColorTableParameteriv(target, GL_COLOR_TABLE_WIDTH0x80D9, &width);
500 /*
501 * The one query above might fail if we're in a state where queries
502 * are illegal, but then width would still be zero anyway.
503 */
504 compsize = __glGetTexImage_size(target, 1, format, type, width, 1, 1);
505 if (compsize < 0)
506 return BadLength16;
507
508 glPixelStorei(GL_PACK_SWAP_BYTES0x0D00, swapBytes);
509 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1)if (compsize < 0) return 16; else if ((compsize) > sizeof
(answerBuffer)) { int bump; if ((cl)->returnBufSize < (
compsize)+(1)) { (cl)->returnBuf = (GLbyte*)realloc((cl)->
returnBuf, (compsize)+(1)); if (!(cl)->returnBuf) { return
11; } (cl)->returnBufSize = (compsize)+(1); } answer = (char
*)cl->returnBuf; bump = (long)(answer) % (1); if (bump) answer
+= (1) - (bump); } else { answer = (char *)answerBuffer; }
;
510 __glXClearErrorOccured();
511 glGetColorTable(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
512 *(GLenum *) (pc + 8), answer);
513
514 if (__glXErrorOccured()) {
515 __GLX_BEGIN_REPLY(0)__glXReply.length = (((0)+3) & (GLuint)~3) >> 2; __glXReply
.type = 1; __glXReply.sequenceNumber = client->sequence;
;
516 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
517 }
518 else {
519 __GLX_BEGIN_REPLY(compsize)__glXReply.length = (((compsize)+3) & (GLuint)~3) >>
2; __glXReply.type = 1; __glXReply.sequenceNumber = client->
sequence;
;
520 ((xGLXGetColorTableReply *) &__glXReply)->width = width;
521 __GLX_SEND_HEADER()WriteToClient (client, 32, &__glXReply);;
522 __GLX_SEND_VOID_ARRAY(compsize)WriteToClient(client, ((((compsize)*1)+3) & (GLuint)~3), answer
)
;
523 }
524
525 return Success0;
526}
527
528int
529__glXDisp_GetColorTable(__GLXclientState * cl, GLbyte * pc)
530{
531 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc)(((xGLXSingleReq*)pc)->contextTag);
532 ClientPtr client = cl->client;
533 REQUEST_FIXED_SIZE(xGLXSingleReq, 16)if (((sizeof(xGLXSingleReq) >> 2) > client->req_len
) || (((16) >> 2) >= client->req_len) || ((((uint64_t
) sizeof(xGLXSingleReq) + (16) + 3) >> 2) != (uint64_t)
client->req_len)) return(16)
;
534 return GetColorTable(cl, pc + __GLX_SINGLE_HDR_SIZE8, tag);
535}
536
537int
538__glXDisp_GetColorTableSGI(__GLXclientState * cl, GLbyte * pc)
539{
540 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc)(((xGLXVendorPrivateReq*)pc)->contextTag);
541 ClientPtr client = cl->client;
542 REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16)if (((sizeof(xGLXVendorPrivateReq) >> 2) > client->
req_len) || (((16) >> 2) >= client->req_len) || (
(((uint64_t) sizeof(xGLXVendorPrivateReq) + (16) + 3) >>
2) != (uint64_t) client->req_len)) return(16)
;
543 return GetColorTable(cl, pc + __GLX_VENDPRIV_HDR_SIZE12, tag);
544}