summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Punt <tpunt@hotmail.co.uk>2017-03-16 08:27:57 +0000
committerNikita Popov <nikita.ppv@gmail.com>2017-03-16 12:23:55 +0100
commit932c4b35dc0fece175ca2764e4c82493a5004273 (patch)
tree11fe3a3551a00a9746f507e4af2c71c6d1dba0d1
parent9d9defa29aafd3b8cfaed8c6e3f8e59c98d0fcb7 (diff)
downloadphp-git-932c4b35dc0fece175ca2764e4c82493a5004273.tar.gz
Remove more unnecessary checks on Zend's allocator functions
-rw-r--r--ext/bz2/bz2_filter.c15
-rw-r--r--ext/mbstring/php_mbregex.c3
-rw-r--r--ext/openssl/xp_ssl.c3
-rw-r--r--ext/pdo/pdo_dbh.c4
-rw-r--r--ext/standard/array.c18
-rw-r--r--ext/standard/user_filters.c4
-rw-r--r--main/fopen_wrappers.c16
-rw-r--r--main/streams/filter.c11
-rw-r--r--main/streams/memory.c8
-rw-r--r--sapi/cli/php_cli_server.c37
10 files changed, 13 insertions, 106 deletions
diff --git a/ext/bz2/bz2_filter.c b/ext/bz2/bz2_filter.c
index cb70888284..6446e29ad9 100644
--- a/ext/bz2/bz2_filter.c
+++ b/ext/bz2/bz2_filter.c
@@ -315,10 +315,6 @@ static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *fi
/* Create this filter */
data = pecalloc(1, sizeof(php_bz2_filter_data), persistent);
- if (!data) {
- php_error_docref(NULL, E_WARNING, "Failed allocating %zu bytes", sizeof(php_bz2_filter_data));
- return NULL;
- }
/* Circular reference */
data->strm.opaque = (void *) data;
@@ -328,19 +324,8 @@ static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *fi
data->persistent = persistent;
data->strm.avail_out = data->outbuf_len = data->inbuf_len = 2048;
data->strm.next_in = data->inbuf = (char *) pemalloc(data->inbuf_len, persistent);
- if (!data->inbuf) {
- php_error_docref(NULL, E_WARNING, "Failed allocating %zu bytes", data->inbuf_len);
- pefree(data, persistent);
- return NULL;
- }
data->strm.avail_in = 0;
data->strm.next_out = data->outbuf = (char *) pemalloc(data->outbuf_len, persistent);
- if (!data->outbuf) {
- php_error_docref(NULL, E_WARNING, "Failed allocating %zu bytes", data->outbuf_len);
- pefree(data->inbuf, persistent);
- pefree(data, persistent);
- return NULL;
- }
if (strcasecmp(filtername, "bzip2.decompress") == 0) {
data->small_footprint = 0;
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c
index 998d9a7072..a2389df880 100644
--- a/ext/mbstring/php_mbregex.c
+++ b/ext/mbstring/php_mbregex.c
@@ -88,9 +88,6 @@ zend_mb_regex_globals *php_mb_regex_globals_alloc(void)
{
zend_mb_regex_globals *pglobals = pemalloc(
sizeof(zend_mb_regex_globals), 1);
- if (!pglobals) {
- return NULL;
- }
if (SUCCESS != _php_mb_regex_globals_ctor(pglobals)) {
pefree(pglobals, 1);
return NULL;
diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c
index 65693c23c7..a2d6860ecd 100644
--- a/ext/openssl/xp_ssl.c
+++ b/ext/openssl/xp_ssl.c
@@ -1431,9 +1431,6 @@ static unsigned char *alpn_protos_parse(unsigned short *outlen, const char *in)
}
out = emalloc(strlen(in) + 1);
- if (!out) {
- return NULL;
- }
for (i = 0; i <= len; ++i) {
if (i == len || in[i] == ',') {
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index 586797e744..4cfd01020f 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -1294,9 +1294,7 @@ int pdo_hash_methods(pdo_dbh_object_t *dbh_obj, int kind)
return 0;
}
- if (!(dbh->cls_methods[kind] = pemalloc(sizeof(HashTable), dbh->is_persistent))) {
- php_error_docref(NULL, E_ERROR, "out of memory while allocating PDO methods.");
- }
+ dbh->cls_methods[kind] = pemalloc(sizeof(HashTable), dbh->is_persistent);
zend_hash_init_ex(dbh->cls_methods[kind], 8, NULL,
dbh->is_persistent? cls_method_pdtor : cls_method_dtor, dbh->is_persistent, 0);
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 94343dc45e..d3c8dae19b 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -4487,10 +4487,6 @@ PHP_FUNCTION(array_unique)
/* create and sort array with pointers to the target_hash buckets */
arTmp = (struct bucketindex *) pemalloc((Z_ARRVAL_P(array)->nNumOfElements + 1) * sizeof(struct bucketindex), Z_ARRVAL_P(array)->u.flags & HASH_FLAG_PERSISTENT);
- if (!arTmp) {
- zval_dtor(return_value);
- RETURN_FALSE;
- }
for (i = 0, idx = 0; idx < Z_ARRVAL_P(array)->nNumUsed; idx++) {
p = Z_ARRVAL_P(array)->arData + idx;
if (Z_TYPE(p->val) == IS_UNDEF) continue;
@@ -4781,13 +4777,6 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
}
hash = Z_ARRVAL(args[i]);
list = (Bucket *) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket), hash->u.flags & HASH_FLAG_PERSISTENT);
- if (!list) {
- PHP_ARRAY_CMP_FUNC_RESTORE();
-
- efree(ptrs);
- efree(lists);
- RETURN_FALSE;
- }
lists[i] = list;
ptrs[i] = list;
for (idx = 0; idx < hash->nNumUsed; idx++) {
@@ -5203,13 +5192,6 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_
}
hash = Z_ARRVAL(args[i]);
list = (Bucket *) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket), hash->u.flags & HASH_FLAG_PERSISTENT);
- if (!list) {
- PHP_ARRAY_CMP_FUNC_RESTORE();
-
- efree(ptrs);
- efree(lists);
- RETURN_FALSE;
- }
lists[i] = list;
ptrs[i] = list;
for (idx = 0; idx < hash->nNumUsed; idx++) {
diff --git a/ext/standard/user_filters.c b/ext/standard/user_filters.c
index 4d7d76d13f..b0205094d9 100644
--- a/ext/standard/user_filters.c
+++ b/ext/standard/user_filters.c
@@ -508,9 +508,7 @@ PHP_FUNCTION(stream_bucket_new)
php_stream_from_zval(stream, zstream);
- if (!(pbuffer = pemalloc(buffer_len, php_stream_is_persistent(stream)))) {
- RETURN_FALSE;
- }
+ pbuffer = pemalloc(buffer_len, php_stream_is_persistent(stream));
memcpy(pbuffer, buffer, buffer_len);
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c
index 578e5d5170..578acc2101 100644
--- a/main/fopen_wrappers.c
+++ b/main/fopen_wrappers.c
@@ -406,16 +406,14 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
IS_ABSOLUTE_PATH(PG(doc_root), length)) {
int path_len = (int)strlen(path_info);
filename = emalloc(length + path_len + 2);
- if (filename) {
- memcpy(filename, PG(doc_root), length);
- if (!IS_SLASH(filename[length - 1])) { /* length is never 0 */
- filename[length++] = PHP_DIR_SEPARATOR;
- }
- if (IS_SLASH(path_info[0])) {
- length--;
- }
- strncpy(filename + length, path_info, path_len + 1);
+ memcpy(filename, PG(doc_root), length);
+ if (!IS_SLASH(filename[length - 1])) { /* length is never 0 */
+ filename[length++] = PHP_DIR_SEPARATOR;
+ }
+ if (IS_SLASH(path_info[0])) {
+ length--;
}
+ strncpy(filename + length, path_info, path_len + 1);
} else {
filename = SG(request_info).path_translated;
}
diff --git a/main/streams/filter.c b/main/streams/filter.c
index 47df8834bd..901cf00ad9 100644
--- a/main/streams/filter.c
+++ b/main/streams/filter.c
@@ -74,22 +74,11 @@ PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, s
php_stream_bucket *bucket;
bucket = (php_stream_bucket*)pemalloc(sizeof(php_stream_bucket), is_persistent);
-
- if (bucket == NULL) {
- return NULL;
- }
-
bucket->next = bucket->prev = NULL;
if (is_persistent && !buf_persistent) {
/* all data in a persistent bucket must also be persistent */
bucket->buf = pemalloc(buflen, 1);
-
- if (bucket->buf == NULL) {
- pefree(bucket, 1);
- return NULL;
- }
-
memcpy(bucket->buf, buf, buflen);
bucket->buflen = buflen;
bucket->own_buf = 1;
diff --git a/main/streams/memory.c b/main/streams/memory.c
index 41c09faca8..253d1d8340 100644
--- a/main/streams/memory.c
+++ b/main/streams/memory.c
@@ -62,12 +62,8 @@ static size_t php_stream_memory_write(php_stream *stream, const char *buf, size_
} else {
tmp = erealloc(ms->data, ms->fpos + count);
}
- if (!tmp) {
- count = ms->fsize - ms->fpos + 1;
- } else {
- ms->data = tmp;
- ms->fsize = ms->fpos + count;
- }
+ ms->data = tmp;
+ ms->fsize = ms->fpos + count;
}
if (!ms->data)
count = 0;
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
index 62e1601c09..de4cfb2195 100644
--- a/sapi/cli/php_cli_server.c
+++ b/sapi/cli/php_cli_server.c
@@ -928,9 +928,6 @@ static size_t php_cli_server_buffer_size(const php_cli_server_buffer *buffer) /*
static php_cli_server_chunk *php_cli_server_chunk_immortal_new(const char *buf, size_t len) /* {{{ */
{
php_cli_server_chunk *chunk = pemalloc(sizeof(php_cli_server_chunk), 1);
- if (!chunk) {
- return NULL;
- }
chunk->type = PHP_CLI_SERVER_CHUNK_IMMORTAL;
chunk->next = NULL;
@@ -942,9 +939,6 @@ static php_cli_server_chunk *php_cli_server_chunk_immortal_new(const char *buf,
static php_cli_server_chunk *php_cli_server_chunk_heap_new(void *block, char *buf, size_t len) /* {{{ */
{
php_cli_server_chunk *chunk = pemalloc(sizeof(php_cli_server_chunk), 1);
- if (!chunk) {
- return NULL;
- }
chunk->type = PHP_CLI_SERVER_CHUNK_HEAP;
chunk->next = NULL;
@@ -957,9 +951,6 @@ static php_cli_server_chunk *php_cli_server_chunk_heap_new(void *block, char *bu
static php_cli_server_chunk *php_cli_server_chunk_heap_new_self_contained(size_t len) /* {{{ */
{
php_cli_server_chunk *chunk = pemalloc(sizeof(php_cli_server_chunk) + len, 1);
- if (!chunk) {
- return NULL;
- }
chunk->type = PHP_CLI_SERVER_CHUNK_HEAP;
chunk->next = NULL;
@@ -1215,12 +1206,6 @@ static php_socket_t php_network_listen_socket(const char *host, int *port, int s
#if HAVE_GETADDRINFO && HAVE_IPV6
case AF_INET6:
sa = pemalloc(sizeof(struct sockaddr_in6), 1);
- if (!sa) {
- closesocket(retval);
- retval = SOCK_ERR;
- *errstr = NULL;
- goto out;
- }
*(struct sockaddr_in6 *)sa = *(struct sockaddr_in6 *)*p;
((struct sockaddr_in6 *)sa)->sin6_port = htons(*port);
*socklen = sizeof(struct sockaddr_in6);
@@ -1228,12 +1213,6 @@ static php_socket_t php_network_listen_socket(const char *host, int *port, int s
#endif
case AF_INET:
sa = pemalloc(sizeof(struct sockaddr_in), 1);
- if (!sa) {
- closesocket(retval);
- retval = SOCK_ERR;
- *errstr = NULL;
- goto out;
- }
*(struct sockaddr_in *)sa = *(struct sockaddr_in *)*p;
((struct sockaddr_in *)sa)->sin_port = htons(*port);
*socklen = sizeof(struct sockaddr_in);
@@ -1370,10 +1349,6 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque
size_t prev_path_len = 0;
int is_static_file = 0;
- if (!buf) {
- return;
- }
-
memmove(p, document_root, document_root_len);
p += document_root_len;
vpath = p;
@@ -1642,9 +1617,6 @@ static int php_cli_server_client_read_request_on_body(php_http_parser *parser, c
php_cli_server_client *client = parser->data;
if (!client->request.content) {
client->request.content = pemalloc(parser->content_length, 1);
- if (!client->request.content) {
- return -1;
- }
client->request.content_len = 0;
}
client->request.content = perealloc(client->request.content, client->request.content_len + length, 1);
@@ -1720,9 +1692,6 @@ static int php_cli_server_client_read_request(php_cli_server_client *client, cha
}
if (client->current_header_name) {
char *header_name = safe_pemalloc(client->current_header_name_len, 1, 1, 1);
- if (!header_name) {
- return -1;
- }
memmove(header_name, client->current_header_name, client->current_header_name_len);
client->current_header_name = header_name;
client->current_header_name_allocated = 1;
@@ -2389,9 +2358,6 @@ static int php_cli_server_do_event_for_each_fd_callback(void *_params, php_socke
php_socket_t client_sock;
socklen_t socklen = server->socklen;
struct sockaddr *sa = pemalloc(server->socklen, 1);
- if (!sa) {
- return FAILURE;
- }
client_sock = accept(server->server_sock, sa, &socklen);
if (!ZEND_VALID_SOCKET(client_sock)) {
char *errstr;
@@ -2406,7 +2372,8 @@ static int php_cli_server_do_event_for_each_fd_callback(void *_params, php_socke
closesocket(client_sock);
return SUCCESS;
}
- if (!(client = pemalloc(sizeof(php_cli_server_client), 1)) || FAILURE == php_cli_server_client_ctor(client, server, client_sock, sa, socklen)) {
+ client = pemalloc(sizeof(php_cli_server_client), 1);
+ if (FAILURE == php_cli_server_client_ctor(client, server, client_sock, sa, socklen)) {
php_cli_server_logf("Failed to create a new request object");
pefree(sa, 1);
closesocket(client_sock);