启用constVariablePointer检查并修复6处指针const化
.pre-commit-config.yaml: 移除 --suppress=constVariablePointer net_select.c: 5 处 p_sock 改 const net_sock_t *(仅只读使用) net_socket.c: net_getsockname 的 p_sock 改 const(只读字段) docs/代码规范/cppcheck使用说明.md: 同步抑制表与处理记录
This commit is contained in:
@@ -78,7 +78,7 @@ int net_select(int nfds, net_fd_set *readfds, net_fd_set *writefds,
|
||||
|
||||
/* 检查哪个 Socket 有事件 */
|
||||
for (i = 0; i < nfds && i < NET_MAX_SOCKETS; i++) {
|
||||
net_sock_t *p_sock = net_get_sock(i);
|
||||
const net_sock_t *p_sock = net_get_sock(i);
|
||||
|
||||
if (NULL == p_sock) {
|
||||
continue;
|
||||
@@ -178,7 +178,7 @@ int net_poll_events(net_pollfd *fds, int nfds, int timeout) {
|
||||
continue;
|
||||
}
|
||||
|
||||
net_sock_t *p_sock = net_get_sock(fds[i].fd);
|
||||
const net_sock_t *p_sock = net_get_sock(fds[i].fd);
|
||||
|
||||
if (NULL == p_sock) {
|
||||
fds[i].revents |= NET_POLLNVAL;
|
||||
@@ -247,7 +247,7 @@ int net_poll_events(net_pollfd *fds, int nfds, int timeout) {
|
||||
* 2. 已建立连接且接收缓冲区长度大于 0 时视为可读
|
||||
*/
|
||||
static int check_socket_readable(int sockfd) {
|
||||
net_sock_t *p_sock;
|
||||
const net_sock_t *p_sock;
|
||||
|
||||
p_sock = net_get_sock(sockfd);
|
||||
if (NULL == p_sock) {
|
||||
@@ -277,7 +277,7 @@ static int check_socket_readable(int sockfd) {
|
||||
* 函数说明:1. 仅已建立连接且 send_ready 标志置位的 Socket 视为可写
|
||||
*/
|
||||
static int check_socket_writable(int sockfd) {
|
||||
net_sock_t *p_sock;
|
||||
const net_sock_t *p_sock;
|
||||
|
||||
p_sock = net_get_sock(sockfd);
|
||||
if (NULL == p_sock) {
|
||||
@@ -304,7 +304,7 @@ static int check_socket_writable(int sockfd) {
|
||||
* 2. 未分配(net_get_sock 返回 NULL)的 Socket 视为错误
|
||||
*/
|
||||
static int check_socket_error(int sockfd) {
|
||||
net_sock_t *p_sock;
|
||||
const net_sock_t *p_sock;
|
||||
|
||||
/* 无效 fd 视为错误 */
|
||||
if ((0 > sockfd) || (NET_MAX_SOCKETS <= sockfd)) {
|
||||
|
||||
Reference in New Issue
Block a user