Skip to content

Commit 9ce89a8

Browse files
authored
Fix compiler warning (#5318)
* 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
1 parent 31ee745 commit 9ce89a8

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

ext-src/swoole_client_coro.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ static PHP_METHOD(swoole_client_coro, peek) {
505505

506506
CLIENT_CORO_GET_SOCKET_SAFE(cli);
507507

508-
buf = (char *) emalloc(buf_len + 1);
508+
buf = (char *) emalloc((size_t)buf_len + 1);
509509
ret = cli->peek(buf, buf_len);
510510
if (ret < 0) {
511511
php_swoole_socket_set_error_properties(ZEND_THIS, cli);

ext-src/swoole_pgsql.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ PGconn *swoole_pgsql_connectdb(const char *conninfo) {
101101
event = SW_EVENT_WRITE;
102102
break;
103103
default:
104+
// should not be here including PGRES_POLLING_ACTIVE
105+
abort();
104106
break;
105107
}
106108

ext-src/swoole_postgresql_coro.cc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,12 +1533,16 @@ static PHP_METHOD(swoole_postgresql_coro, createLOB) {
15331533
}
15341534

15351535
static PHP_METHOD(swoole_postgresql_coro, openLOB) {
1536-
Oid oid = 0;
1537-
char *modestr = "rb";
1538-
size_t modestrlen;
1539-
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "l|s", &oid, &modestr, &modestrlen)) {
1540-
RETURN_THROWS();
1541-
}
1536+
zend_long oid = 0;
1537+
// default: "rb"
1538+
zend_string *mode_str = NULL;
1539+
int mode = INV_READ;
1540+
1541+
ZEND_PARSE_PARAMETERS_START(1, 2)
1542+
Z_PARAM_LONG(oid)
1543+
Z_PARAM_OPTIONAL
1544+
Z_PARAM_STR(mode_str)
1545+
ZEND_PARSE_PARAMETERS_END();
15421546

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

1552-
int mode = INV_READ;
1553-
1554-
if (strpbrk(modestr, "+w")) {
1556+
if (mode_str && strpbrk(ZSTR_VAL(mode_str), "+w")) {
15551557
mode = INV_READ | INV_WRITE;
15561558
}
15571559

@@ -1579,11 +1581,11 @@ static PHP_METHOD(swoole_postgresql_coro, openLOB) {
15791581
}
15801582

15811583
static PHP_METHOD(swoole_postgresql_coro, unlinkLOB) {
1582-
Oid oid = 0;
1584+
zend_long oid = 0;
15831585

1584-
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &oid)) {
1585-
RETURN_THROWS();
1586-
}
1586+
ZEND_PARSE_PARAMETERS_START(1, 1)
1587+
Z_PARAM_LONG(oid)
1588+
ZEND_PARSE_PARAMETERS_END();
15871589

15881590
PGObject *object = php_swoole_postgresql_coro_get_object(ZEND_THIS);
15891591
if (!object || !object->conn) {

ext-src/swoole_runtime.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ static php_stream *socket_create(const char *proto,
10981098

10991099
stream = php_stream_alloc_rel(&socket_ops, abstract, persistent_id, "r+");
11001100
if (stream == nullptr) {
1101-
pefree(abstract, persistent_id ? 1 : 0);
1101+
delete abstract;
11021102
goto _failed;
11031103
}
11041104

src/protocol/base.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int Protocol::recv_with_length_protocol(network::Socket *socket, String *buffer)
110110
PacketLength pl{};
111111
ssize_t package_length;
112112
uint8_t _package_length_size = get_package_length_size ? get_package_length_size(socket) : package_length_size;
113-
uint32_t recv_size;
113+
uint32_t recv_size = 0;
114114
ssize_t recv_n = 0;
115115

116116
// protocol error

0 commit comments

Comments
 (0)