From 0be78cd2b4371380568527a2592af3a10c8866ce Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Tue, 22 Apr 2003 01:38:36 +0000 Subject: [PATCH] emalloc -> safe_emalloc. --- ext/ereg/ereg.c | 12 ++++++------ ext/standard/metaphone.c | 4 ++-- ext/standard/pack.c | 6 +++--- ext/standard/reg.c | 12 ++++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ext/ereg/ereg.c b/ext/ereg/ereg.c index 2af1fefb3a..193e43a247 100644 --- a/ext/ereg/ereg.c +++ b/ext/ereg/ereg.c @@ -118,7 +118,7 @@ static void php_reg_eprint(int err, regex_t *re) { /* get the length of the message */ buf_len = regerror(REG_ITOA | err, re, NULL, 0); if (buf_len) { - buf = (char *)emalloc(buf_len * sizeof(char)); + buf = (char *)safe_emalloc(buf_len, sizeof(char), 0); if (!buf) return; /* fail silently */ /* finally, get the error message */ regerror(REG_ITOA | err, re, buf, buf_len); @@ -130,7 +130,7 @@ static void php_reg_eprint(int err, regex_t *re) { if (len) { TSRMLS_FETCH(); - message = (char *)emalloc((buf_len + len + 2) * sizeof(char)); + message = (char *)safe_emalloc((buf_len + len + 2), sizeof(char), 0); if (!message) { return; /* fail silently */ } @@ -298,7 +298,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha /* start with a buffer that is twice the size of the stringo we're doing replacements in */ buf_len = 2 * string_len + 1; - buf = emalloc(buf_len * sizeof(char)); + buf = safe_emalloc(buf_len, sizeof(char), 0); err = pos = 0; buf[0] = '\0'; @@ -373,7 +373,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha new_l = strlen (buf) + 1; if (new_l + 1 > buf_len) { buf_len = 1 + buf_len + 2 * new_l; - nbuf = emalloc(buf_len * sizeof(char)); + nbuf = safe_emalloc(buf_len, sizeof(char), 0); strcpy(nbuf, buf); efree(buf); buf = nbuf; @@ -388,7 +388,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha new_l = strlen(buf) + strlen(&string[pos]); if (new_l + 1 > buf_len) { buf_len = new_l + 1; /* now we know exactly how long it is */ - nbuf = emalloc(buf_len * sizeof(char)); + nbuf = safe_emalloc(buf_len, sizeof(char), 0); strcpy(nbuf, buf); efree(buf); buf = nbuf; @@ -607,7 +607,7 @@ PHPAPI PHP_FUNCTION(sql_regcase) } convert_to_string_ex(string); - tmp = emalloc((Z_STRLEN_PP(string) * 4) + 1); + tmp = safe_emalloc(Z_STRLEN_PP(string), 4, 1); for (i = j = 0; i < Z_STRLEN_PP(string); i++) { c = (unsigned char) Z_STRVAL_PP(string)[i]; diff --git a/ext/standard/metaphone.c b/ext/standard/metaphone.c index def77a7714..b433208d9c 100644 --- a/ext/standard/metaphone.c +++ b/ext/standard/metaphone.c @@ -183,12 +183,12 @@ static int metaphone(char *word, int word_len, int max_phonemes, char **phoned_w /*-- Allocate memory for our phoned_phrase --*/ if (max_phonemes == 0) { /* Assume largest possible */ max_buffer_len = word_len; - *phoned_word = emalloc(sizeof(char) * word_len + 1); + *phoned_word = safe_emalloc(sizeof(char), word_len, 1); if (!*phoned_word) return -1; } else { max_buffer_len = max_phonemes; - *phoned_word = emalloc(sizeof(char) * max_phonemes + 1); + *phoned_word = safe_emalloc(sizeof(char), max_phonemes, 1); if (!*phoned_word) return -1; } diff --git a/ext/standard/pack.c b/ext/standard/pack.c index 0002aaeb37..cce7913a9a 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -122,7 +122,7 @@ PHP_FUNCTION(pack) WRONG_PARAM_COUNT; } - argv = emalloc(argc * sizeof(zval **)); + argv = safe_emalloc(sizeof(zval **), argc, 0); if (zend_get_parameters_array_ex(argc, argv) == FAILURE) { efree(argv); @@ -134,8 +134,8 @@ PHP_FUNCTION(pack) formatlen = Z_STRLEN_PP(argv[0]); /* We have a maximum of format codes to deal with */ - formatcodes = emalloc(formatlen * sizeof(*formatcodes)); - formatargs = emalloc(formatlen * sizeof(*formatargs)); + formatcodes = safe_emalloc(formatlen, sizeof(*formatcodes), 0); + formatargs = safe_emalloc(formatlen, sizeof(*formatargs), 0); currentarg = 1; /* Preprocess format into formatcodes and formatargs */ diff --git a/ext/standard/reg.c b/ext/standard/reg.c index 2af1fefb3a..193e43a247 100644 --- a/ext/standard/reg.c +++ b/ext/standard/reg.c @@ -118,7 +118,7 @@ static void php_reg_eprint(int err, regex_t *re) { /* get the length of the message */ buf_len = regerror(REG_ITOA | err, re, NULL, 0); if (buf_len) { - buf = (char *)emalloc(buf_len * sizeof(char)); + buf = (char *)safe_emalloc(buf_len, sizeof(char), 0); if (!buf) return; /* fail silently */ /* finally, get the error message */ regerror(REG_ITOA | err, re, buf, buf_len); @@ -130,7 +130,7 @@ static void php_reg_eprint(int err, regex_t *re) { if (len) { TSRMLS_FETCH(); - message = (char *)emalloc((buf_len + len + 2) * sizeof(char)); + message = (char *)safe_emalloc((buf_len + len + 2), sizeof(char), 0); if (!message) { return; /* fail silently */ } @@ -298,7 +298,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha /* start with a buffer that is twice the size of the stringo we're doing replacements in */ buf_len = 2 * string_len + 1; - buf = emalloc(buf_len * sizeof(char)); + buf = safe_emalloc(buf_len, sizeof(char), 0); err = pos = 0; buf[0] = '\0'; @@ -373,7 +373,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha new_l = strlen (buf) + 1; if (new_l + 1 > buf_len) { buf_len = 1 + buf_len + 2 * new_l; - nbuf = emalloc(buf_len * sizeof(char)); + nbuf = safe_emalloc(buf_len, sizeof(char), 0); strcpy(nbuf, buf); efree(buf); buf = nbuf; @@ -388,7 +388,7 @@ PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const cha new_l = strlen(buf) + strlen(&string[pos]); if (new_l + 1 > buf_len) { buf_len = new_l + 1; /* now we know exactly how long it is */ - nbuf = emalloc(buf_len * sizeof(char)); + nbuf = safe_emalloc(buf_len, sizeof(char), 0); strcpy(nbuf, buf); efree(buf); buf = nbuf; @@ -607,7 +607,7 @@ PHPAPI PHP_FUNCTION(sql_regcase) } convert_to_string_ex(string); - tmp = emalloc((Z_STRLEN_PP(string) * 4) + 1); + tmp = safe_emalloc(Z_STRLEN_PP(string), 4, 1); for (i = j = 0; i < Z_STRLEN_PP(string); i++) { c = (unsigned char) Z_STRVAL_PP(string)[i]; -- 2.40.0