]> granicus.if.org Git - php/commitdiff
MFB: safe_emalloc()
authorMarcus Boerger <helly@php.net>
Thu, 24 Apr 2003 20:54:43 +0000 (20:54 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 24 Apr 2003 20:54:43 +0000 (20:54 +0000)
ext/dba/dba.c
ext/dba/dba_cdb.c
ext/dba/libcdb/cdb_make.c
ext/dba/libflatfile/flatfile.c

index cacb2086be11345338a85b8b4438e46e8e9d2bb3..f83ec079a8ab136db79927dcb25b898e0eb08fde 100644 (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++) {
index 654f07f684a943c7c46ea557e0560a1e00b12323..b6f1c5e8dcfadb2a25c4984c6d7d4027d873b49c 100644 (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;
index 1c3402e9081b057eef341c156ec7f02a181e8339..64525a17a23292017c1c63cf5f71fceb0a675f84 100644 (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;
 
index 44ef3d53a3e31fea228ff8f259df4c20f4826426..5a9074da6e9a86d5b14851e91617726d432a471d 100644 (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;