MFB: safe_emalloc()

This commit is contained in:
Marcus Boerger 2003-04-24 20:54:43 +00:00
parent 228f65f889
commit 8a5ba51ac8
4 changed files with 9 additions and 10 deletions

View File

@ -525,7 +525,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
}
/* we pass additional args to the respective handler */
args = emalloc(ac * sizeof(zval *));
args = safe_emalloc(ac, sizeof(zval *), 0);
if (zend_get_parameters_array_ex(ac, args) != SUCCESS) {
FREENOW;
WRONG_PARAM_COUNT;
@ -541,7 +541,8 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
list_entry *le;
/* calculate hash */
key = emalloc(keylen);
key = safe_emalloc(keylen, 1, 1);
key[keylen] = '\0';
keylen = 0;
for(i = 0; i < ac; i++) {

View File

@ -163,7 +163,7 @@ DBA_FETCH_FUNC(cdb)
}
}
len = cdb_datalen(&cdb->c);
new_entry = emalloc(len+1);
new_entry = safe_emalloc(len, 1, 1);
if (php_cdb_read(&cdb->c, new_entry, len, cdb_datapos(&cdb->c)) == -1) {
efree(new_entry);
@ -268,7 +268,7 @@ DBA_FIRSTKEY_FUNC(cdb)
uint32_unpack(buf, &klen);
uint32_unpack(buf + 4, &dlen);
key = emalloc(klen + 1);
key = safe_emalloc(klen, 1, 1);
if (cdb_file_read(cdb->file, key, klen) < klen) {
efree(key);
key = NULL;
@ -300,7 +300,7 @@ DBA_NEXTKEY_FUNC(cdb)
uint32_unpack(buf, &klen);
uint32_unpack(buf + 4, &dlen);
key = emalloc(klen + 1);
key = safe_emalloc(klen, 1, 1);
if (cdb_file_read(cdb->file, key, klen) < klen) {
efree(key);
key = NULL;

View File

@ -79,8 +79,7 @@ int cdb_make_addend(struct cdb_make *c, unsigned int keylen, unsigned int datale
head = c->head;
if (!head || (head->num >= CDB_HPLIST)) {
head = (struct cdb_hplist *)
emalloc(sizeof(struct cdb_hplist));
head = (struct cdb_hplist *) emalloc(sizeof(struct cdb_hplist));
if (!head)
return -1;
head->num = 0;
@ -172,8 +171,7 @@ int cdb_make_finish(struct cdb_make *c TSRMLS_DC)
return -1;
}
c->split = (struct cdb_hp *)
emalloc(memsize * sizeof(struct cdb_hp));
c->split = (struct cdb_hp *) safe_emalloc(memsize, sizeof(struct cdb_hp), 0);
if (!c->split)
return -1;

View File

@ -91,7 +91,7 @@ datum flatfile_fetch(flatfile *dba, datum key_datum TSRMLS_DC) {
if (flatfile_findkey(dba, key_datum TSRMLS_CC)) {
if (php_stream_gets(dba->fp, buf, sizeof(buf))) {
value_datum.dsize = atoi(buf);
value_datum.dptr = emalloc(value_datum.dsize+1);
value_datum.dptr = safe_emalloc(value_datum.dsize, 1, 1);
value_datum.dsize = php_stream_read(dba->fp, value_datum.dptr, value_datum.dsize);
} else {
value_datum.dptr = NULL;