Skip to content

Commit

Permalink
emalloc -> safe_emalloc
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilia Alshanetsky committed Aug 12, 2003
1 parent 3652ab6 commit 93bcd55
Show file tree
Hide file tree
Showing 30 changed files with 96 additions and 96 deletions.
30 changes: 15 additions & 15 deletions ext/db/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ char *php_dbm_fetch(dbm_info *info, char *key TSRMLS_DC)
value_datum = DBM_FETCH(dbf, key_datum);

if (value_datum.dptr) {
ret = (char *)emalloc(sizeof(char) * value_datum.dsize + 1);
ret = (char *)safe_emalloc(sizeof(char), value_datum.dsize, 1);
strncpy(ret, value_datum.dptr, value_datum.dsize);
ret[value_datum.dsize] = '\0';

Expand Down Expand Up @@ -806,7 +806,7 @@ char *php_dbm_first_key(dbm_info *info TSRMLS_DC) {
if (!ret_datum.dptr)
return NULL;

ret = (char *)emalloc((ret_datum.dsize + 1) * sizeof(char));
ret = (char *)safe_emalloc((ret_datum.dsize + 1), sizeof(char), 0);
strncpy(ret, ret_datum.dptr, ret_datum.dsize);
ret[ret_datum.dsize] = '\0';

Expand Down Expand Up @@ -873,7 +873,7 @@ char *php_dbm_nextkey(dbm_info *info, char *key TSRMLS_DC)
ret_datum = DBM_NEXTKEY(dbf, key_datum);

if (ret_datum.dptr) {
ret = (char *)emalloc(sizeof(char) * ret_datum.dsize + 1);
ret = (char *)safe_emalloc(sizeof(char), ret_datum.dsize, 1);
strncpy(ret, ret_datum.dptr, ret_datum.dsize);
ret[ret_datum.dsize] = '\0';
#if GDBM
Expand Down Expand Up @@ -935,7 +935,7 @@ datum flatfile_fetch(FILE *dbf, datum key_datum) {
char *buf;

if (flatfile_findkey(dbf, key_datum)) {
buf = emalloc((buf_size+1) * sizeof(char));
buf = safe_emalloc((buf_size+1), sizeof(char), 0);
if (fgets(buf, 15, dbf)) {
num = atoi(buf);
if (num > buf_size) {
Expand Down Expand Up @@ -963,7 +963,7 @@ int flatfile_delete(FILE *dbf, datum key_datum) {

rewind(dbf);

buf = emalloc((buf_size + 1)*sizeof(char));
buf = safe_emalloc((buf_size + 1), sizeof(char), 0);
while(!feof(dbf)) {
/* read in the length of the key name */
if (!fgets(buf, 15, dbf))
Expand Down Expand Up @@ -996,7 +996,7 @@ int flatfile_delete(FILE *dbf, datum key_datum) {
if (num > buf_size) {
buf_size+=num;
if (buf) efree(buf);
buf = emalloc((buf_size+1)*sizeof(char));
buf = safe_emalloc((buf_size+1), sizeof(char), 0);
}
/* read in the value */
num = fread(buf, sizeof(char), num, dbf);
Expand All @@ -1019,14 +1019,14 @@ int flatfile_findkey(FILE *dbf, datum key_datum) {
int size = key_datum.dsize;

rewind(dbf);
buf = emalloc((buf_size+1)*sizeof(char));
buf = safe_emalloc((buf_size+1), sizeof(char), 0);
while (!feof(dbf)) {
if (!fgets(buf, 15, dbf)) break;
num = atoi(buf);
if (num > buf_size) {
if (buf) efree(buf);
buf_size+=num;
buf = emalloc((buf_size+1)*sizeof(char));
buf = safe_emalloc((buf_size+1), sizeof(char), 0);
}
num = fread(buf, sizeof(char), num, dbf);
if (num<0) break;
Expand All @@ -1043,7 +1043,7 @@ int flatfile_findkey(FILE *dbf, datum key_datum) {
if (num > buf_size) {
if (buf) efree(buf);
buf_size+=num;
buf = emalloc((buf_size+1)*sizeof(char));
buf = safe_emalloc((buf_size+1), sizeof(char), 0);
}
num = fread(buf, sizeof(char), num, dbf);
if (num<0) break;
Expand All @@ -1062,14 +1062,14 @@ datum flatfile_firstkey(FILE *dbf) {
int buf_size=1024;

rewind(dbf);
buf.dptr = emalloc((buf_size+1)*sizeof(char));
buf.dptr = safe_emalloc((buf_size+1), sizeof(char), 0);
while(!feof(dbf)) {
if (!fgets(buf.dptr, 15, dbf)) break;
num = atoi(buf.dptr);
if (num > buf_size) {
buf_size+=num;
if (buf.dptr) efree(buf.dptr);
buf.dptr = emalloc((buf_size+1)*sizeof(char));
buf.dptr = safe_emalloc((buf_size+1), sizeof(char), 0);
}
num = fread(buf.dptr, sizeof(char), num, dbf);
if (num<0) break;
Expand All @@ -1083,7 +1083,7 @@ datum flatfile_firstkey(FILE *dbf) {
if (num > buf_size) {
buf_size+=num;
if (buf.dptr) efree(buf.dptr);
buf.dptr = emalloc((buf_size+1)*sizeof(char));
buf.dptr = safe_emalloc((buf_size+1), sizeof(char), 0);
}
num = fread(buf.dptr, sizeof(char), num, dbf);
if (num<0) break;
Expand All @@ -1102,14 +1102,14 @@ datum flatfile_nextkey(FILE *dbf) {
int buf_size=1024;

fseek(dbf, CurrentFlatFilePos, SEEK_SET);
buf.dptr = emalloc((buf_size+1)*sizeof(char));
buf.dptr = safe_emalloc((buf_size+1), sizeof(char), 0);
while(!feof(dbf)) {
if (!fgets(buf.dptr, 15, dbf)) break;
num = atoi(buf.dptr);
if (num > buf_size) {
buf_size+=num;
if (buf.dptr) efree(buf.dptr);
buf.dptr = emalloc((buf_size+1)*sizeof(char));
buf.dptr = safe_emalloc((buf_size+1), sizeof(char), 0);
}
num = fread(buf.dptr, sizeof(char), num, dbf);
if (num<0) break;
Expand All @@ -1118,7 +1118,7 @@ datum flatfile_nextkey(FILE *dbf) {
if (num > buf_size) {
buf_size+=num;
if (buf.dptr) efree(buf.dptr);
buf.dptr = emalloc((buf_size+1)*sizeof(char));
buf.dptr = safe_emalloc((buf_size+1), sizeof(char), 0);
}
num = fread(buf.dptr, sizeof(char), num, dbf);
if (num<0) break;
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ PHP_FUNCTION(dom_document_get_elements_by_tag_name)
ctxp = xmlXPathNewContext(docp);

ctxp->node = NULL;
str = (char*) emalloc((name_len+3) * sizeof(char)) ;
str = (char*) safe_emalloc((name_len+3), sizeof(char), 0) ;
sprintf(str ,"//%s",name);

xpathobjp = xmlXPathEval(str, ctxp);
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/element.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ PHP_FUNCTION(dom_element_get_elements_by_tag_name)
ctxp = xmlXPathNewContext(docp);

ctxp->node = nodep;
str = (char*) emalloc((name_len+13) * sizeof(char)) ;
str = (char*) safe_emalloc((name_len+13), sizeof(char), 0) ;
sprintf(str ,"descendant::%s",name);

xpathobjp = xmlXPathEval(str, ctxp);
Expand Down
4 changes: 2 additions & 2 deletions ext/fbsql/php_fbsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,7 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
*length = l*2+3+1;
if (value)
{
char* r = emalloc(l*2+3+1);
char* r = safe_emalloc(l, 2, 4);
r[0] = 'X';
r[1] = '\'';
for (i = 0; i < nBits / 8; i++)
Expand All @@ -2371,7 +2371,7 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
*length = l*2+3+1;
if (value)
{
char* r = emalloc(l*2+3+1);
char* r = safe_emalloc(l, 2, 1);
r[0] = 'B';
r[1] = '\'';
for (i = 0; i < nBits; i++)
Expand Down
2 changes: 1 addition & 1 deletion ext/ftp/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)

rewind(tmpfp);

ret = emalloc((lines + 1) * sizeof(char**) + size * sizeof(char*));
ret = safe_emalloc((lines + 1), sizeof(char**), size * sizeof(char*));

entry = ret;
text = (char*) (ret + lines + 1);
Expand Down
4 changes: 2 additions & 2 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ PHP_FUNCTION(imagesetstyle)
convert_to_array_ex(styles);

/* copy the style values in the stylearr */
stylearr = emalloc(sizeof(int) * zend_hash_num_elements(HASH_OF(*styles)));
stylearr = safe_emalloc(sizeof(int), zend_hash_num_elements(HASH_OF(*styles)), 0);

zend_hash_internal_pointer_reset_ex(HASH_OF(*styles), &pos);

Expand Down Expand Up @@ -2572,7 +2572,7 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
RETURN_FALSE;
}

points = (gdPointPtr) emalloc(npoints * sizeof(gdPoint));
points = (gdPointPtr) safe_emalloc(npoints, sizeof(gdPoint), 0);

for (i = 0; i < npoints; i++) {
if (zend_hash_index_find(Z_ARRVAL_PP(POINTS), (i * 2), (void **) &var) == SUCCESS) {
Expand Down
4 changes: 2 additions & 2 deletions ext/gd/libgd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,7 @@ void gdImageFill(gdImagePtr im, int x, int y, int nc)
oc = gdImageGetPixel(im, x, y);
if (oc==nc || x<0 || x>wx2 || y<0 || y>wy2) return;

stack = (struct seg *)emalloc(sizeof(struct seg) * ((int)(im->sy*im->sx)/4)+1);
stack = (struct seg *)safe_emalloc(sizeof(struct seg), ((int)(im->sy*im->sx)/4), 1);
sp = stack;

/* required! */
Expand Down Expand Up @@ -1938,7 +1938,7 @@ void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc)
pts[i] = (int *) ecalloc(im->sx, sizeof(int));
}

stack = (struct seg *)emalloc(sizeof(struct seg) * ((int)(im->sy*im->sx)/4)+1);
stack = (struct seg *)safe_emalloc(sizeof(struct seg), ((int)(im->sy*im->sx)/4), 1);
sp = stack;

oc = gdImageGetPixel(im, x, y);
Expand Down
6 changes: 3 additions & 3 deletions ext/imap/php_imap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ PHP_FUNCTION(imap_list_full)
}

array_init(return_value);
delim = emalloc(2 * sizeof(char));
delim = safe_emalloc(2, sizeof(char), 0);
cur=IMAPG(imap_folder_objects);
while (cur != NIL) {
MAKE_STD_ZVAL(mboxob);
Expand Down Expand Up @@ -1654,7 +1654,7 @@ PHP_FUNCTION(imap_lsub_full)
convert_to_string_ex(ref);
convert_to_string_ex(pat);

delim = emalloc(2 * sizeof(char));
delim = safe_emalloc(2, sizeof(char), 0);

/* set flag for new, improved array of objects list */
IMAPG(folderlist_style) = FLIST_OBJECT;
Expand Down Expand Up @@ -3551,7 +3551,7 @@ PHP_FUNCTION(imap_mime_header_decode)
string = Z_STRVAL_PP(str);
end = Z_STRLEN_PP(str);

charset = (char *) emalloc((end + 1) * 2);
charset = (char *) safe_emalloc((end + 1), 2, 0);
text = &charset[end + 1];
while (offset < end) { /* Reached end of the string? */
if ((charset_token = (long)php_memnstr(&string[offset], "=?", 2, string + end))) { /* Is there anything encoded in the string? */
Expand Down
2 changes: 1 addition & 1 deletion ext/ingres_ii/ii.c
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ static void php_ii_fetch(INTERNAL_FUNCTION_PARAMETERS, II_LINK *ii_link, int res
}

/* allocate memory for j fields */
columnData = (IIAPI_DATAVALUE *) emalloc(j * sizeof(IIAPI_DATAVALUE));
columnData = (IIAPI_DATAVALUE *) safe_emalloc(j, sizeof(IIAPI_DATAVALUE), 0);
for (k = 1; k <= j; k++) {
columnData[k - 1].dv_value = (II_PTR) emalloc((ii_link->descriptor[i + k - 2]).ds_length);
}
Expand Down
18 changes: 9 additions & 9 deletions ext/interbase/interbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ static void _php_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
WRONG_PARAM_COUNT;
}

args = (zval ***) emalloc(sizeof(zval **) * ZEND_NUM_ARGS());
args = (zval ***) safe_emalloc(sizeof(zval **), ZEND_NUM_ARGS());
if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
efree(args);
RETURN_FALSE;
Expand Down Expand Up @@ -1084,7 +1084,7 @@ static int _php_ibase_alloc_array(ibase_array **ib_arrayp, int *array_cntp, XSQL

if (ar_cnt) { /* have arrays ? */
*array_cntp = ar_cnt;
IB_ARRAY = emalloc(sizeof(ibase_array)*ar_cnt);
IB_ARRAY = safe_emalloc(sizeof(ibase_array), ar_cnt, 0);
ar_cnt = 0;
var = sqlda->sqlvar;
for (i = 0; i < sqlda->sqld; i++, var++) {
Expand Down Expand Up @@ -1471,10 +1471,10 @@ static void _php_ibase_alloc_xsqlda(XSQLDA *sqlda)
for (i = 0; i < sqlda->sqld; i++, var++) {
switch (var->sqltype & ~1) {
case SQL_TEXT:
var->sqldata = emalloc(sizeof(char) * (var->sqllen));
var->sqldata = safe_emalloc(sizeof(char), (var->sqllen), 0);
break;
case SQL_VARYING:
var->sqldata = emalloc(sizeof(char) * (var->sqllen + sizeof(short)));
var->sqldata = safe_emalloc(sizeof(char), (var->sqllen + sizeof(short)), 0);
break;
case SQL_SHORT:
var->sqldata = emalloc(sizeof(short));
Expand Down Expand Up @@ -1549,7 +1549,7 @@ static int _php_ibase_exec(ibase_result **ib_resultp, ibase_query *ib_query, int
_php_ibase_alloc_xsqlda(out_sqlda);

if (ib_query->out_array) {
IB_RESULT->out_array = emalloc(sizeof(ibase_array) * ib_query->out_array_cnt);
IB_RESULT->out_array = safe_emalloc(sizeof(ibase_array), ib_query->out_array_cnt, 0);
memcpy(IB_RESULT->out_array, ib_query->out_array, sizeof(ibase_array) * ib_query->out_array_cnt);
} else {
IB_RESULT->out_array = NULL;
Expand All @@ -1564,7 +1564,7 @@ static int _php_ibase_exec(ibase_result **ib_resultp, ibase_query *ib_query, int
}
in_sqlda = emalloc(XSQLDA_LENGTH(ib_query->in_sqlda->sqld));
memcpy(in_sqlda, ib_query->in_sqlda, XSQLDA_LENGTH(ib_query->in_sqlda->sqld));
bind_buf = emalloc(sizeof(BIND_BUF) * ib_query->in_sqlda->sqld);
bind_buf = safe_emalloc(sizeof(BIND_BUF), ib_query->in_sqlda->sqld, 0);
if (_php_ibase_bind(in_sqlda, args, bind_buf, ib_query TSRMLS_CC) == FAILURE) {
IBDEBUG("Could not bind input XSQLDA");
goto _php_ibase_exec_error;
Expand Down Expand Up @@ -1720,7 +1720,7 @@ PHP_FUNCTION(ibase_trans)
}

/* register the transaction in our own data structures */
ib_trans = (ibase_trans *) emalloc(sizeof(ibase_trans) + (link_cnt-1)*sizeof(ibase_db_link *));
ib_trans = (ibase_trans *) safe_emalloc((link_cnt-1), sizeof(ibase_db_link *), sizeof(ibase_trans));
ib_trans->handle = tr_handle;
ib_trans->link_cnt = link_cnt;
ib_trans->affected_rows = 0;
Expand Down Expand Up @@ -2261,7 +2261,7 @@ static int _php_ibase_var_zval(zval *val, void *data, int type, int len, int sca
data = ((IBASE_VCHAR *) data)->var_str;
/* fallout */
case SQL_TEXT:
Z_STRVAL_P(val) = (char *) emalloc(sizeof(char) * (len + 1));
Z_STRVAL_P(val) = (char *) safe_emalloc(sizeof(char), (len + 1), 0);
memcpy(Z_STRVAL_P(val), data, len);
Z_STRVAL_P(val)[len] = '\0';
if (PG(magic_quotes_runtime)) {
Expand Down Expand Up @@ -2894,7 +2894,7 @@ PHP_FUNCTION(ibase_timefmt)
WRONG_PARAM_COUNT;
}

args = (zval ***) emalloc(sizeof(zval **) * ZEND_NUM_ARGS());
args = (zval ***) safe_emalloc(sizeof(zval **), ZEND_NUM_ARGS(), 0);
if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
efree(args);
RETURN_FALSE;
Expand Down
2 changes: 1 addition & 1 deletion ext/msession/msession.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ PHP_FUNCTION(msession_set_array)

countpair = zend_hash_num_elements(htTuples);

pairs = (char **)emalloc(sizeof(char *) * countpair * 2);
pairs = (char **)safe_emalloc(sizeof(char *), countpair * 2, 0);

ELOG("have pairs");

Expand Down
14 changes: 7 additions & 7 deletions ext/mssql/php_mssql.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ static int _mssql_fetch_batch(mssql_link *mssql_ptr, mssql_result *result, int r
int *column_types;
char computed_buf[16];

column_types = (int *) emalloc(sizeof(int) * result->num_fields);
column_types = (int *) safe_emalloc(sizeof(int), result->num_fields, 0);
for (i=0; i<result->num_fields; i++) {
char *fname = (char *)dbcolname(mssql_ptr->link,i+1);

Expand Down Expand Up @@ -1036,14 +1036,14 @@ static int _mssql_fetch_batch(mssql_link *mssql_ptr, mssql_result *result, int r

i=0;
if (!result->data) {
result->data = (zval **) emalloc(sizeof(zval *)*MSSQL_ROWS_BLOCK*(++result->blocks_initialized));
result->data = (zval **) safe_emalloc(sizeof(zval *), MSSQL_ROWS_BLOCK*(++result->blocks_initialized), 0);
}
while (retvalue!=FAIL && retvalue!=NO_MORE_ROWS) {
result->num_rows++;
if (result->num_rows > result->blocks_initialized*MSSQL_ROWS_BLOCK) {
result->data = (zval **) erealloc(result->data,sizeof(zval *)*MSSQL_ROWS_BLOCK*(++result->blocks_initialized));
}
result->data[i] = (zval *) emalloc(sizeof(zval)*result->num_fields);
result->data[i] = (zval *) safe_emalloc(sizeof(zval), result->num_fields, 0);
for (j=0; j<result->num_fields; j++) {
INIT_ZVAL(result->data[i][j]);
MS_SQL_G(get_column_content(mssql_ptr, j+1, &result->data[i][j], column_types[j] TSRMLS_CC));
Expand Down Expand Up @@ -1163,7 +1163,7 @@ PHP_FUNCTION(mssql_query)
result->cur_field=result->cur_row=result->num_rows=0;

if (num_fields > 0) {
result->fields = (mssql_field *) emalloc(sizeof(mssql_field)*result->num_fields);
result->fields = (mssql_field *) safe_emalloc(sizeof(mssql_field), result->num_fields, 0);
result->num_rows = _mssql_fetch_batch(mssql_ptr, result, retvalue TSRMLS_CC);
}
else
Expand Down Expand Up @@ -1794,7 +1794,7 @@ PHP_FUNCTION(mssql_next_result)
retvalue = dbnextrow(mssql_ptr->link);

result->num_fields = dbnumcols(mssql_ptr->link);
result->fields = (mssql_field *) emalloc(sizeof(mssql_field)*result->num_fields);
result->fields = (mssql_field *) safe_emalloc(sizeof(mssql_field), result->num_fields, 0);
result->num_rows = _mssql_fetch_batch(mssql_ptr, result, retvalue TSRMLS_CC);
RETURN_TRUE;
}
Expand Down Expand Up @@ -2101,12 +2101,12 @@ PHP_FUNCTION(mssql_execute)
result = (mssql_result *) emalloc(sizeof(mssql_result));
result->batchsize = batchsize;
result->blocks_initialized = 1;
result->data = (zval **) emalloc(sizeof(zval *)*MSSQL_ROWS_BLOCK);
result->data = (zval **) safe_emalloc(sizeof(zval *), MSSQL_ROWS_BLOCK);
result->mssql_ptr = mssql_ptr;
result->cur_field=result->cur_row=result->num_rows=0;
result->num_fields = num_fields;

result->fields = (mssql_field *) emalloc(sizeof(mssql_field)*num_fields);
result->fields = (mssql_field *) safe_emalloc(sizeof(mssql_field), num_fields);
result->num_rows = _mssql_fetch_batch(mssql_ptr, result, retvalue TSRMLS_CC);
result->statement = statement;
}
Expand Down
Loading

0 comments on commit 93bcd55

Please sign in to comment.