Browse Source

Removed pointless memory allocation checks.

PHP-5
Ilia Alshanetsky 23 years ago
parent
commit
71e9f8cdd5
  1. 12
      ext/standard/exec.c
  2. 2
      ext/standard/file.c
  3. 10
      ext/standard/image.c
  4. 5
      ext/standard/info.c
  5. 8
      ext/standard/metaphone.c
  6. 3
      ext/standard/string.c

12
ext/standard/exec.c

@ -67,10 +67,6 @@ int php_Exec(int type, char *cmd, pval *array, pval *return_value TSRMLS_DC)
#endif
buf = (char *) emalloc(EXEC_INPUT_BUF);
if (!buf) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to emalloc %d bytes for exec buffer", EXEC_INPUT_BUF);
return -1;
}
buflen = EXEC_INPUT_BUF;
if (PG(safe_mode)) {
@ -162,14 +158,6 @@ int php_Exec(int type, char *cmd, pval *array, pval *return_value TSRMLS_DC)
do {
if ( buflen <= (l+1) ) {
buf = erealloc(buf, buflen + EXEC_INPUT_BUF);
if ( buf == NULL ) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to erealloc %d bytes for exec buffer",
buflen + EXEC_INPUT_BUF);
#if PHP_SIGCHILD
signal (SIGCHLD, sig_handler);
#endif
return -1;
}
buflen += EXEC_INPUT_BUF;
}

2
ext/standard/file.c

@ -1495,7 +1495,7 @@ PHP_FUNCTION(fscanf)
WRONG_PARAM_COUNT;
}
args = (zval ***)emalloc(argCount * sizeof(zval **));
if (!args || (zend_get_parameters_array_ex(argCount, args) == FAILURE)) {
if (zend_get_parameters_array_ex(argCount, args) == FAILURE) {
efree( args );
WRONG_PARAM_COUNT;
}

10
ext/standard/image.c

@ -215,10 +215,6 @@ static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC)
do {
szlength=slength*(1<<factor++);
buf = (char *) erealloc(buf,szlength);
if (!buf) {
status = 1;
break;
}
status = uncompress(buf, &szlength, bufz, slength);
} while ((status==Z_BUF_ERROR)&&(factor<maxfactor));
@ -439,7 +435,6 @@ static void php_read_APP(php_stream * stream, unsigned int marker, zval *info TS
length -= 2; /* length includes itself */
buffer = emalloc(length);
if ( !buffer) return;
if (php_stream_read(stream, buffer, (long) length) <= 0) {
efree(buffer);
@ -485,8 +480,6 @@ static struct gfxinfo *php_handle_jpeg (php_stream * stream, pval *info TSRMLS_D
if (result == NULL) {
/* handle SOFn block */
result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
if ( !result)
return NULL;
length = php_read2(stream TSRMLS_CC);
result->bits = php_stream_getc(stream);
result->height = php_read2(stream TSRMLS_CC);
@ -605,9 +598,6 @@ static struct gfxinfo *php_handle_jpc(php_stream * stream TSRMLS_DC)
}
result = (struct gfxinfo *)ecalloc(1, sizeof(struct gfxinfo));
if (!result) {
return NULL;
}
dummy_short = php_read2(stream TSRMLS_CC); /* Lsiz */
dummy_short = php_read2(stream TSRMLS_CC); /* Rsiz */

5
ext/standard/info.c

@ -439,10 +439,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
for (zend_hash_internal_pointer_reset(url_stream_wrappers_hash);
zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, NULL, 0, NULL) == HASH_KEY_IS_STRING;
zend_hash_move_forward(url_stream_wrappers_hash)) {
if (NULL == (stream_protocols_buf = erealloc(stream_protocols_buf,
stream_protocols_buf_len + stream_protocol_len + 2 /* ", " */ + 1 /* 0 byte at end */))) {
break;
}
stream_protocols_buf = erealloc(stream_protocols_buf, stream_protocols_buf_len + stream_protocol_len + 2 + 1);
memcpy(stream_protocols_buf + stream_protocols_buf_len, stream_protocol, stream_protocol_len);
stream_protocols_buf[stream_protocols_buf_len + stream_protocol_len] = ',';
stream_protocols_buf[stream_protocols_buf_len + stream_protocol_len + 1] = ' ';

8
ext/standard/metaphone.c

@ -145,9 +145,7 @@ static char Lookahead(char *word, int how_far)
* could be one though; or more too). */
#define Phonize(c) { \
if (p_idx >= max_buffer_len) { \
if (NULL == (*phoned_word = erealloc(*phoned_word, max_buffer_len + 2))) { \
return -1; \
} \
*phoned_word = erealloc(*phoned_word, max_buffer_len + 2); \
max_buffer_len += 2; \
} \
(*phoned_word)[p_idx++] = c; \
@ -185,13 +183,9 @@ static int metaphone(char *word, int word_len, int max_phonemes, char **phoned_w
if (max_phonemes == 0) { /* Assume largest possible */
max_buffer_len = word_len;
*phoned_word = 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);
if (!*phoned_word)
return -1;
}

3
ext/standard/string.c

@ -113,9 +113,6 @@ static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t *
size_t i, j;
result = (char *) emalloc(oldlen * 2 * sizeof(char) + 1);
if (!result) {
return result;
}
for (i = j = 0; i < oldlen; i++) {
result[j++] = hexconvtab[old[i] >> 4];

Loading…
Cancel
Save