summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/mysqlnd/mysqlnd_net.c6
-rw-r--r--ext/openssl/xp_ssl.c1
-rw-r--r--ext/standard/fsock.c12
-rw-r--r--ext/standard/http_fopen_wrapper.c7
-rw-r--r--ext/standard/streamsfuncs.c59
-rw-r--r--ext/standard/string.c51
6 files changed, 56 insertions, 80 deletions
diff --git a/ext/mysqlnd/mysqlnd_net.c b/ext/mysqlnd/mysqlnd_net.c
index 76e49a5d9d..84757f88c1 100644
--- a/ext/mysqlnd/mysqlnd_net.c
+++ b/ext/mysqlnd/mysqlnd_net.c
@@ -160,7 +160,7 @@ MYSQLND_METHOD(mysqlnd_net, open_tcp_or_unix)(MYSQLND_NET * const net, const cha
unsigned int streams_flags = STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT;
char * hashed_details = NULL;
int hashed_details_len = 0;
- char * errstr = NULL;
+ zend_string *errstr = NULL;
int errcode = 0;
struct timeval tv;
dtor_func_t origin_dtor;
@@ -190,10 +190,10 @@ MYSQLND_METHOD(mysqlnd_net, open_tcp_or_unix)(MYSQLND_NET * const net, const cha
mnd_sprintf_free(hashed_details);
}
errcode = CR_CONNECTION_ERROR;
- SET_CLIENT_ERROR(*error_info, errcode? errcode:CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, errstr);
+ SET_CLIENT_ERROR(*error_info, errcode? errcode:CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, errstr->val);
if (errstr) {
/* no mnd_ since we don't allocate it */
- efree(errstr);
+ STR_RELEASE(errstr);
}
DBG_RETURN(NULL);
}
diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c
index 8fdbf2845f..b26e973507 100644
--- a/ext/openssl/xp_ssl.c
+++ b/ext/openssl/xp_ssl.c
@@ -1947,7 +1947,6 @@ static inline int php_openssl_tcp_sockop_accept(php_stream *stream, php_openssl_
clisock = php_network_accept_incoming(sock->s.socket,
xparam->want_textaddr ? &xparam->outputs.textaddr : NULL,
- xparam->want_textaddr ? &xparam->outputs.textaddrlen : NULL,
xparam->want_addr ? &xparam->outputs.addr : NULL,
xparam->want_addr ? &xparam->outputs.addrlen : NULL,
xparam->inputs.timeout,
diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c
index e11bb84056..300df8c1c0 100644
--- a/ext/standard/fsock.c
+++ b/ext/standard/fsock.c
@@ -43,7 +43,7 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent)
int err;
char *hostname = NULL;
long hostname_len;
- char *errstr = NULL;
+ zend_string *errstr = NULL;
RETVAL_FALSE;
@@ -83,7 +83,7 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent)
efree(hostname);
}
if (stream == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s:%ld (%s)", host, port, errstr == NULL ? "Unknown error" : errstr);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s:%ld (%s)", host, port, errstr == NULL ? "Unknown error" : errstr->val);
}
if (hashkey) {
@@ -98,18 +98,16 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent)
if (zerrstr && errstr) {
/* no need to dup; we need to efree buf anyway */
zval_dtor(zerrstr);
- // TODO: avoid reallocation ???
- ZVAL_STRING(zerrstr, errstr);
- efree(errstr);
+ ZVAL_STR(zerrstr, errstr);
} else if (!zerrstr && errstr) {
- efree(errstr);
+ STR_RELEASE(errstr);
}
RETURN_FALSE;
}
if (errstr) {
- efree(errstr);
+ STR_RELEASE(errstr);
}
php_stream_to_zval(stream, return_value);
diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c
index 1007b16123..73952dda31 100644
--- a/ext/standard/http_fopen_wrapper.c
+++ b/ext/standard/http_fopen_wrapper.c
@@ -130,7 +130,8 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
char tmp_line[128];
size_t chunk_size = 0, file_size = 0;
int eol_detect = 0;
- char *transport_string, *errstr = NULL;
+ char *transport_string;
+ zend_string *errstr = NULL;
int transport_len, have_header = 0, request_fulluri = 0, ignore_errors = 0;
char *protocol_version = NULL;
int protocol_version_len = 3; /* Default: "1.0" */
@@ -216,8 +217,8 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
}
if (errstr) {
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "%s", errstr);
- efree(errstr);
+ php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "%s", errstr->val);
+ STR_RELEASE(errstr);
errstr = NULL;
}
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c
index 9ba10edb13..652512ce07 100644
--- a/ext/standard/streamsfuncs.c
+++ b/ext/standard/streamsfuncs.c
@@ -97,7 +97,7 @@ PHP_FUNCTION(stream_socket_client)
php_stream *stream = NULL;
int err;
long flags = PHP_STREAM_CLIENT_CONNECT;
- char *errstr = NULL;
+ zend_string *errstr = NULL;
php_stream_context *context = NULL;
RETVAL_FALSE;
@@ -140,7 +140,7 @@ PHP_FUNCTION(stream_socket_client)
/* host might contain binary characters */
zend_string *quoted_host = php_addslashes(host, host_len, 0 TSRMLS_CC);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", quoted_host->val, errstr == NULL ? "Unknown error" : errstr);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", quoted_host->val, errstr == NULL ? "Unknown error" : errstr->val);
STR_RELEASE(quoted_host);
}
@@ -154,19 +154,16 @@ PHP_FUNCTION(stream_socket_client)
ZVAL_LONG(zerrno, err);
}
if (zerrstr && errstr) {
- /* no need to dup; we need to efree buf anyway */
zval_dtor(zerrstr);
- // TODO: avoid reallocation ???
- ZVAL_STRING(zerrstr, errstr);
- efree(errstr);
+ ZVAL_STR(zerrstr, errstr);
} else if (errstr) {
- efree(errstr);
+ STR_RELEASE(errstr);
}
RETURN_FALSE;
}
if (errstr) {
- efree(errstr);
+ STR_RELEASE(errstr);
}
php_stream_to_zval(stream, return_value);
@@ -184,7 +181,7 @@ PHP_FUNCTION(stream_socket_server)
php_stream *stream = NULL;
int err = 0;
long flags = STREAM_XPORT_BIND | STREAM_XPORT_LISTEN;
- char *errstr = NULL;
+ zend_string *errstr = NULL;
php_stream_context *context = NULL;
RETVAL_FALSE;
@@ -213,7 +210,7 @@ PHP_FUNCTION(stream_socket_server)
NULL, NULL, context, &errstr, &err);
if (stream == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", host, errstr == NULL ? "Unknown error" : errstr);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", host, errstr == NULL ? "Unknown error" : errstr->val);
}
if (stream == NULL) {
@@ -222,19 +219,16 @@ PHP_FUNCTION(stream_socket_server)
ZVAL_LONG(zerrno, err);
}
if (zerrstr && errstr) {
- /* no need to dup; we need to efree buf anyway */
zval_dtor(zerrstr);
- // TODO: avoid reallocation ???
- ZVAL_STRING(zerrstr, errstr);
- efree(errstr);
+ ZVAL_STR(zerrstr, errstr);
} else if (errstr) {
- efree(errstr);
+ STR_RELEASE(errstr);
}
RETURN_FALSE;
}
if (errstr) {
- efree(errstr);
+ STR_RELEASE(errstr);
}
php_stream_to_zval(stream, return_value);
@@ -247,14 +241,12 @@ PHP_FUNCTION(stream_socket_accept)
{
double timeout = FG(default_socket_timeout);
zval *zpeername = NULL;
- char *peername = NULL;
- int peername_len;
+ zend_string *peername = NULL;
php_timeout_ull conv;
struct timeval tv;
php_stream *stream = NULL, *clistream = NULL;
zval *zstream;
-
- char *errstr = NULL;
+ zend_string *errstr = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|dz/", &zstream, &timeout, &zpeername) == FAILURE) {
RETURN_FALSE;
@@ -278,24 +270,21 @@ PHP_FUNCTION(stream_socket_accept)
if (0 == php_stream_xport_accept(stream, &clistream,
zpeername ? &peername : NULL,
- zpeername ? &peername_len : NULL,
NULL, NULL,
&tv, &errstr
TSRMLS_CC) && clistream) {
if (peername) {
- // TODO: avoid reallocation ???
- ZVAL_STRINGL(zpeername, peername, peername_len);
- efree(peername);
+ ZVAL_STR(zpeername, peername);
}
php_stream_to_zval(clistream, return_value);
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "accept failed: %s", errstr ? errstr : "Unknown error");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "accept failed: %s", errstr ? errstr->val : "Unknown error");
RETVAL_FALSE;
}
if (errstr) {
- efree(errstr);
+ STR_RELEASE(errstr);
}
}
/* }}} */
@@ -307,8 +296,7 @@ PHP_FUNCTION(stream_socket_get_name)
php_stream *stream;
zval *zstream;
zend_bool want_peer;
- char *name = NULL;
- int name_len;
+ zend_string *name = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &zstream, &want_peer) == FAILURE) {
RETURN_FALSE;
@@ -318,15 +306,12 @@ PHP_FUNCTION(stream_socket_get_name)
if (0 != php_stream_xport_get_name(stream, want_peer,
&name,
- &name_len,
NULL, NULL
TSRMLS_CC)) {
RETURN_FALSE;
}
- // TODO: avoid reallocation ???
- RETVAL_STRINGL(name, name_len);
- efree(name);
+ RETVAL_STR(name);
}
/* }}} */
@@ -365,8 +350,7 @@ PHP_FUNCTION(stream_socket_recvfrom)
{
php_stream *stream;
zval *zstream, *zremote = NULL;
- char *remote_addr = NULL;
- int remote_addr_len;
+ zend_string *remote_addr = NULL;
long to_read = 0;
zend_string *read_buf;
long flags = 0;
@@ -391,15 +375,12 @@ PHP_FUNCTION(stream_socket_recvfrom)
read_buf = STR_ALLOC(to_read, 0);
recvd = php_stream_xport_recvfrom(stream, read_buf->val, to_read, flags, NULL, NULL,
- zremote ? &remote_addr : NULL,
- zremote ? &remote_addr_len : NULL
+ zremote ? &remote_addr : NULL
TSRMLS_CC);
if (recvd >= 0) {
if (zremote) {
- // TODO: avoid reallocation ???
- ZVAL_STRINGL(zremote, remote_addr, remote_addr_len);
- efree(remote_addr);
+ ZVAL_STR(zremote, remote_addr);
}
read_buf->val[recvd] = '\0';
read_buf->len = recvd;
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 5f4f360ca6..0b7cef3da8 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -146,41 +146,42 @@ static zend_string *php_bin2hex(const unsigned char *old, const size_t oldlen)
/* {{{ php_hex2bin
*/
-static char *php_hex2bin(const unsigned char *old, const size_t oldlen, size_t *newlen)
+static zend_string *php_hex2bin(const unsigned char *old, const size_t oldlen)
{
size_t target_length = oldlen >> 1;
- register unsigned char *str = (unsigned char *)safe_emalloc(target_length, sizeof(char), 1);
+ zend_string *str = STR_ALLOC(target_length, 0);
+ unsigned char *ret = (unsigned char *)str->val;
size_t i, j;
+
for (i = j = 0; i < target_length; i++) {
- char c = old[j++];
+ unsigned char c = old[j++];
+ unsigned char d;
+
if (c >= '0' && c <= '9') {
- str[i] = (c - '0') << 4;
+ d = (c - '0') << 4;
} else if (c >= 'a' && c <= 'f') {
- str[i] = (c - 'a' + 10) << 4;
+ d = (c - 'a' + 10) << 4;
} else if (c >= 'A' && c <= 'F') {
- str[i] = (c - 'A' + 10) << 4;
+ d = (c - 'A' + 10) << 4;
} else {
- efree(str);
+ STR_FREE(str);
return NULL;
}
c = old[j++];
if (c >= '0' && c <= '9') {
- str[i] |= c - '0';
+ d |= c - '0';
} else if (c >= 'a' && c <= 'f') {
- str[i] |= c - 'a' + 10;
+ d |= c - 'a' + 10;
} else if (c >= 'A' && c <= 'F') {
- str[i] |= c - 'A' + 10;
+ d |= c - 'A' + 10;
} else {
- efree(str);
+ STR_FREE(str);
return NULL;
}
+ ret[i] = d;
}
- str[target_length] = '\0';
-
- if (newlen)
- *newlen = target_length;
- return (char *)str;
+ return str;
}
/* }}} */
@@ -256,29 +257,25 @@ PHP_FUNCTION(bin2hex)
Converts the hex representation of data to binary */
PHP_FUNCTION(hex2bin)
{
- char *result, *data;
- size_t newlen;
- int datalen;
+ zend_string *result, *data;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &datalen) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &data) == FAILURE) {
return;
}
- if (datalen % 2 != 0) {
+ if (data->len % 2 != 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Hexadecimal input string must have an even length");
RETURN_FALSE;
}
- result = php_hex2bin((unsigned char *)data, datalen, &newlen);
+ result = php_hex2bin((unsigned char *)data->val, data->len);
if (!result) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input string must be hexadecimal string");
RETURN_FALSE;
}
- // TODO: avoid reallocation ???
- RETVAL_STRINGL(result, newlen);
- efree(result);
+ RETVAL_STR(result);
}
/* }}} */
@@ -2457,7 +2454,7 @@ PHP_FUNCTION(substr_replace)
orig_str = tmp_str;
}
- /*
+ /*???
refcount = Z_REFCOUNT_P(orig_str);
*/
@@ -2528,7 +2525,7 @@ PHP_FUNCTION(substr_replace)
} else {
repl_str = tmp_repl;
}
- /*
+ /*???
if (Z_REFCOUNT_P(orig_str) != refcount) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument was modified while replacing");
if (Z_TYPE_P(tmp_repl) != IS_STRING) {