Xi: 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
085919667b
commit
55544ff85f
|
@ -2335,12 +2335,10 @@ DeliverGestureEventToOwner(DeviceIntPtr dev, GestureInfoPtr gi, InternalEvent *e
|
|||
int
|
||||
InitProximityClassDeviceStruct(DeviceIntPtr dev)
|
||||
{
|
||||
ProximityClassPtr proxc;
|
||||
|
||||
BUG_RETURN_VAL(dev == NULL, FALSE);
|
||||
BUG_RETURN_VAL(dev->proximity != NULL, FALSE);
|
||||
|
||||
proxc = (ProximityClassPtr) malloc(sizeof(ProximityClassRec));
|
||||
ProximityClassPtr proxc = calloc(1, sizeof(ProximityClassRec));
|
||||
if (!proxc)
|
||||
return FALSE;
|
||||
proxc->sourceid = dev->id;
|
||||
|
|
|
@ -168,7 +168,7 @@ int
|
|||
ProcXGetDeviceControl(ClientPtr client)
|
||||
{
|
||||
int rc, total_length = 0;
|
||||
char *buf, *savbuf;
|
||||
char *savbuf;
|
||||
DeviceIntPtr dev;
|
||||
xGetDeviceControlReply rep;
|
||||
|
||||
|
@ -206,7 +206,7 @@ ProcXGetDeviceControl(ClientPtr client)
|
|||
return BadValue;
|
||||
}
|
||||
|
||||
buf = (char *) malloc(total_length);
|
||||
char *buf = calloc(1, total_length);
|
||||
if (!buf)
|
||||
return BadAlloc;
|
||||
savbuf = buf;
|
||||
|
|
|
@ -261,7 +261,7 @@ int
|
|||
ProcXGetFeedbackControl(ClientPtr client)
|
||||
{
|
||||
int rc, total_length = 0;
|
||||
char *buf, *savbuf;
|
||||
char *savbuf;
|
||||
DeviceIntPtr dev;
|
||||
KbdFeedbackPtr k;
|
||||
PtrFeedbackPtr p;
|
||||
|
@ -315,7 +315,7 @@ ProcXGetFeedbackControl(ClientPtr client)
|
|||
if (total_length == 0)
|
||||
return BadMatch;
|
||||
|
||||
buf = (char *) malloc(total_length);
|
||||
char *buf = (char *) calloc(1, total_length);
|
||||
if (!buf)
|
||||
return BadAlloc;
|
||||
savbuf = buf;
|
||||
|
|
|
@ -131,7 +131,7 @@ ProcXGetSelectedExtensionEvents(ClientPtr client)
|
|||
total_length = (rep.all_clients_count + rep.this_client_count) *
|
||||
sizeof(XEventClass);
|
||||
rep.length = bytes_to_int32(total_length);
|
||||
buf = (XEventClass *) malloc(total_length);
|
||||
buf = calloc(1, total_length);
|
||||
|
||||
tclient = buf;
|
||||
aclient = buf + rep.this_client_count;
|
||||
|
|
|
@ -103,9 +103,7 @@ typedef struct _BarrierScreen {
|
|||
|
||||
static struct PointerBarrierDevice *AllocBarrierDevice(void)
|
||||
{
|
||||
struct PointerBarrierDevice *pbd = NULL;
|
||||
|
||||
pbd = malloc(sizeof(struct PointerBarrierDevice));
|
||||
struct PointerBarrierDevice *pbd = calloc(1, sizeof(struct PointerBarrierDevice));
|
||||
if (!pbd)
|
||||
return NULL;
|
||||
|
||||
|
@ -558,15 +556,13 @@ CreatePointerBarrierClient(ClientPtr client,
|
|||
ScreenPtr screen;
|
||||
BarrierScreenPtr cs;
|
||||
int err;
|
||||
int size;
|
||||
int i;
|
||||
struct PointerBarrierClient *ret;
|
||||
CARD16 *in_devices;
|
||||
DeviceIntPtr dev;
|
||||
|
||||
size = sizeof(*ret) + sizeof(DeviceIntPtr) * stuff->num_devices;
|
||||
ret = malloc(size);
|
||||
|
||||
const int size = sizeof(struct PointerBarrierClient)
|
||||
+ sizeof(DeviceIntPtr) * stuff->num_devices;
|
||||
struct PointerBarrierClient *ret = calloc(1, size);
|
||||
if (!ret) {
|
||||
return BadAlloc;
|
||||
}
|
||||
|
|
|
@ -575,9 +575,7 @@ XIUnregisterPropertyHandler(DeviceIntPtr dev, long id)
|
|||
static XIPropertyPtr
|
||||
XICreateDeviceProperty(Atom property)
|
||||
{
|
||||
XIPropertyPtr prop;
|
||||
|
||||
prop = (XIPropertyPtr) malloc(sizeof(XIPropertyRec));
|
||||
XIPropertyPtr prop = calloc(1, sizeof(XIPropertyRec));
|
||||
if (!prop)
|
||||
return NULL;
|
||||
|
||||
|
|
Loading…
Reference in New Issue