xwin: replace ZeroMemory()

replace Windows specific ZeroMemory (macro just calling memset())
by static initialization, calloc() and memset().

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1295>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-02-14 12:01:17 +01:00 committed by Marge Bot
parent c444223da3
commit 7bd19a9580
8 changed files with 53 additions and 84 deletions

View File

@ -58,15 +58,12 @@ winAllocatePrivates(ScreenPtr pScreen)
}
/* Allocate memory for the screen private structure */
pScreenPriv = malloc(sizeof(winPrivScreenRec));
pScreenPriv = calloc(sizeof(winPrivScreenRec), 1);
if (!pScreenPriv) {
ErrorF("winAllocateScreenPrivates - malloc () failed\n");
return FALSE;
}
/* Initialize the memory of the private structure */
ZeroMemory(pScreenPriv, sizeof(winPrivScreenRec));
/* Initialize private structure members */
pScreenPriv->fActive = TRUE;
@ -143,15 +140,12 @@ winAllocateCmapPrivates(ColormapPtr pCmap)
}
/* Allocate memory for our private structure */
pCmapPriv = malloc(sizeof(winPrivCmapRec));
pCmapPriv = calloc(sizeof(winPrivCmapRec), 1);
if (!pCmapPriv) {
ErrorF("winAllocateCmapPrivates - malloc () failed\n");
return FALSE;
}
/* Initialize the memory of the private structure */
ZeroMemory(pCmapPriv, sizeof(winPrivCmapRec));
/* Register our colourmap private */
if (!dixRegisterPrivateKey(g_iCmapPrivateKey, PRIVATE_COLORMAP, 0)) {
ErrorF("winAllocateCmapPrivates - AllocateCmapPrivate () failed\n");

View File

@ -512,14 +512,12 @@ winGetWorkArea(RECT * prcWorkArea, winScreenInfo * pScreenInfo)
static Bool
winTaskbarOnScreenEdge(unsigned int uEdge, winScreenInfo * pScreenInfo)
{
APPBARDATA abd;
HWND hwndAutoHide;
APPBARDATA abd = (APPBARDATA) {
.cbSize = sizeof(APPBARDATA),
.uEdge = uEdge
};
ZeroMemory(&abd, sizeof(abd));
abd.cbSize = sizeof(abd);
abd.uEdge = uEdge;
hwndAutoHide = (HWND) SHAppBarMessage(ABM_GETAUTOHIDEBAR, &abd);
HWND hwndAutoHide = (HWND) SHAppBarMessage(ABM_GETAUTOHIDEBAR, &abd);
if (hwndAutoHide != NULL) {
/*
Found an autohide taskbar on that edge, but is it on the
@ -541,15 +539,15 @@ winTaskbarOnScreenEdge(unsigned int uEdge, winScreenInfo * pScreenInfo)
static Bool
winAdjustForAutoHide(RECT * prcWorkArea, winScreenInfo * pScreenInfo)
{
APPBARDATA abd;
APPBARDATA abd = (APPBARDATA) {
.cbSize = sizeof(APPBARDATA)
};
winDebug("winAdjustForAutoHide - Original WorkArea: %d %d %d %d\n",
(int) prcWorkArea->top, (int) prcWorkArea->left,
(int) prcWorkArea->bottom, (int) prcWorkArea->right);
/* Find out if the Windows taskbar is set to auto-hide */
ZeroMemory(&abd, sizeof(abd));
abd.cbSize = sizeof(abd);
if (SHAppBarMessage(ABM_GETSTATE, &abd) & ABS_AUTOHIDE)
winDebug("winAdjustForAutoHide - Taskbar is auto hide\n");

View File

@ -1395,9 +1395,9 @@ winInitWM(void **ppWMInfo,
pthread_mutex_t * ppmServerStarted,
int dwScreen, HWND hwndScreen, Bool compositeWM)
{
WMProcArgPtr pArg = malloc(sizeof(WMProcArgRec));
WMInfoPtr pWMInfo = malloc(sizeof(WMInfoRec));
XMsgProcArgPtr pXMsgArg = malloc(sizeof(XMsgProcArgRec));
WMProcArgPtr pArg = calloc(sizeof(WMProcArgRec), 1);
WMInfoPtr pWMInfo = calloc(sizeof(WMInfoRec), 1);
XMsgProcArgPtr pXMsgArg = calloc(sizeof(XMsgProcArgRec), 1);
/* Bail if the input parameters are bad */
if (pArg == NULL || pWMInfo == NULL || pXMsgArg == NULL) {
@ -1408,11 +1408,6 @@ winInitWM(void **ppWMInfo,
return FALSE;
}
/* Zero the allocated memory */
ZeroMemory(pArg, sizeof(WMProcArgRec));
ZeroMemory(pWMInfo, sizeof(WMInfoRec));
ZeroMemory(pXMsgArg, sizeof(XMsgProcArgRec));
/* Set a return pointer to the Window Manager info structure */
*ppWMInfo = pWMInfo;
pWMInfo->fCompositeWM = compositeWM;

View File

@ -621,13 +621,11 @@ winTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
/* Are we tracking yet? */
if (!s_fTracking) {
TRACKMOUSEEVENT tme;
/* Setup data structure */
ZeroMemory(&tme, sizeof(tme));
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = hwnd;
TRACKMOUSEEVENT tme = (TRACKMOUSEEVENT) {
.cbSize = sizeof(TRACKMOUSEEVENT),
.dwFlags = TME_LEAVE,
.hwndTrack = hwnd,
};
/* Call the tracking function */
if (!TrackMouseEvent(&tme))

View File

@ -98,16 +98,14 @@ winCreatePrimarySurfaceShadowDDNL(ScreenPtr pScreen)
{
winScreenPriv(pScreen);
HRESULT ddrval = DD_OK;
DDSURFACEDESC2 ddsd;
DDSURFACEDESC2 ddsd = (DDSURFACEDESC2) {
.dwSize = sizeof(DDSURFACEDESC2),
.dwFlags = DDSD_CAPS,
.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE
};
winDebug("winCreatePrimarySurfaceShadowDDNL - Creating primary surface\n");
/* Describe the primary surface */
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
/* Create the primary surface */
ddrval = IDirectDraw4_CreateSurface(pScreenPriv->pdd4,
&ddsd,
@ -195,9 +193,10 @@ winAllocateFBShadowDDNL(ScreenPtr pScreen)
winScreenPriv(pScreen);
winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
HRESULT ddrval = DD_OK;
DDSURFACEDESC2 ddsdShadow;
char *lpSurface = NULL;
DDPIXELFORMAT ddpfPrimary;
DDPIXELFORMAT ddpfPrimary = (DDPIXELFORMAT) {
.dwSize = sizeof(DDPIXELFORMAT)
};
#if CYGDEBUG
winDebug("winAllocateFBShadowDDNL - w %u h %u d %u\n",
@ -211,18 +210,12 @@ winAllocateFBShadowDDNL(ScreenPtr pScreen)
pScreenInfo->dwBPP);
/* Allocate memory for our shadow surface */
lpSurface = malloc(pScreenInfo->dwPaddedWidth * pScreenInfo->dwHeight);
lpSurface = calloc(pScreenInfo->dwPaddedWidth, pScreenInfo->dwHeight);
if (lpSurface == NULL) {
ErrorF("winAllocateFBShadowDDNL - Could not allocate bits\n");
return FALSE;
}
/*
* Initialize the framebuffer memory so we don't get a
* strange display at startup
*/
ZeroMemory(lpSurface, pScreenInfo->dwPaddedWidth * pScreenInfo->dwHeight);
/* Create a clipper */
ddrval = (*g_fpDirectDrawCreateClipper) (0,
&pScreenPriv->pddcPrimary, NULL);
@ -275,7 +268,6 @@ winAllocateFBShadowDDNL(ScreenPtr pScreen)
/* Are we full screen? */
if (pScreenInfo->fFullScreen) {
DDSURFACEDESC2 ddsdCurrent;
DWORD dwRefreshRateCurrent = 0;
HDC hdc = NULL;
@ -295,8 +287,9 @@ winAllocateFBShadowDDNL(ScreenPtr pScreen)
* if a refresh rate has been passed on the command line.
*/
if (pScreenInfo->dwRefreshRate != 0) {
ZeroMemory(&ddsdCurrent, sizeof(ddsdCurrent));
ddsdCurrent.dwSize = sizeof(ddsdCurrent);
DDSURFACEDESC2 ddsdCurrent = (DDSURFACEDESC2) {
.dwSize = sizeof(DDSURFACEDESC2)
};
/* Get information about current display settings */
ddrval = IDirectDraw4_GetDisplayMode(pScreenPriv->pdd4,
@ -390,8 +383,6 @@ winAllocateFBShadowDDNL(ScreenPtr pScreen)
}
/* Get primary surface's pixel format */
ZeroMemory(&ddpfPrimary, sizeof(ddpfPrimary));
ddpfPrimary.dwSize = sizeof(ddpfPrimary);
ddrval = IDirectDrawSurface4_GetPixelFormat(pScreenPriv->pddsPrimary4,
&ddpfPrimary);
if (FAILED(ddrval)) {
@ -418,16 +409,17 @@ winAllocateFBShadowDDNL(ScreenPtr pScreen)
* so you shouldn't be allocating video memory when
* you have the option of using system memory instead.
*/
ZeroMemory(&ddsdShadow, sizeof(ddsdShadow));
ddsdShadow.dwSize = sizeof(ddsdShadow);
ddsdShadow.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH
| DDSD_LPSURFACE | DDSD_PITCH | DDSD_PIXELFORMAT;
ddsdShadow.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
ddsdShadow.dwHeight = pScreenInfo->dwHeight;
ddsdShadow.dwWidth = pScreenInfo->dwWidth;
ddsdShadow.u1.lPitch = pScreenInfo->dwPaddedWidth;
ddsdShadow.lpSurface = lpSurface;
ddsdShadow.u4.ddpfPixelFormat = ddpfPrimary;
DDSURFACEDESC2 ddsdShadow = (DDSURFACEDESC2) {
.dwSize = sizeof(ddsdShadow),
.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH
| DDSD_LPSURFACE | DDSD_PITCH | DDSD_PIXELFORMAT,
.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
.dwHeight = pScreenInfo->dwHeight,
.dwWidth = pScreenInfo->dwWidth,
.u1.lPitch = pScreenInfo->dwPaddedWidth,
.lpSurface = lpSurface,
.u4.ddpfPixelFormat = ddpfPrimary
};
winDebug("winAllocateFBShadowDDNL - lPitch: %d\n",
(int) pScreenInfo->dwPaddedWidth);

View File

@ -106,7 +106,7 @@ winQueryScreenDIBFormat(ScreenPtr pScreen, BITMAPINFOHEADER * pbmih)
}
/* Initialize our bitmap info header */
ZeroMemory(pbmih, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
memset(pbmih, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD), 1);
pbmih->biSize = sizeof(BITMAPINFOHEADER);
/* Get the biBitCount */
@ -1162,18 +1162,14 @@ winCreateColormapShadowGDI(ColormapPtr pColormap)
dwEntriesMax = pVisual->ColormapEntries;
/* Allocate a Windows logical color palette with max entries */
lpPaletteNew = malloc(sizeof(LOGPALETTE)
+ (dwEntriesMax - 1) * sizeof(PALETTEENTRY));
lpPaletteNew = calloc(sizeof(LOGPALETTE)
+ (dwEntriesMax - 1) * sizeof(PALETTEENTRY), 1);
if (lpPaletteNew == NULL) {
ErrorF("winCreateColormapShadowGDI - Couldn't allocate palette "
"with %d entries\n", (int) dwEntriesMax);
return FALSE;
}
/* Zero out the colormap */
ZeroMemory(lpPaletteNew, sizeof(LOGPALETTE)
+ (dwEntriesMax - 1) * sizeof(PALETTEENTRY));
/* Set the logical palette structure */
lpPaletteNew->palVersion = 0x0300;
lpPaletteNew->palNumEntries = dwEntriesMax;

View File

@ -711,13 +711,11 @@ winWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
/* Are we tracking yet? */
if (!s_fTracking) {
TRACKMOUSEEVENT tme;
/* Setup data structure */
ZeroMemory(&tme, sizeof(tme));
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = hwnd;
TRACKMOUSEEVENT tme = (TRACKMOUSEEVENT) {
tme.cbSize = sizeof(tme),
tme.dwFlags = TME_LEAVE,
tme.hwndTrack = hwnd
};
/* Call the tracking function */
if (!TrackMouseEvent(&tme))

View File

@ -1492,15 +1492,13 @@ Win32TempDir(void)
int
System(const char *cmdline)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
STARTUPINFO si = (STARTUPINFO) {
.cb = sizeof(si),
};
PROCESS_INFORMATION pi = (PROCESS_INFORMATION){0};
DWORD dwExitCode;
char *cmd = strdup(cmdline);
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
LPVOID buffer;