зеркало из https://github.com/mozilla/pjs.git
Use calloc() instead of malloc() followed by memset to 0. Bug 124302, patch by
Aaron Lehmann <aaronl@vitelus.com>, r=timeless, sr=bzbarsky
This commit is contained in:
Родитель
b1264437f8
Коммит
e43c4fe666
|
@ -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.
|
||||
|
|
307
dbm/src/nsres.c
307
dbm/src/nsres.c
|
@ -1,307 +0,0 @@
|
|||
#include "watcomfx.h"
|
||||
|
||||
#include "nsres.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
struct RESDATABASE
|
||||
{
|
||||
DB *hdb;
|
||||
NSRESTHREADINFO *threadinfo;
|
||||
char * pbuf[MAXBUFNUM];
|
||||
} ;
|
||||
typedef struct RESDATABASE * RESHANDLE;
|
||||
|
||||
typedef struct STRINGDATA
|
||||
{
|
||||
char *str;
|
||||
unsigned int charsetid;
|
||||
} STRINGDATA;
|
||||
|
||||
|
||||
typedef unsigned int CHARSETTYPE;
|
||||
#define RES_LOCK if (hres->threadinfo) hres->threadinfo->fn_lock(hres->threadinfo->lock);
|
||||
#define RES_UNLOCK if (hres->threadinfo) hres->threadinfo->fn_unlock(hres->threadinfo->lock);
|
||||
|
||||
int GenKeyData(const char *library, int32 id, DBT *key);
|
||||
|
||||
/*
|
||||
Right now, the page size used for resource is same as for Navigator cache
|
||||
database
|
||||
*/
|
||||
HASHINFO res_hash_info = {
|
||||
32*1024,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0, /* 64 * 1024U */
|
||||
0};
|
||||
|
||||
int GenKeyData(const char *library, int32 id, DBT *key)
|
||||
{
|
||||
char idstr[10];
|
||||
static char * strdata = NULL;
|
||||
size_t len;
|
||||
|
||||
if (strdata)
|
||||
free (strdata);
|
||||
|
||||
if (id == 0)
|
||||
idstr[0] = '\0';
|
||||
else
|
||||
{
|
||||
sprintf(idstr, "%d", id);
|
||||
/* itoa(id, idstr, 10); */
|
||||
}
|
||||
|
||||
if (library == NULL)
|
||||
len = strlen(idstr) + 1;
|
||||
else
|
||||
len = strlen(library) + strlen(idstr) + 1;
|
||||
strdata = (char *) malloc (len);
|
||||
strcpy(strdata, library);
|
||||
strcat(strdata, idstr);
|
||||
|
||||
key->size = len;
|
||||
key->data = strdata;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
NSRESHANDLE NSResCreateTable(const char *filename, NSRESTHREADINFO *threadinfo)
|
||||
{
|
||||
RESHANDLE hres;
|
||||
int flag;
|
||||
|
||||
flag = O_RDWR | O_CREAT;
|
||||
|
||||
hres = (RESHANDLE) malloc ( sizeof(struct RESDATABASE) );
|
||||
memset(hres, 0, sizeof(struct RESDATABASE));
|
||||
|
||||
if (threadinfo && threadinfo->lock && threadinfo->fn_lock
|
||||
&& threadinfo->fn_unlock)
|
||||
{
|
||||
hres->threadinfo = (NSRESTHREADINFO *) malloc( sizeof(NSRESTHREADINFO) );
|
||||
hres->threadinfo->lock = threadinfo->lock;
|
||||
hres->threadinfo->fn_lock = threadinfo->fn_lock;
|
||||
hres->threadinfo->fn_unlock = threadinfo->fn_unlock;
|
||||
}
|
||||
|
||||
|
||||
RES_LOCK
|
||||
|
||||
hres->hdb = dbopen(filename, flag, 0644, DB_HASH, &res_hash_info);
|
||||
|
||||
RES_UNLOCK
|
||||
|
||||
if(!hres->hdb)
|
||||
return NULL;
|
||||
|
||||
return (NSRESHANDLE) hres;
|
||||
}
|
||||
|
||||
NSRESHANDLE NSResOpenTable(const char *filename, NSRESTHREADINFO *threadinfo)
|
||||
{
|
||||
RESHANDLE hres;
|
||||
int flag;
|
||||
|
||||
flag = O_RDONLY; /* only open database for reading */
|
||||
|
||||
hres = (RESHANDLE) malloc ( sizeof(struct RESDATABASE) );
|
||||
memset(hres, 0, sizeof(struct RESDATABASE));
|
||||
|
||||
if (threadinfo && threadinfo->lock && threadinfo->fn_lock
|
||||
&& threadinfo->fn_unlock)
|
||||
{
|
||||
hres->threadinfo = (NSRESTHREADINFO *) malloc( sizeof(NSRESTHREADINFO) );
|
||||
hres->threadinfo->lock = threadinfo->lock;
|
||||
hres->threadinfo->fn_lock = threadinfo->fn_lock;
|
||||
hres->threadinfo->fn_unlock = threadinfo->fn_unlock;
|
||||
}
|
||||
|
||||
|
||||
RES_LOCK
|
||||
|
||||
hres->hdb = dbopen(filename, flag, 0644, DB_HASH, &res_hash_info);
|
||||
|
||||
RES_UNLOCK
|
||||
|
||||
if(!hres->hdb)
|
||||
return NULL;
|
||||
|
||||
return (NSRESHANDLE) hres;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void NSResCloseTable(NSRESHANDLE handle)
|
||||
{
|
||||
RESHANDLE hres;
|
||||
int i;
|
||||
|
||||
if (handle == NULL)
|
||||
return;
|
||||
hres = (RESHANDLE) handle;
|
||||
|
||||
RES_LOCK
|
||||
|
||||
(*hres->hdb->sync)(hres->hdb, 0);
|
||||
(*hres->hdb->close)(hres->hdb);
|
||||
|
||||
RES_UNLOCK
|
||||
|
||||
for (i = 0; i < MAXBUFNUM; i++)
|
||||
{
|
||||
if (hres->pbuf[i])
|
||||
free (hres->pbuf[i]);
|
||||
}
|
||||
|
||||
if (hres->threadinfo)
|
||||
free (hres->threadinfo);
|
||||
free (hres);
|
||||
}
|
||||
|
||||
|
||||
char *NSResLoadString(NSRESHANDLE handle, const char * library, int32 id,
|
||||
unsigned int charsetid, char *retbuf)
|
||||
{
|
||||
int status;
|
||||
RESHANDLE hres;
|
||||
DBT key, data;
|
||||
if (handle == NULL)
|
||||
return NULL;
|
||||
|
||||
hres = (RESHANDLE) handle;
|
||||
GenKeyData(library, id, &key);
|
||||
|
||||
RES_LOCK
|
||||
|
||||
status = (*hres->hdb->get)(hres->hdb, &key, &data, 0);
|
||||
|
||||
RES_UNLOCK
|
||||
|
||||
if (retbuf)
|
||||
{
|
||||
memcpy(retbuf, (char *)data.data + sizeof(CHARSETTYPE), data.size - sizeof(CHARSETTYPE));
|
||||
return retbuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
static int WhichString = 0;
|
||||
static int bFirstTime = 1;
|
||||
char *szLoadedString;
|
||||
int i;
|
||||
|
||||
RES_LOCK
|
||||
|
||||
if (bFirstTime) {
|
||||
for (i = 0; i < MAXBUFNUM; i++)
|
||||
hres->pbuf[i] = (char *) malloc(MAXSTRINGLEN * sizeof(char));
|
||||
bFirstTime = 0;
|
||||
}
|
||||
|
||||
szLoadedString = hres->pbuf[WhichString];
|
||||
WhichString++;
|
||||
|
||||
/* reset to 0, if WhichString reaches to the end */
|
||||
if (WhichString == MAXBUFNUM)
|
||||
WhichString = 0;
|
||||
|
||||
if (status == 0)
|
||||
memcpy(szLoadedString, (char *) data.data + sizeof(CHARSETTYPE),
|
||||
data.size - sizeof(CHARSETTYPE));
|
||||
else
|
||||
szLoadedString[0] = 0;
|
||||
|
||||
RES_UNLOCK
|
||||
|
||||
return szLoadedString;
|
||||
}
|
||||
}
|
||||
|
||||
int32 NSResGetSize(NSRESHANDLE handle, const char *library, int32 id)
|
||||
{
|
||||
int status;
|
||||
RESHANDLE hres;
|
||||
DBT key, data;
|
||||
if (handle == NULL)
|
||||
return 0;
|
||||
hres = (RESHANDLE) handle;
|
||||
GenKeyData(library, id, &key);
|
||||
|
||||
RES_LOCK
|
||||
|
||||
status = (*hres->hdb->get)(hres->hdb, &key, &data, 0);
|
||||
|
||||
RES_UNLOCK
|
||||
|
||||
return data.size - sizeof(CHARSETTYPE);
|
||||
}
|
||||
|
||||
int32 NSResLoadResource(NSRESHANDLE handle, const char *library, int32 id, char *retbuf)
|
||||
{
|
||||
int status;
|
||||
RESHANDLE hres;
|
||||
DBT key, data;
|
||||
if (handle == NULL)
|
||||
return 0;
|
||||
hres = (RESHANDLE) handle;
|
||||
GenKeyData(library, id, &key);
|
||||
|
||||
RES_LOCK
|
||||
|
||||
status = (*hres->hdb->get)(hres->hdb, &key, &data, 0);
|
||||
|
||||
RES_UNLOCK
|
||||
|
||||
if (retbuf)
|
||||
{
|
||||
memcpy(retbuf, (char *)data.data + sizeof(CHARSETTYPE), data.size - sizeof(CHARSETTYPE));
|
||||
return data.size;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NSResAddString(NSRESHANDLE handle, const char *library, int32 id,
|
||||
const char *string, unsigned int charset)
|
||||
{
|
||||
int status;
|
||||
RESHANDLE hres;
|
||||
DBT key, data;
|
||||
char * recdata;
|
||||
|
||||
if (handle == NULL)
|
||||
return 0;
|
||||
hres = (RESHANDLE) handle;
|
||||
|
||||
GenKeyData(library, id, &key);
|
||||
|
||||
data.size = sizeof(CHARSETTYPE) + (strlen(string) + 1) ;
|
||||
|
||||
recdata = (char *) malloc(data.size) ;
|
||||
|
||||
/* set charset to the first field of record data */
|
||||
*((CHARSETTYPE *)recdata) = (CHARSETTYPE)charset;
|
||||
|
||||
/* set data field */
|
||||
memcpy(recdata+sizeof(CHARSETTYPE), string, strlen(string) + 1);
|
||||
|
||||
data.data = recdata;
|
||||
|
||||
RES_LOCK
|
||||
|
||||
status = (*hres->hdb->put)(hres->hdb, &key, &data, 0);
|
||||
|
||||
|
||||
if (recdata)
|
||||
free(recdata);
|
||||
|
||||
RES_UNLOCK
|
||||
|
||||
return status;
|
||||
}
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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, '/');
|
||||
|
|
|
@ -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++)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче