Browse Source

optimize #477: rm compile warnings

ithewei 2 years ago
parent
commit
7cdb4ec45e
5 changed files with 16 additions and 11 deletions
  1. 4 4
      base/hsocket.c
  2. 4 1
      base/hsocket.h
  3. 3 1
      event/epoll.c
  4. 1 1
      http/server/HttpHandler.cpp
  5. 4 4
      http/server/HttpService.h

+ 4 - 4
base/hsocket.c

@@ -348,7 +348,7 @@ int Socketpair(int family, int type, int protocol, int sv[2]) {
     WSAInit();
 #endif
     int listenfd, connfd, acceptfd;
-    listenfd = connfd = acceptfd = INVALID_SOCKET;
+    listenfd = connfd = acceptfd = -1;
     struct sockaddr_in localaddr;
     socklen_t addrlen = sizeof(localaddr);
     memset(&localaddr, 0, addrlen);
@@ -395,13 +395,13 @@ int Socketpair(int family, int type, int protocol, int sv[2]) {
     sv[1] = acceptfd;
     return 0;
 error:
-    if (listenfd != INVALID_SOCKET) {
+    if (listenfd != -1) {
         closesocket(listenfd);
     }
-    if (connfd != INVALID_SOCKET) {
+    if (connfd != -1) {
         closesocket(connfd);
     }
-    if (acceptfd != INVALID_SOCKET) {
+    if (acceptfd != -1) {
         closesocket(acceptfd);
     }
     return -1;

+ 4 - 1
base/hsocket.h

@@ -32,7 +32,8 @@ HV_EXPORT const char* socket_strerror(int err);
 
 #ifdef OS_WIN
 
-typedef int socklen_t;
+typedef SOCKET  hsocket_t;
+typedef int     socklen_t;
 
 void WSAInit();
 void WSADeinit();
@@ -63,6 +64,8 @@ HV_INLINE int nonblocking(int sockfd) {
 
 #else
 
+typedef int     hsocket_t;
+
 #define blocking(s)     fcntl(s, F_SETFL, fcntl(s, F_GETFL) & ~O_NONBLOCK)
 #define nonblocking(s)  fcntl(s, F_SETFL, fcntl(s, F_GETFL) |  O_NONBLOCK)
 

+ 3 - 1
event/epoll.c

@@ -7,8 +7,10 @@
 
 #ifdef OS_WIN
 #include "wepoll/wepoll.h"
+typedef HANDLE  epoll_handle_t;
 #else
 #include <sys/epoll.h>
+typedef int     epoll_handle_t;
 #define epoll_close(epfd) close(epfd)
 #endif
 
@@ -17,7 +19,7 @@
 ARRAY_DECL(struct epoll_event, events);
 
 typedef struct epoll_ctx_s {
-    int                 epfd;
+    epoll_handle_t      epfd;
     struct events       events;
 } epoll_ctx_t;
 

+ 1 - 1
http/server/HttpHandler.cpp

@@ -368,7 +368,7 @@ int HttpHandler::handleRequestHeaders() {
     pReq->ParseUrl();
     // printf("path=%s\n",  pReq->path.c_str());
     // fix CVE-2023-26147
-    if (pReq->path.find("\%") != std::string::npos) {
+    if (pReq->path.find("%") != std::string::npos) {
         std::string unescaped_path = HUrl::unescape(pReq->path);
         if (unescaped_path.find("\r\n") != std::string::npos) {
             hlogw("Illegal path: %s\n",  unescaped_path.c_str());

+ 4 - 4
http/server/HttpService.h

@@ -55,10 +55,10 @@ struct http_handler {
     http_handler(http_ctx_handler fn)   : ctx_handler(std::move(fn))    {}
     http_handler(http_state_handler fn) : state_handler(std::move(fn))  {}
     http_handler(const http_handler& rhs)
-        : sync_handler(std::move(rhs.sync_handler))
-        , async_handler(std::move(rhs.async_handler))
-        , ctx_handler(std::move(rhs.ctx_handler))
-        , state_handler(std::move(rhs.state_handler))
+        : sync_handler(std::move(const_cast<http_handler&>(rhs).sync_handler))
+        , async_handler(std::move(const_cast<http_handler&>(rhs).async_handler))
+        , ctx_handler(std::move(const_cast<http_handler&>(rhs).ctx_handler))
+        , state_handler(std::move(const_cast<http_handler&>(rhs).state_handler))
     {}
 
     const http_handler& operator=(http_sync_handler fn) {