Use calloc() instead of malloc() followed by memset to 0. Bug 124302, patch by

Aaron Lehmann <aaronl@vitelus.com>, r=timeless, sr=bzbarsky


git-svn-id: svn://10.0.0.236/trunk@134212 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bzbarsky%mit.edu
2002-11-20 23:13:09 +00:00
parent cdcb47665c
commit b549c5800b
12 changed files with 21 additions and 53 deletions

View File

@@ -707,15 +707,13 @@ void add_macro(char *pString, macro_list **ppList)
/* Allocate a new list entry for the macro.
*/
pEntry = (macro_list *)malloc(sizeof(macro_list));
memset(pEntry, 0, sizeof(macro_list));
pEntry = (macro_list *)calloc(1, sizeof(macro_list));
/* Very first part of the string is the macro name.
* How long is it?
*/
iLength = macro_length(pString);
pEntry->m_pMacro = (char *)malloc(iLength + 1);
memset(pEntry->m_pMacro, 0, iLength + 1);
pEntry->m_pMacro = (char *)calloc(iLength + 1, 1);
strncpy(pEntry->m_pMacro, pString, iLength);
/* Skip to the values.
@@ -803,11 +801,9 @@ void add_values(char *pString, char_list **ppList)
/* Allocate a new list entry for the next value.
*/
pEntry = (char_list *)malloc(sizeof(char_list));
memset(pEntry, 0, sizeof(char_list));
pEntry = (char_list *)calloc(1, sizeof(char_list));
pEntry->m_pString = (char *)malloc(iLength + 1);
memset(pEntry->m_pString, 0, iLength + 1);
pEntry->m_pString = (char *)calloc(iLength + 1, 1);
strncpy(pEntry->m_pString, pString, iLength);
/* Add new value entry to the end of the list.

View File

@@ -79,8 +79,7 @@ NSRESHANDLE NSResCreateTable(const char *filename, NSRESTHREADINFO *threadinfo)
flag = O_RDWR | O_CREAT;
hres = (RESHANDLE) malloc ( sizeof(struct RESDATABASE) );
memset(hres, 0, sizeof(struct RESDATABASE));
hres = (RESHANDLE) calloc ( 1, sizeof(struct RESDATABASE) );
if (threadinfo && threadinfo->lock && threadinfo->fn_lock
&& threadinfo->fn_unlock)
@@ -111,8 +110,7 @@ NSRESHANDLE NSResOpenTable(const char *filename, NSRESTHREADINFO *threadinfo)
flag = O_RDONLY; /* only open database for reading */
hres = (RESHANDLE) malloc ( sizeof(struct RESDATABASE) );
memset(hres, 0, sizeof(struct RESDATABASE));
hres = (RESHANDLE) calloc ( 1, sizeof(struct RESDATABASE) );
if (threadinfo && threadinfo->lock && threadinfo->fn_lock
&& threadinfo->fn_unlock)

View File

@@ -104,8 +104,7 @@ _OpenURL(NPP npp, const char *szURL, const char *szTarget, void *pNotifyData, co
USES_CONVERSION;
DWORD cbNewURL = (url.Length() + bstrCurrentURL.Length() + 1) * sizeof(WCHAR);
DWORD cbNewURLUsed = 0;
WCHAR *pszNewURL = (WCHAR *) malloc(cbNewURL);
memset(pszNewURL, 0, cbNewURL);
WCHAR *pszNewURL = (WCHAR *) calloc(cbNewURL, 1);
ATLASSERT(pszNewURL);
CoInternetCombineUrl(

View File

@@ -437,8 +437,7 @@ xxlib_rgb_make_colorcube (XlibRgbHandle *handle, unsigned long *pixels, int nr,
unsigned char rt[16], gt[16], bt[16];
int i;
handle->colorcube = malloc(sizeof(unsigned char) * 4096);
memset(handle->colorcube, 0, (sizeof(unsigned char) * 4096));
handle->colorcube = calloc(4096, 1);
for (i = 0; i < 16; i++)
{
rt[i] = ng * nb * ((i * 17 * (nr - 1) + 128) >> 8);
@@ -462,8 +461,7 @@ xxlib_rgb_make_colorcube_d (XlibRgbHandle *handle, unsigned long *pixels, int nr
int r, g, b;
int i;
handle->colorcube_d = malloc(sizeof(unsigned char) * 512);
memset(handle->colorcube_d, 0, (sizeof(unsigned char) * 512));
handle->colorcube_d = calloc(512, 1);
for (i = 0; i < 512; i++)
{
r = MIN (nr - 1, i >> 6);

View File

@@ -374,8 +374,7 @@ main (int argc, char **argv)
PR_Init("mimefilt", 24, 1, 0);
cdb_handle = (CERTCertDBHandle *) malloc(sizeof(*cdb_handle));
memset(cdb_handle, 0, sizeof(*cdb_handle));
cdb_handle = (CERTCertDBHandle *) calloc(1, sizeof(*cdb_handle));
if (SECSuccess != CERT_OpenCertDB(cdb_handle, PR_FALSE, test_cdb_name_cb, NULL))
CERT_OpenVolatileCertDB(cdb_handle);

View File

@@ -117,8 +117,7 @@ Init () {
gDesc = RDF_GetResource("Description", 1);
gEditor = RDF_GetResource("editor", 1);
gNewsGroup = RDF_GetResource("newsGroup", 1);
gTemplate = (char*) malloc(MAX_TEMPLATE_SIZE+1);
memset(gTemplate, '\0', MAX_TEMPLATE_SIZE);
gTemplate = (char*) calloc(MAX_TEMPLATE_SIZE+1, 1);
n = fread(gTemplate, 1, MAX_TEMPLATE_SIZE, templateFile);
gTemplate[n] = '\0';
fclose(templateFile);
@@ -226,19 +225,6 @@ void describeCategory (WriteClientProc callBack, void* obj, RDF_Resource u) {
#define MRN 1000
char*
xGetMem (size_t n) {
char* ans = (char*) malloc(n);
if (ans) memset(ans, '\0', n);
return ans;
}
void
xFreeMem(void* item) {
free(item);
}
RDF_Resource
stToProp (char c) {
if (!c || (c == 'a')) {
@@ -260,8 +246,8 @@ AnswerSearchQuery (WriteClientProc callBack, void* obj, char *query, char* cooki
size_t catn = 0;
size_t itemn = 0;
size_t index;
RDF_Resource* cats = (RDF_Resource*)xGetMem(sizeof(RDF_Resource) * (MRN + 1));
RDF_Resource* items = (RDF_Resource*)xGetMem(sizeof(RDF_Resource) * (MRN + 1));
RDF_Resource* cats = (RDF_Resource*)calloc(MRN+1, sizeof(RDF_Resource));
RDF_Resource* items = (RDF_Resource*)calloc(MRN+1, sizeof(RDF_Resource));
char showDesc = cookiePropValue(cookie, "searchDesc");
(*callBack)(obj, PREFIX);
@@ -302,8 +288,8 @@ AnswerSearchQuery (WriteClientProc callBack, void* obj, char *query, char* cooki
(*callBack)(obj, "</UL>");
}
xFreeMem(items);
xFreeMem(cats);
free(items);
free(cats);
}

View File

@@ -178,9 +178,7 @@ startsWith (const char* pattern, const char* uuid) {
char*
getMem (size_t n) {
char* ans = (char*) malloc(n);
if (ans) memset(ans, '\0', n);
return ans;
return (char*) calloc(1, n);
}
void

View File

@@ -119,9 +119,7 @@ startsWith (const char* pattern, const char* uuid)
char*
getMem (size_t n) {
char* ans = (char*) malloc(n);
if (ans) memset(ans, '\0', n);
return ans;
return (char*) calloc(1, n);
}
void

View File

@@ -43,8 +43,7 @@
#include <stdio.h>
void main () {
char* nextQuery = malloc(200);
memset(nextQuery, '\0', 200);
char* nextQuery = calloc(200, sizeof(char));
RDF_Initialize();
while (1) {
int n;

View File

@@ -156,8 +156,7 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval)
filedlg.fl |= FDS_OPEN_DIALOG;
}
PMYDATA pmydata;
pmydata = (PMYDATA)malloc(sizeof(MYDATA));
memset(pmydata, 0, sizeof(MYDATA));
pmydata = (PMYDATA)calloc(1, sizeof(MYDATA));
filedlg.ulUser = (ULONG)pmydata;
filedlg.pfnDlgProc = FileDialogProc;

View File

@@ -579,8 +579,7 @@ nsXIEngine::ParseURL(char *aURL, char **aHost, char **aDir)
hostTerminator = strchr(host, '/');
if (!hostTerminator) return E_BAD_FTP_URL;
*aHost = (char *) malloc(sizeof(char) * (hostTerminator - host + 1));
memset(*aHost, 0, (hostTerminator - host + 1));
*aHost = (char *) calloc(hostTerminator - host + 1, 1);
strncpy(*aHost, host, hostTerminator - host);
dirTerminator = strrchr(hostTerminator + 1, '/');

View File

@@ -392,8 +392,7 @@ int ParseArgumentList(struct Params *ArgList, int argc, char *argv[])
ArgList->Sector = -1;
ArgList->SuppressHeader = 0;
ArgList->AutoInfoFormat = 0;
ArgList->DirName = (char *)malloc(sizeof(char)*MAX_BUF);
memset(ArgList->DirName, 0, MAX_BUF);
ArgList->DirName = (char *)calloc(MAX_BUF, 1);
for(i = 1; i < argc; i++)
{