glx: use calloc() instead of malloc()
Using calloc() instead of malloc() as preventive measure, so there never can be any hidden bugs or leaks due uninitialized memory. The extra cost of using this compiler intrinsic should be practically impossible to measure - in many cases a good compiler can even deduce if certain areas really don't need to be zero'd (because they're written to right after allocation) and create more efficient machine code. The code pathes in question are pretty cold anyways, so it's probably not worth even thinking about potential extra runtime costs. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
a53acd9f27
commit
085919667b
|
@ -272,15 +272,15 @@ __glXcombine_strings(const char *cext_string, const char *sext_string)
|
||||||
clen = strlen(cext_string);
|
clen = strlen(cext_string);
|
||||||
slen = strlen(sext_string);
|
slen = strlen(sext_string);
|
||||||
if (clen > slen) {
|
if (clen > slen) {
|
||||||
combo_string = (char *) malloc(slen + 2);
|
combo_string = (char *) calloc(1, slen + 2);
|
||||||
s1 = (char *) malloc(slen + 2);
|
s1 = (char *) calloc(1, slen + 2);
|
||||||
if (s1)
|
if (s1)
|
||||||
strcpy(s1, sext_string);
|
strcpy(s1, sext_string);
|
||||||
s2 = cext_string;
|
s2 = cext_string;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
combo_string = (char *) malloc(clen + 2);
|
combo_string = (char *) calloc(1, clen + 2);
|
||||||
s1 = (char *) malloc(clen + 2);
|
s1 = (char *) calloc(1, clen + 2);
|
||||||
if (s1)
|
if (s1)
|
||||||
strcpy(s1, cext_string);
|
strcpy(s1, cext_string);
|
||||||
s2 = sext_string;
|
s2 = sext_string;
|
||||||
|
|
|
@ -126,7 +126,6 @@ static int dispatch_GLXQueryVersion(ClientPtr client)
|
||||||
static int dispatch_GLXClientInfo(ClientPtr client)
|
static int dispatch_GLXClientInfo(ClientPtr client)
|
||||||
{
|
{
|
||||||
GlxServerVendor *vendor;
|
GlxServerVendor *vendor;
|
||||||
void *requestCopy = NULL;
|
|
||||||
size_t requestSize = client->req_len * 4;
|
size_t requestSize = client->req_len * 4;
|
||||||
|
|
||||||
if (client->minorOp == X_GLXClientInfo) {
|
if (client->minorOp == X_GLXClientInfo) {
|
||||||
|
@ -142,7 +141,7 @@ static int dispatch_GLXClientInfo(ClientPtr client)
|
||||||
// We'll forward this request to each vendor library. Since a vendor might
|
// We'll forward this request to each vendor library. Since a vendor might
|
||||||
// modify the request data in place (e.g., for byte swapping), make a copy
|
// modify the request data in place (e.g., for byte swapping), make a copy
|
||||||
// of the request first.
|
// of the request first.
|
||||||
requestCopy = malloc(requestSize);
|
void *requestCopy = calloc(1, requestSize);
|
||||||
if (requestCopy == NULL) {
|
if (requestCopy == NULL) {
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ __glXMakeBitmapFromGlyph(FontPtr font, CharInfoPtr pci)
|
||||||
widthPadded = GLYPHWIDTHBYTESPADDED(pci);
|
widthPadded = GLYPHWIDTHBYTESPADDED(pci);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Use the local buf if possible, otherwise malloc.
|
** Use the local buf if possible, otherwise calloc.
|
||||||
*/
|
*/
|
||||||
allocBytes = widthPadded * h;
|
allocBytes = widthPadded * h;
|
||||||
if (allocBytes <= __GL_CHAR_BUF_SIZE) {
|
if (allocBytes <= __GL_CHAR_BUF_SIZE) {
|
||||||
|
@ -72,7 +72,7 @@ __glXMakeBitmapFromGlyph(FontPtr font, CharInfoPtr pci)
|
||||||
allocbuf = 0;
|
allocbuf = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p = (unsigned char *) malloc(allocBytes);
|
p = calloc(1, allocBytes);
|
||||||
if (!p)
|
if (!p)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
allocbuf = p;
|
allocbuf = p;
|
||||||
|
|
Loading…
Reference in New Issue