From 1d550bb2c5cb5b3e588f0e0b68a421dc1cb8bd7c Mon Sep 17 00:00:00 2001 From: Eamon Walsh Date: Thu, 5 Apr 2007 12:12:58 -0400 Subject: [PATCH] devPrivates rework: minor fix; use calloc and avoid initialization. --- dix/devices.c | 3 +-- dix/main.c | 13 +++++-------- dix/privates.c | 6 ++---- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/dix/devices.c b/dix/devices.c index 4a7ec4d92..ab64fcb04 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -128,12 +128,11 @@ AddInputDevice(DeviceProc deviceProc, Bool autoStart) #endif /* must pre-allocate one private for the new devPrivates support */ dev->nPrivates = 1; - dev->devPrivates = (DevUnion *)xalloc(sizeof(DevUnion)); + dev->devPrivates = (DevUnion *)xcalloc(1, sizeof(DevUnion)); if (!dev->devPrivates) { xfree(dev); return NULL; } - dev->devPrivates[0].ptr = NULL; dev->unwrapProc = NULL; dev->coreEvents = TRUE; diff --git a/dix/main.c b/dix/main.c index b5db193ba..cae50c85d 100644 --- a/dix/main.c +++ b/dix/main.c @@ -720,20 +720,17 @@ AddScreen( /* must pre-allocate one private for the new devPrivates support */ pScreen->WindowPrivateLen = 1; - pScreen->WindowPrivateSizes = (unsigned *)xalloc(sizeof(unsigned)); + pScreen->WindowPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned)); pScreen->totalWindowSize = PadToLong(sizeof(WindowRec)) + sizeof(DevUnion); pScreen->GCPrivateLen = 1; - pScreen->GCPrivateSizes = (unsigned *)xalloc(sizeof(unsigned)); + pScreen->GCPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned)); pScreen->totalGCSize = PadToLong(sizeof(GC)) + sizeof(DevUnion); pScreen->PixmapPrivateLen = 1; - pScreen->PixmapPrivateSizes = (unsigned *)xalloc(sizeof(unsigned)); + pScreen->PixmapPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned)); pScreen->totalPixmapSize = BitmapBytePad(8 * (sizeof(PixmapRec) + sizeof(DevUnion))); - if (pScreen->WindowPrivateSizes && pScreen->GCPrivateSizes && - pScreen->PixmapPrivateSizes) - *pScreen->WindowPrivateSizes = *pScreen->GCPrivateSizes = - *pScreen->PixmapPrivateSizes = 0; - else { + if (!pScreen->WindowPrivateSizes || !pScreen->GCPrivateSizes || + !pScreen->PixmapPrivateSizes) { xfree(pScreen); return -1; } diff --git a/dix/privates.c b/dix/privates.c index 8a39437cb..4cb2e358d 100644 --- a/dix/privates.c +++ b/dix/privates.c @@ -298,10 +298,9 @@ ResetExtensionPrivates() extensionPrivateCount = 1; extensionPrivateLen = 1; xfree(extensionPrivateSizes); - extensionPrivateSizes = (unsigned *)xalloc(sizeof(unsigned)); + extensionPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned)); if (!extensionPrivateSizes) return FALSE; - *extensionPrivateSizes = 0; totalExtensionSize = PadToLong(sizeof(ExtensionEntry)) + sizeof(DevUnion); return TRUE; } @@ -358,10 +357,9 @@ ResetClientPrivates() clientPrivateCount = 1; clientPrivateLen = 1; xfree(clientPrivateSizes); - clientPrivateSizes = (unsigned *)xalloc(sizeof(unsigned)); + clientPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned)); if (!clientPrivateSizes) return FALSE; - *clientPrivateSizes = 0; totalClientSize = PadToLong(sizeof(ClientRec)) + sizeof(DevUnion); return TRUE; }