Skip to content

Commit

Permalink
Fix compiler warning (#5318)
Browse files Browse the repository at this point in the history
* fixed compiler maybe-uninitialized warning

* fixed: using delete to release object created by new

* fixed compiler warning: ISO C++ forbids converting a string constant to 'char*' and using ZPP api

* fixed compiler warning: 'recv_size' may be used uninitialized and comparison of integer expressions of different signedness
  • Loading branch information
Appla authored May 9, 2024
1 parent 31ee745 commit 9ce89a8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ext-src/swoole_client_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ static PHP_METHOD(swoole_client_coro, peek) {

CLIENT_CORO_GET_SOCKET_SAFE(cli);

buf = (char *) emalloc(buf_len + 1);
buf = (char *) emalloc((size_t)buf_len + 1);
ret = cli->peek(buf, buf_len);
if (ret < 0) {
php_swoole_socket_set_error_properties(ZEND_THIS, cli);
Expand Down
2 changes: 2 additions & 0 deletions ext-src/swoole_pgsql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ PGconn *swoole_pgsql_connectdb(const char *conninfo) {
event = SW_EVENT_WRITE;
break;
default:
// should not be here including PGRES_POLLING_ACTIVE
abort();
break;
}

Expand Down
28 changes: 15 additions & 13 deletions ext-src/swoole_postgresql_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1533,12 +1533,16 @@ static PHP_METHOD(swoole_postgresql_coro, createLOB) {
}

static PHP_METHOD(swoole_postgresql_coro, openLOB) {
Oid oid = 0;
char *modestr = "rb";
size_t modestrlen;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "l|s", &oid, &modestr, &modestrlen)) {
RETURN_THROWS();
}
zend_long oid = 0;
// default: "rb"
zend_string *mode_str = NULL;
int mode = INV_READ;

ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_LONG(oid)
Z_PARAM_OPTIONAL
Z_PARAM_STR(mode_str)
ZEND_PARSE_PARAMETERS_END();

PGObject *object = php_swoole_postgresql_coro_get_object(ZEND_THIS);
if (!object || !object->conn) {
Expand All @@ -1549,9 +1553,7 @@ static PHP_METHOD(swoole_postgresql_coro, openLOB) {
RETURN_FALSE;
}

int mode = INV_READ;

if (strpbrk(modestr, "+w")) {
if (mode_str && strpbrk(ZSTR_VAL(mode_str), "+w")) {
mode = INV_READ | INV_WRITE;
}

Expand Down Expand Up @@ -1579,11 +1581,11 @@ static PHP_METHOD(swoole_postgresql_coro, openLOB) {
}

static PHP_METHOD(swoole_postgresql_coro, unlinkLOB) {
Oid oid = 0;
zend_long oid = 0;

if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &oid)) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_LONG(oid)
ZEND_PARSE_PARAMETERS_END();

PGObject *object = php_swoole_postgresql_coro_get_object(ZEND_THIS);
if (!object || !object->conn) {
Expand Down
2 changes: 1 addition & 1 deletion ext-src/swoole_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ static php_stream *socket_create(const char *proto,

stream = php_stream_alloc_rel(&socket_ops, abstract, persistent_id, "r+");
if (stream == nullptr) {
pefree(abstract, persistent_id ? 1 : 0);
delete abstract;
goto _failed;
}

Expand Down
2 changes: 1 addition & 1 deletion src/protocol/base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int Protocol::recv_with_length_protocol(network::Socket *socket, String *buffer)
PacketLength pl{};
ssize_t package_length;
uint8_t _package_length_size = get_package_length_size ? get_package_length_size(socket) : package_length_size;
uint32_t recv_size;
uint32_t recv_size = 0;
ssize_t recv_n = 0;

// protocol error
Expand Down

0 comments on commit 9ce89a8

Please sign in to comment.