From 5377ee4d813fc6de34a46c31198a6a2a05c218cd Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 10 Apr 2025 20:11:48 +0200 Subject: [PATCH] xwin: 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 --- hw/xwin/InitOutput.c | 8 ++++---- hw/xwin/glx/indirect.c | 8 +++----- hw/xwin/winauth.c | 7 +------ hw/xwin/winclipboard/textconv.c | 2 +- hw/xwin/winclipboard/xevents.c | 22 +++++++++++----------- hw/xwin/wincmap.c | 5 ++--- hw/xwin/winconfig.c | 9 ++++----- hw/xwin/wincursor.c | 3 +-- hw/xwin/winmouse.c | 3 +-- hw/xwin/winmultiwindowclass.c | 8 ++++---- hw/xwin/winmultiwindowicons.c | 6 +++--- hw/xwin/winmultiwindowwindow.c | 5 ++--- hw/xwin/winmultiwindowwm.c | 10 ++++------ hw/xwin/winprefs.c | 4 ++-- hw/xwin/winprefslex.l | 3 +-- hw/xwin/winprefsyacc.y | 10 +++++----- hw/xwin/winprocarg.c | 2 +- hw/xwin/winrandr.c | 4 ++-- hw/xwin/winshadgdi.c | 9 ++++----- 19 files changed, 56 insertions(+), 72 deletions(-) diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c index a8a8cac24..65fa17150 100644 --- a/hw/xwin/InitOutput.c +++ b/hw/xwin/InitOutput.c @@ -463,7 +463,7 @@ winFixupPaths(void) /* allocate memory */ if (fontpath == NULL) - fontpath = malloc(newsize + 1); + fontpath = calloc(1, newsize + 1); else fontpath = realloc(fontpath, newsize + 1); @@ -509,7 +509,7 @@ winFixupPaths(void) while (ptr != NULL) { size_t oldfp_len = (ptr - oldptr); size_t newsize = oldfp_len; - char *newpath = malloc(newsize + 1); + char *newpath = calloc(1, newsize + 1); strncpy(newpath, oldptr, newsize); newpath[newsize] = 0; @@ -518,7 +518,7 @@ winFixupPaths(void) char *compose; newsize = newsize - libx11dir_len + basedirlen; - compose = malloc(newsize + 1); + compose = calloc(1, newsize + 1); strcpy(compose, basedir); strncat(compose, newpath + libx11dir_len, newsize - basedirlen); compose[newsize] = 0; @@ -532,7 +532,7 @@ winFixupPaths(void) newfp_len += newsize; if (newfp == NULL) - newfp = malloc(newfp_len + 1); + newfp = calloc(1, newfp_len + 1); else newfp = realloc(newfp, newfp_len + 1); diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c index f8664a8b3..eb30ae99f 100644 --- a/hw/xwin/glx/indirect.c +++ b/hw/xwin/glx/indirect.c @@ -843,9 +843,7 @@ glxWinCreateDrawable(ClientPtr client, DrawablePtr pDraw, XID drawId, int type, XID glxDrawId, __GLXconfig * conf) { - __GLXWinDrawable *glxPriv; - - glxPriv = malloc(sizeof *glxPriv); + __GLXWinDrawable *glxPriv = calloc(1, sizeof *glxPriv); if (glxPriv == NULL) return NULL; @@ -1969,7 +1967,7 @@ glxWinCreateConfigs(HDC hdc, glxWinScreen * screen) n++; // allocate and save - work = malloc(sizeof(GLXWinConfig)); + work = calloc(1, sizeof(GLXWinConfig)); if (NULL == work) { ErrorF("Failed to allocate GLXWinConfig\n"); break; @@ -2383,7 +2381,7 @@ glxWinCreateConfigsExt(HDC hdc, glxWinScreen * screen, PixelFormatRejectStats * n++; // allocate and save - work = malloc(sizeof(GLXWinConfig)); + work = calloc(1, sizeof(GLXWinConfig)); if (NULL == work) { ErrorF("Failed to allocate GLXWinConfig\n"); break; diff --git a/hw/xwin/winauth.c b/hw/xwin/winauth.c index 5bc5a7316..09469e0a9 100644 --- a/hw/xwin/winauth.c +++ b/hw/xwin/winauth.c @@ -81,10 +81,6 @@ GenerateAuthorization(unsigned name_length, BOOL winGenerateAuthorization(void) { -#ifdef XCSECURITY - SecurityAuthorizationPtr pAuth = NULL; -#endif - /* Call OS layer to generate authorization key */ g_authId = GenerateAuthorization(strlen(AUTH_NAME), AUTH_NAME, @@ -107,8 +103,7 @@ winGenerateAuthorization(void) #ifdef XCSECURITY /* Allocate structure for additional auth information */ - pAuth = (SecurityAuthorizationPtr) - malloc(sizeof(SecurityAuthorizationRec)); + SecurityAuthorizationPtr pAuth = calloc(1, sizeof(SecurityAuthorizationRec)); if (!(pAuth)) { ErrorF("winGenerateAuthorization - Failed allocating " "SecurityAuthorizationPtr.\n"); diff --git a/hw/xwin/winclipboard/textconv.c b/hw/xwin/winclipboard/textconv.c index 651ccc666..b2bf0f71d 100644 --- a/hw/xwin/winclipboard/textconv.c +++ b/hw/xwin/winclipboard/textconv.c @@ -100,7 +100,7 @@ winClipboardUNIXtoDOS(char **ppszData, int iLength) return; /* Allocate a new string */ - pszDestBegin = pszDest = malloc(iLength + iNewlineCount + 1); + pszDestBegin = pszDest = calloc(1, iLength + iNewlineCount + 1); /* Set source pointer to beginning of data string */ pszSrc = *ppszData; diff --git a/hw/xwin/winclipboard/xevents.c b/hw/xwin/winclipboard/xevents.c index 6a846902e..41b6d9cbc 100644 --- a/hw/xwin/winclipboard/xevents.c +++ b/hw/xwin/winclipboard/xevents.c @@ -138,7 +138,7 @@ static char *get_atom_name(xcb_connection_t *conn, xcb_atom_t atom) xcb_get_atom_name_reply_t *reply = xcb_get_atom_name_reply(conn, cookie, NULL); if (!reply) return NULL; - ret = malloc(xcb_get_atom_name_name_length(reply) + 1); + ret = calloc(1, xcb_get_atom_name_name_length(reply) + 1); if (ret) { memcpy(ret, xcb_get_atom_name_name(reply), xcb_get_atom_name_name_length(reply)); ret[xcb_get_atom_name_name_length(reply)] = '\0'; @@ -166,7 +166,7 @@ winClipboardSelectionNotifyTargets(HWND hwnd, xcb_window_t iWindow, xcb_connecti xcb_atom_t *prop = xcb_get_property_value(reply); int nitems = xcb_get_property_value_length(reply)/sizeof(xcb_atom_t); int i; - data->targetList = malloc((nitems+1)*sizeof(xcb_atom_t)); + data->targetList = calloc(nitems+1, sizeof(xcb_atom_t)); for (i = 0; i < nitems; i++) { @@ -242,8 +242,8 @@ winClipboardSelectionNotifyData(HWND hwnd, xcb_window_t iWindow, xcb_connection_ if (encoding == atoms->atomIncr) { winDebug("winClipboardSelectionNotifyData: starting INCR, anticipated size %d\n", *(int *)value); data->incrsize = 0; - data->incr = malloc(*(int *)value); - // XXX: if malloc failed, we have an error + data->incr = calloc(1, *(int *)value); + // XXX: if calloc failed, we have an error return WIN_XEVENTS_SUCCESS; } else if (data->incr) { @@ -276,23 +276,23 @@ winClipboardSelectionNotifyData(HWND hwnd, xcb_window_t iWindow, xcb_connection_ } if (xtpText_encoding == atoms->atomUTF8String) { - pszReturnData = malloc(xtpText_nitems + 1); + pszReturnData = calloc(1, xtpText_nitems + 1); memcpy(pszReturnData, xtpText_value, xtpText_nitems); pszReturnData[xtpText_nitems] = 0; codepage = CP_UTF8; // code page identifier for utf8 } else if (xtpText_encoding == XCB_ATOM_STRING) { // STRING encoding is Latin1 (ISO8859-1) plus tab and newline - pszReturnData = malloc(xtpText_nitems + 1); + pszReturnData = calloc(1, xtpText_nitems + 1); memcpy(pszReturnData, xtpText_value, xtpText_nitems); pszReturnData[xtpText_nitems] = 0; codepage = CP_ISO_8559_1; // code page identifier for iso-8559-1 } else if (xtpText_encoding == atoms->atomCompoundText) { // COMPOUND_TEXT is complex, based on ISO 2022 ErrorF("SelectionNotify: data in COMPOUND_TEXT encoding which is not implemented, discarding\n"); - pszReturnData = malloc(1); + pszReturnData = calloc(1, 1); pszReturnData[0] = '\0'; } else { // shouldn't happen as we accept no other encodings - pszReturnData = malloc(1); + pszReturnData = calloc(1, 1); pszReturnData[0] = '\0'; } @@ -314,10 +314,10 @@ winClipboardSelectionNotifyData(HWND hwnd, xcb_window_t iWindow, xcb_connection_ pszReturnData, -1, NULL, 0); /* NOTE: iUnicodeLen includes space for null terminator */ - pwszUnicodeStr = malloc(sizeof(wchar_t) * iUnicodeLen); + pwszUnicodeStr = calloc(iUnicodeLen, sizeof(wchar_t)); if (!pwszUnicodeStr) { ErrorF("winClipboardFlushXEvents - SelectionNotify " - "malloc failed for pwszUnicodeStr, aborting.\n"); + "calloc failed for pwszUnicodeStr, aborting.\n"); /* Abort */ goto winClipboardFlushXEvents_SelectionNotify_Done; @@ -551,7 +551,7 @@ winClipboardFlushXEvents(HWND hwnd, (LPCWSTR) pszGlobalData, -1, NULL, 0, NULL, NULL); /* NOTE: iConvertDataLen includes space for null terminator */ - pszConvertData = malloc(iConvertDataLen); + pszConvertData = calloc(1, iConvertDataLen); WideCharToMultiByte(codepage, 0, (LPCWSTR) pszGlobalData, -1, pszConvertData, iConvertDataLen, NULL, NULL); diff --git a/hw/xwin/wincmap.c b/hw/xwin/wincmap.c index 3567afad5..7b279f490 100644 --- a/hw/xwin/wincmap.c +++ b/hw/xwin/wincmap.c @@ -405,7 +405,6 @@ winGetPaletteDD(ScreenPtr pScreen, ColormapPtr pcmap) Pixel pixel; /* Pixel == CARD32 */ CARD16 nRed, nGreen, nBlue; /* CARD16 == unsigned short */ UINT uiSystemPaletteEntries; - LPPALETTEENTRY ppeColors = NULL; HDC hdc = NULL; /* Get a DC to obtain the default palette */ @@ -429,9 +428,9 @@ winGetPaletteDD(ScreenPtr pScreen, ColormapPtr pcmap) #endif /* Allocate palette entries structure */ - ppeColors = malloc(uiSystemPaletteEntries * sizeof(PALETTEENTRY)); + LPPALETTEENTRY ppeColors = calloc(uiSystemPaletteEntries, sizeof(PALETTEENTRY)); if (ppeColors == NULL) { - ErrorF("winGetPaletteDD - malloc () for colormap failed\n"); + ErrorF("winGetPaletteDD - calloc () for colormap failed\n"); return FALSE; } diff --git a/hw/xwin/winconfig.c b/hw/xwin/winconfig.c index 4f16b21e0..bac21d799 100644 --- a/hw/xwin/winconfig.c +++ b/hw/xwin/winconfig.c @@ -294,10 +294,9 @@ winConfigKeyboard(DeviceIntPtr pDevice) HKEY regkey = NULL; const char regtempl[] = "SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\"; - char *regpath; DWORD namesize = sizeof(layoutFriendlyName); - regpath = malloc(sizeof(regtempl) + KL_NAMELENGTH + 1); + char *regpath = calloc(1, sizeof(regtempl) + KL_NAMELENGTH + 1); strcpy(regpath, regtempl); strcat(regpath, layoutName); @@ -907,7 +906,7 @@ ParseOptionValue(int scrnIndex, void *options, OptionInfoPtr p) } else { free(n); - n = malloc(strlen(p->name) + 2 + 1); + n = calloc(1, strlen(p->name) + 2 + 1); if (!n) { p->found = FALSE; return FALSE; @@ -995,13 +994,13 @@ GetBoolValue(OptionInfoPtr p, const char *s) char * winNormalizeName(const char *s) { - char *ret, *q; + char *q; const char *p; if (s == NULL) return NULL; - ret = malloc(strlen(s) + 1); + char *ret = calloc(1, strlen(s) + 1); for (p = s, q = ret; *p != 0; p++) { switch (*p) { case '_': diff --git a/hw/xwin/wincursor.c b/hw/xwin/wincursor.c index 6b42c990e..f4f88abe0 100644 --- a/hw/xwin/wincursor.c +++ b/hw/xwin/wincursor.c @@ -150,7 +150,6 @@ winLoadCursor(ScreenPtr pScreen, CursorPtr pCursor, int screen) { winScreenPriv(pScreen); HCURSOR hCursor = NULL; - unsigned char *pAnd; unsigned char *pXor; int nCX, nCY; int nBytes; @@ -196,7 +195,7 @@ winLoadCursor(ScreenPtr pScreen, CursorPtr pCursor, int screen) nCY = min(pScreenPriv->cursor.sm_cy, pCursor->bits->height); /* Allocate memory for the bitmaps */ - pAnd = malloc(nBytes); + unsigned char *pAnd = calloc(1, nBytes); memset(pAnd, 0xFF, nBytes); pXor = calloc(1, nBytes); diff --git a/hw/xwin/winmouse.c b/hw/xwin/winmouse.c index 52166a850..2e8f56d34 100644 --- a/hw/xwin/winmouse.c +++ b/hw/xwin/winmouse.c @@ -66,7 +66,6 @@ winMouseProc(DeviceIntPtr pDeviceInt, int iState) { int lngMouseButtons, i; int lngWheelEvents = 4; - CARD8 *map; DevicePtr pDevice = (DevicePtr) pDeviceInt; Atom btn_labels[9]; Atom axes_labels[2]; @@ -98,7 +97,7 @@ winMouseProc(DeviceIntPtr pDeviceInt, int iState) /* allocate memory: * number of buttons + 4 x mouse wheel event + 1 extra (offset for map) */ - map = malloc(sizeof(CARD8) * (lngMouseButtons + lngWheelEvents + 1)); + CARD8 *map = calloc(lngMouseButtons + lngWheelEvents + 1, sizeof(CARD8)); /* initialize button map */ map[0] = 0; diff --git a/hw/xwin/winmultiwindowclass.c b/hw/xwin/winmultiwindowclass.c index 0d5ce3b1c..667858a14 100644 --- a/hw/xwin/winmultiwindowclass.c +++ b/hw/xwin/winmultiwindowclass.c @@ -68,7 +68,7 @@ winMultiWindowGetClassHint(WindowPtr pWin, char **res_name, char **res_class) len_name = strlen((char *) prop->data); if (len_name > prop->size) len_name = prop->size; - (*res_name) = malloc(len_name + 1); + (*res_name) = calloc(1, len_name + 1); if (!*res_name) { ErrorF("winMultiWindowGetClassHint - *res_name was NULL\n"); @@ -83,7 +83,7 @@ winMultiWindowGetClassHint(WindowPtr pWin, char **res_name, char **res_class) len_class = (len_name >= prop->size) ? 0 : (strlen(((char *) prop->data) + 1 + len_name)); if (len_class > prop->size - 1 - len_name) len_class = prop->size - 1 - len_name; - (*res_class) = malloc(len_class + 1); + (*res_class) = calloc(1, len_class + 1); if (!*res_class) { ErrorF("winMultiWindowGetClassHint - *res_class was NULL\n"); @@ -146,7 +146,7 @@ winMultiWindowGetWindowRole(WindowPtr pWin, char **res_role) && prop->type == XA_STRING && prop->format == 8 && prop->data) { len_role = prop->size; - (*res_role) = malloc(len_role + 1); + (*res_role) = calloc(1, len_role + 1); if (!*res_role) { ErrorF("winMultiWindowGetWindowRole - *res_role was NULL\n"); @@ -235,7 +235,7 @@ winMultiWindowGetWMName(WindowPtr pWin, char **wmName) && prop->type == XA_STRING && prop->data) { len_name = prop->size; - (*wmName) = malloc(len_name + 1); + (*wmName) = calloc(1, len_name + 1); if (!*wmName) { ErrorF("winMultiWindowGetWMName - *wmName was NULL\n"); diff --git a/hw/xwin/winmultiwindowicons.c b/hw/xwin/winmultiwindowicons.c index e5b09e48d..834a6fea9 100644 --- a/hw/xwin/winmultiwindowicons.c +++ b/hw/xwin/winmultiwindowicons.c @@ -513,9 +513,9 @@ winXIconToHICON(xcb_connection_t *conn, xcb_window_t id, int iconSize) /* Mask is 1-bit deep */ maskStride = ((iconSize * 1 + 15) & (~15)) / 8; - image = malloc(stride * iconSize); - imageMask = malloc(stride * iconSize); - mask = malloc(maskStride * iconSize); + image = calloc(stride, iconSize); + imageMask = calloc(stride, iconSize); + mask = calloc(maskStride, iconSize); /* Default to a completely black mask */ memset(imageMask, 0, stride * iconSize); diff --git a/hw/xwin/winmultiwindowwindow.c b/hw/xwin/winmultiwindowwindow.c index 7c7a5d2d6..e50a93a9b 100644 --- a/hw/xwin/winmultiwindowwindow.c +++ b/hw/xwin/winmultiwindowwindow.c @@ -872,13 +872,12 @@ winAdjustXWindow(WindowPtr pWin, HWND hwnd) static HBITMAP winCreateDIB(ScreenPtr pScreen, int width, int height, int bpp, void **ppvBits, BITMAPINFOHEADER **ppbmih) { winScreenPriv(pScreen); - BITMAPV4HEADER *pbmih = NULL; HBITMAP hBitmap = NULL; /* Allocate bitmap info header */ - pbmih = malloc(sizeof(BITMAPV4HEADER) + 256 * sizeof(RGBQUAD)); + BITMAPV4HEADER *pbmih = calloc(1, sizeof(BITMAPV4HEADER) + 256 * sizeof(RGBQUAD)); if (pbmih == NULL) { - ErrorF("winCreateDIB: malloc() failed\n"); + ErrorF("winCreateDIB: calloc() failed\n"); return NULL; } memset(pbmih, 0, sizeof(BITMAPV4HEADER) + 256 * sizeof(RGBQUAD)); diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c index 2d5ebc2f5..ca0cbddf2 100644 --- a/hw/xwin/winmultiwindowwm.c +++ b/hw/xwin/winmultiwindowwm.c @@ -458,7 +458,7 @@ GetWindowName(WMInfoPtr pWMInfo, xcb_window_t iWin, char **ppWindowName) (strstr(pszWindowName, pszClientHostname) == 0)) { /* ... add '@' to end of window name */ *ppWindowName = - malloc(strlen(pszWindowName) + + calloc(1, strlen(pszWindowName) + strlen(pszClientMachine) + 2); strcpy(*ppWindowName, pszWindowName); strcat(*ppWindowName, "@"); @@ -634,8 +634,7 @@ UpdateName(WMInfoPtr pWMInfo, xcb_window_t iWindow) /* Convert from UTF-8 to wide char */ int iLen = MultiByteToWideChar(CP_UTF8, 0, pszWindowName, -1, NULL, 0); - wchar_t *pwszWideWindowName = - malloc(sizeof(wchar_t)*(iLen + 1)); + wchar_t *pwszWideWindowName = calloc(iLen + 1, sizeof(wchar_t)); MultiByteToWideChar(CP_UTF8, 0, pszWindowName, -1, pwszWideWindowName, iLen); @@ -1401,7 +1400,7 @@ winInitWM(void **ppWMInfo, /* Bail if the input parameters are bad */ if (pArg == NULL || pWMInfo == NULL || pXMsgArg == NULL) { - ErrorF("winInitWM - malloc failed.\n"); + ErrorF("winInitWM - calloc failed.\n"); free(pArg); free(pWMInfo); free(pXMsgArg); @@ -1629,13 +1628,12 @@ winInitMultiWindowWM(WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) void winSendMessageToWM(void *pWMInfo, winWMMessagePtr pMsg) { - WMMsgNodePtr pNode; #if ENABLE_DEBUG ErrorF("winSendMessageToWM %s\n", MessageName(pMsg)); #endif - pNode = malloc(sizeof(WMMsgNodeRec)); + WMMsgNodePtr pNode = calloc(1, sizeof(WMMsgNodeRec)); if (pNode != NULL) { memcpy(&pNode->msg, pMsg, sizeof(winWMMessageRec)); PushMessage(&((WMInfoPtr) pWMInfo)->wmMsgQueue, pNode); diff --git a/hw/xwin/winprefs.c b/hw/xwin/winprefs.c index 8cf45fd51..75ecab9dc 100644 --- a/hw/xwin/winprefs.c +++ b/hw/xwin/winprefs.c @@ -541,7 +541,7 @@ LoadImageComma(char *fname, char *iconDirectory, int sx, int sy, int flags) MAKEINTRESOURCE(i), IMAGE_ICON, sx, sy, flags); } else { - char *file = malloc(PATH_MAX + NAME_MAX + 2); + char *file = calloc(1, PATH_MAX + NAME_MAX + 2); #ifdef __CYGWIN__ Bool convert = FALSE; #endif @@ -752,7 +752,7 @@ LoadPreferences(void) /* Setup a DISPLAY environment variable, need to allocate on heap */ /* because putenv doesn't copy the argument... */ winGetDisplayName(szDisplay, 0); - szEnvDisplay = (char *) (malloc(strlen(szDisplay) + strlen("DISPLAY=") + 1)); + szEnvDisplay = calloc(1, strlen(szDisplay) + strlen("DISPLAY=") + 1); if (szEnvDisplay) { snprintf(szEnvDisplay, 512, "DISPLAY=%s", szDisplay); putenv(szEnvDisplay); diff --git a/hw/xwin/winprefslex.l b/hw/xwin/winprefslex.l index 9e6f0d6d4..035204f29 100644 --- a/hw/xwin/winprefslex.l +++ b/hw/xwin/winprefslex.l @@ -42,8 +42,7 @@ extern void ErrorF (const char* /*f*/, ...); /* Copy the parsed string, must be free()d in yacc parser */ static char *makestr(char *str) { - char *ptr; - ptr = malloc(strlen(str)+1); + char *ptr = calloc(1, strlen(str)+1); if (!ptr) { ErrorF ("winMultiWindowLex:makestr() out of memory\n"); diff --git a/hw/xwin/winprefsyacc.y b/hw/xwin/winprefsyacc.y index 9bb28ae92..4f2391149 100644 --- a/hw/xwin/winprefsyacc.y +++ b/hw/xwin/winprefsyacc.y @@ -310,7 +310,7 @@ static void AddMenuLine (const char *text, MENUCOMMANDTYPE cmd, const char *param) { if (menu.menuItem==NULL) - menu.menuItem = malloc(sizeof(MENUITEM)); + menu.menuItem = calloc(1, sizeof(MENUITEM)); else menu.menuItem = realloc(menu.menuItem, sizeof(MENUITEM)*(menu.menuItems+1)); @@ -339,7 +339,7 @@ CloseMenu (void) if (pref.menuItems) pref.menu = realloc (pref.menu, (pref.menuItems+1)*sizeof(MENUPARSED)); else - pref.menu = malloc (sizeof(MENUPARSED)); + pref.menu = calloc(1, sizeof(MENUPARSED)); memcpy (pref.menu+pref.menuItems, &menu, sizeof(MENUPARSED)); pref.menuItems++; @@ -362,7 +362,7 @@ static void AddIconLine (char *matchstr, char *iconfile) { if (pref.icon==NULL) - pref.icon = malloc(sizeof(ICONITEM)); + pref.icon = calloc(1, sizeof(ICONITEM)); else pref.icon = realloc(pref.icon, sizeof(ICONITEM)*(pref.iconItems+1)); @@ -397,7 +397,7 @@ static void AddStyleLine (char *matchstr, unsigned long style) { if (pref.style==NULL) - pref.style = malloc(sizeof(STYLEITEM)); + pref.style = calloc(1, sizeof(STYLEITEM)); else pref.style = realloc(pref.style, sizeof(STYLEITEM)*(pref.styleItems+1)); @@ -429,7 +429,7 @@ static void AddSysMenuLine (char *matchstr, char *menuname, int pos) { if (pref.sysMenu==NULL) - pref.sysMenu = malloc(sizeof(SYSMENUITEM)); + pref.sysMenu = calloc(1, sizeof(SYSMENUITEM)); else pref.sysMenu = realloc(pref.sysMenu, sizeof(SYSMENUITEM)*(pref.sysMenuItems+1)); diff --git a/hw/xwin/winprocarg.c b/hw/xwin/winprocarg.c index d87c40936..56280c232 100644 --- a/hw/xwin/winprocarg.c +++ b/hw/xwin/winprocarg.c @@ -1123,7 +1123,7 @@ winLogCommandLine(int argc, char *argv[]) } /* Allocate memory for concatenated command line */ - g_pszCommandLine = malloc(iSize + 1); + g_pszCommandLine = calloc(1, iSize + 1); if (!g_pszCommandLine) FatalError("winLogCommandLine - Could not allocate memory for " "command line string. Exiting.\n"); diff --git a/hw/xwin/winrandr.c b/hw/xwin/winrandr.c index 0ea235136..262da9fce 100644 --- a/hw/xwin/winrandr.c +++ b/hw/xwin/winrandr.c @@ -266,14 +266,14 @@ winRandRInit(ScreenPtr pScreen) output->crtc = crtc; /* Set crtc outputs (should use RRCrtcNotify?) */ - crtc->outputs = malloc(sizeof(RROutputPtr)); + crtc->outputs = calloc(1, sizeof(RROutputPtr)); crtc->outputs[0] = output; crtc->numOutputs = 1; pRRScrPriv->primaryOutput = output; /* Ensure we have space for exactly one mode */ - output->modes = malloc(sizeof(RRModePtr)); + output->modes = calloc(1, sizeof(RRModePtr)); output->modes[0] = NULL; /* Set mode to current display size */ diff --git a/hw/xwin/winshadgdi.c b/hw/xwin/winshadgdi.c index 970ce9550..cf8391413 100644 --- a/hw/xwin/winshadgdi.c +++ b/hw/xwin/winshadgdi.c @@ -151,7 +151,6 @@ static winQueryRGBBitsAndMasks(ScreenPtr pScreen) { winScreenPriv(pScreen); - BITMAPINFOHEADER *pbmih = NULL; Bool fReturn = TRUE; LPDWORD pdw = NULL; DWORD dwRedBits, dwGreenBits, dwBlueBits; @@ -187,9 +186,9 @@ winQueryRGBBitsAndMasks(ScreenPtr pScreen) } /* Allocate a bitmap header and color table */ - pbmih = malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); + BITMAPINFOHEADER *pbmih = calloc(1, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); if (pbmih == NULL) { - ErrorF("winQueryRGBBitsAndMasks - malloc failed\n"); + ErrorF("winQueryRGBBitsAndMasks - calloc failed\n"); return FALSE; } @@ -541,9 +540,9 @@ winInitScreenShadowGDI(ScreenPtr pScreen) pScreenPriv->hdcShadow = CreateCompatibleDC(pScreenPriv->hdcScreen); /* Allocate bitmap info header */ - pScreenPriv->pbmih = malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); + pScreenPriv->pbmih = calloc(1, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); if (pScreenPriv->pbmih == NULL) { - ErrorF("winInitScreenShadowGDI - malloc () failed\n"); + ErrorF("winInitScreenShadowGDI - calloc () failed\n"); return FALSE; }