Skip to content

Commit 3096a80

Browse files
authored
Fix coverity issues 2 (#3769)
* update supported.md * fix printf type * fix 2
1 parent 962e257 commit 3096a80

File tree

11 files changed

+31
-22
lines changed

11 files changed

+31
-22
lines changed

SUPPORTED.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ Supported Versions
22
---
33
| Branch | Initialization | Active Support Until | Security Support Until |
44
| ---------------------------------------------------------- | -------------- | -------------------- | ---------------------- |
5-
| [v4.3.x](https://github.com/swoole/swoole-src/tree/v4.3.x) | 2019-2-7 | 2019-9-30 | 2019-12-31 |
65
| [v4.4.x](https://github.com/swoole/swoole-src/tree/v4.4.x) | 2019-4-15 | 2020-4-30 | 2020-7-31 |
76
| [v4.5.x](https://github.com/swoole/swoole-src/tree/master) | 2019-12-20 | 2020-12-31 | 2021-3-31 |
87

@@ -18,3 +17,4 @@ Unsupported Branches
1817
- `v1.x` (2012-7-1 ~ 2018-05-14)
1918
- `v2.x` (2016-12-30 ~ 2018-05-23)
2019
- `v4.0.x`, `v4.1.x`, `v4.2.x` (2018-06-14 ~ 2019-02-02)
20+
- `v4.3.x` (2019-2-7 ~ 2019-12-31)

ext-src/swoole_client.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static PHP_METHOD(swoole_client, getSocket);
126126
SW_EXTERN_C_END
127127

128128
#ifdef PHP_SWOOLE_CLIENT_USE_POLL
129-
static int client_poll_add(zval *sock_array, int index, struct pollfd *fds, int maxevents, int event);
129+
static uint32_t client_poll_add(zval *sock_array, uint32_t index, struct pollfd *fds, int maxevents, int event);
130130
static int client_poll_wait(zval *sock_array, struct pollfd *fds, int maxevents, int n_event, int revent);
131131
#else
132132
static int client_select_add(zval *sock_array, fd_set *fds, int *max_fd);
@@ -1354,7 +1354,8 @@ static PHP_METHOD(swoole_client, shutdown) {
13541354
PHP_FUNCTION(swoole_client_select) {
13551355
#ifdef PHP_SWOOLE_CLIENT_USE_POLL
13561356
zval *r_array, *w_array, *e_array;
1357-
int retval, index = 0;
1357+
int retval;
1358+
uint32_t index = 0;
13581359
double timeout = SW_CLIENT_CONNECT_TIMEOUT;
13591360

13601361
if (zend_parse_parameters(ZEND_NUM_ARGS(), "a!a!a!|d", &r_array, &w_array, &e_array, &timeout) == FAILURE) {
@@ -1374,7 +1375,7 @@ PHP_FUNCTION(swoole_client_select) {
13741375
if (e_array != nullptr && php_swoole_array_length(e_array) > 0) {
13751376
index = client_poll_add(e_array, index, fds, maxevents, POLLHUP);
13761377
}
1377-
if (index <= 0) {
1378+
if (index == 0) {
13781379
efree(fds);
13791380
php_swoole_fatal_error(E_WARNING, "no resource arrays were passed to select");
13801381
RETURN_FALSE;
@@ -1503,13 +1504,13 @@ static int client_poll_wait(zval *sock_array, struct pollfd *fds, int maxevents,
15031504

15041505
zval_ptr_dtor(sock_array);
15051506
ZVAL_COPY_VALUE(sock_array, &new_array);
1506-
return num ? 1 : 0;
1507+
return num;
15071508
}
15081509

1509-
static int client_poll_add(zval *sock_array, int index, struct pollfd *fds, int maxevents, int event) {
1510+
static uint32_t client_poll_add(zval *sock_array, uint32_t index, struct pollfd *fds, int maxevents, int event) {
15101511
zval *element = nullptr;
15111512
if (!ZVAL_IS_ARRAY(sock_array)) {
1512-
return -1;
1513+
return 0;
15131514
}
15141515

15151516
int sock;

ext-src/swoole_http_request.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ static int http_request_on_header_value(swoole_http_parser *parser, const char *
462462
boundary_len = tmp - boundary_str;
463463
}
464464
if (boundary_len <= 0) {
465-
swWarn("invalid multipart/form-data body fd:%d", ctx->fd);
465+
swWarn("invalid multipart/form-data body fd:%ld", ctx->fd);
466466
return -1;
467467
}
468468
// trim '"'

include/swoole_coroutine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class Coroutine {
176176
long init_msec = Timer::get_absolute_msec();
177177
void *task = nullptr;
178178
coroutine::Context ctx;
179-
Coroutine *origin;
179+
Coroutine *origin = nullptr;
180180

181181
Coroutine(const coroutine_func_t &fn, void *private_data) : ctx(stack_size, fn, private_data) {
182182
cid = ++last_cid;

src/core/base.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ size_t swDataHead::dump(char *_buf, size_t _len) {
799799
_len,
800800
"swDataHead[%p]\n"
801801
"{\n"
802-
" int fd = %d;\n"
802+
" long fd = %ld;\n"
803803
" uint32_t len = %d;\n"
804804
" int16_t reactor_id = %d;\n"
805805
" uint8_t type = %d;\n"

src/os/file.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ size_t File::write_all(const void *data, size_t len) {
125125
if (errno == EINTR) {
126126
continue;
127127
} else if (!(errno == EAGAIN || errno == EWOULDBLOCK)) {
128-
swSysWarn("pwrite(%d, %p, %llu, %llu) failed", fd_, data, len - written_bytes, written_bytes);
128+
swSysWarn("pwrite(%d, %p, %lu, %lu) failed", fd_, data, len - written_bytes, written_bytes);
129129
}
130130
break;
131131
}
@@ -145,7 +145,7 @@ size_t File::read_all(void *buf, size_t len) {
145145
if (errno == EINTR) {
146146
continue;
147147
} else if (!(errno == EAGAIN || errno == EWOULDBLOCK)) {
148-
swSysWarn("pread(%d, %p, %llu, %llu) failed", fd_, buf, len - read_bytes, read_bytes);
148+
swSysWarn("pread(%d, %p, %lu, %lu) failed", fd_, buf, len - read_bytes, read_bytes);
149149
}
150150
break;
151151
}

src/protocol/redis.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ int swRedis_recv_packet(Protocol *protocol, Connection *conn, String *buffer) {
106106
request->state = SW_REDIS_RECEIVE_LENGTH;
107107
break;
108108
}
109+
if (p == nullptr) {
110+
goto _failed;
111+
}
109112
/* no break */
110113

111114
case SW_REDIS_RECEIVE_LENGTH:
@@ -124,6 +127,9 @@ int swRedis_recv_packet(Protocol *protocol, Connection *conn, String *buffer) {
124127
else if (*p == ':' && (p = swRedis_get_number(p, &ret))) {
125128
break;
126129
}
130+
if (p == nullptr) {
131+
goto _failed;
132+
}
127133
/* no break */
128134

129135
case SW_REDIS_RECEIVE_STRING:

src/server/base.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ static bool swFactory_dispatch(Factory *factory, SendData *task) {
5454
if (Server::is_stream_event(task->info.type)) {
5555
conn = serv->get_connection(task->info.fd);
5656
if (conn == nullptr || conn->active == 0) {
57-
swWarn("dispatch[type=%d] failed, connection#%d is not active", task->info.type, task->info.fd);
57+
swWarn("dispatch[type=%d] failed, socket#%ld is not active", task->info.type, task->info.fd);
5858
return false;
5959
}
6060
// server active close, discard data.
6161
if (conn->closed) {
62-
swWarn("dispatch[type=%d] failed, connection#%d is closed by server", task->info.type, task->info.fd);
62+
swWarn("dispatch[type=%d] failed, socket#%ld is closed by server", task->info.type, task->info.fd);
6363
return false;
6464
}
6565
// converted fd to session_id
@@ -95,12 +95,12 @@ static bool swFactory_notify(Factory *factory, DataHead *info) {
9595
Server *serv = (Server *) factory->ptr;
9696
Connection *conn = serv->get_connection(info->fd);
9797
if (conn == nullptr || conn->active == 0) {
98-
swWarn("dispatch[type=%d] failed, socket#%lld is not active", info->type, info->fd);
98+
swWarn("dispatch[type=%d] failed, socket#%ld is not active", info->type, info->fd);
9999
return false;
100100
}
101101
// server active close, discard data.
102102
if (conn->closed) {
103-
swWarn("dispatch[type=%d] failed, session#%lld is closed by server", info->type, conn->session_id);
103+
swWarn("dispatch[type=%d] failed, session#%ld is closed by server", info->type, conn->session_id);
104104
return false;
105105
}
106106
// converted fd to session_id

src/server/port.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static int Port_onRead_check_length(Reactor *reactor, ListenPort *port, Event *e
282282
return SW_OK;
283283
}
284284

285-
#define CLIENT_INFO_FMT " from session#%lld on %s:%d"
285+
#define CLIENT_INFO_FMT " from session#%ld on %s:%d"
286286
#define CLIENT_INFO_ARGS conn->session_id, port->host.c_str(), port->port
287287

288288
/**

src/server/reactor_thread.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static void ReactorThread_onStreamResponse(Stream *stream, const char *data, uin
9898
SessionId session_id = stream->private_data_fd;
9999

100100
if (!conn->active || session_id != conn->session_id) {
101-
swoole_error_log(SW_LOG_NOTICE, SW_ERROR_SESSION_NOT_EXIST, "session#%lld does not exists", session_id);
101+
swoole_error_log(SW_LOG_NOTICE, SW_ERROR_SESSION_NOT_EXIST, "session#%ld does not exists", session_id);
102102
return;
103103
}
104104
if (data == nullptr) {
@@ -499,7 +499,7 @@ static int ReactorThread_onPipeWrite(Reactor *reactor, Event *ev) {
499499
} else if (serv->discard_timeout_request) {
500500
swoole_error_log(SW_LOG_WARNING,
501501
SW_ERROR_SESSION_DISCARD_TIMEOUT_DATA,
502-
"[1] ignore data[%u bytes] received from session#%lld",
502+
"[1] ignore data[%u bytes] received from session#%ld",
503503
send_data->info.len,
504504
send_data->info.fd);
505505
goto _discard;

0 commit comments

Comments
 (0)