Browse Source

[Pal/Linux] Turn on -Wsign-compare and fix the produced warnings

Michał Kowalczyk 5 years ago
parent
commit
4fe1365d05

+ 2 - 2
Pal/lib/api.h

@@ -151,8 +151,8 @@ int snprintf (char * buf, int n, const char * fmt, ...);
 
 /* Miscelleneous */
 
-int inet_pton4 (const char *src, int len, void *dst);
-int inet_pton6 (const char *src, int len, void *dst);
+int inet_pton4 (const char *src, size_t len, void *dst);
+int inet_pton6 (const char *src, size_t len, void *dst);
 
 uint32_t __htonl (uint32_t x);
 uint32_t __ntohl (uint32_t x);

+ 2 - 2
Pal/lib/network/inet_pton.c

@@ -39,7 +39,7 @@
  * author:
  *    Paul Vixie, 1996.
  */
-int inet_pton4 (const char *src, int len, void *dstp)
+int inet_pton4 (const char *src, size_t len, void *dstp)
 {
     unsigned char *dst = (unsigned char *) dstp;
     const char *end = src + len;
@@ -95,7 +95,7 @@ static int tolower (char c)
  * author:
  *    Paul Vixie, 1996.
  */
-int inet_pton6 (const char *src, int len, void *dstp)
+int inet_pton6 (const char *src, size_t len, void *dstp)
 {
     unsigned char *dst = (unsigned char *) dstp;
     const char *end = src + len;

+ 1 - 1
Pal/src/host/Linux/Makefile

@@ -23,7 +23,7 @@ all: $(host_files)
 
 ifeq ($(DEBUG),1)
 CC += -gdwarf-2 -g3
-CFLAGS += -DDEBUG
+CFLAGS += -DDEBUG -Wsign-compare
 export DEBUG
 endif
 

+ 2 - 2
Pal/src/host/Linux/db_devices.c

@@ -195,7 +195,7 @@ static int64_t char_read(PAL_HANDLE handle, uint64_t offset, uint64_t size, void
 
     int fd = handle->dev.fd_in;
 
-    if (fd == PAL_IDX_POISON)
+    if ((PAL_IDX)fd == PAL_IDX_POISON)
         return -PAL_ERROR_DENIED;
 
     int64_t bytes = INLINE_SYSCALL(read, 3, fd, buffer, size);
@@ -213,7 +213,7 @@ static int64_t char_write(PAL_HANDLE handle, uint64_t offset, uint64_t size, con
 
     int fd = handle->dev.fd_out;
 
-    if (fd == PAL_IDX_POISON)
+    if ((PAL_IDX)fd == PAL_IDX_POISON)
         return -PAL_ERROR_DENIED;
 
     int64_t bytes = INLINE_SYSCALL(write, 3, fd, buffer, size);

+ 1 - 1
Pal/src/host/Linux/db_exception.c

@@ -351,7 +351,7 @@ void signal_setup (void)
         PAL_EVENT_RESUME,
     };
 
-    for (int e = 0 ; e < sizeof(events) / sizeof(events[0]) ; e++)
+    for (size_t e = 0 ; e < sizeof(events) / sizeof(events[0]) ; e++)
         if ((ret = _DkPersistentSighandlerSetup(events[e])) < 0)
             goto err;
 

+ 6 - 6
Pal/src/host/Linux/db_files.c

@@ -57,7 +57,7 @@ static int file_open (PAL_HANDLE * handle, const char * type, const char * uri,
         return unix_to_pal_error(ERRNO(ret));
 
     /* if try_create_path succeeded, prepare for the file handle */
-    int len = strlen(uri);
+    size_t len = strlen(uri);
     PAL_HANDLE hdl = malloc(HANDLE_SIZE(file) + len + 1);
     SET_HANDLE_TYPE(hdl, file);
     HANDLE_HDR(hdl)->flags |= RFD(0)|WFD(0)|WRITEABLE(0);
@@ -315,7 +315,7 @@ static int file_getname (PAL_HANDLE handle, char * buffer, size_t count)
     if (!handle->file.realpath)
         return 0;
 
-    int len = strlen(handle->file.realpath);
+    size_t len = strlen(handle->file.realpath);
     char * tmp = strcpy_static(buffer, "file:", count);
 
     if (!tmp || buffer + count < tmp + len + 1)
@@ -373,7 +373,7 @@ static int dir_open (PAL_HANDLE * handle, const char * type, const char * uri,
     if (IS_ERR(ret))
         return unix_to_pal_error(ERRNO(ret));
 
-    int len = strlen(uri);
+    size_t len = strlen(uri);
     PAL_HANDLE hdl = malloc(HANDLE_SIZE(dir) + len + 1);
     SET_HANDLE_TYPE(hdl, dir);
     HANDLE_HDR(hdl)->flags |= RFD(0);
@@ -411,7 +411,7 @@ struct linux_dirent64 {
 
 /* 'read' operation for directory stream. Directory stream will not
    need a 'write' operat4on. */
-int64_t dir_read (PAL_HANDLE handle, uint64_t offset, uint64_t count, void * buf)
+int64_t dir_read (PAL_HANDLE handle, uint64_t offset, size_t count, void * buf)
 {
     if (offset)
         return -PAL_ERROR_INVAL;
@@ -451,7 +451,7 @@ output:
                 goto next;
 
             bool isdir = (d->d_type == DT_DIR);
-            int len = strlen(d->d_name);
+            size_t len = strlen(d->d_name);
             if (len + (isdir ? 2 : 1) > count)
                 break;
 
@@ -557,7 +557,7 @@ static int dir_getname (PAL_HANDLE handle, char * buffer, size_t count)
     if (!handle->dir.realpath)
         return 0;
 
-    int len = strlen(handle->dir.realpath);
+    size_t len = strlen(handle->dir.realpath);
     char * tmp = strcpy_static(buffer, "dir:", count);
 
     if (!tmp || buffer + count < tmp + len + 1)

+ 8 - 5
Pal/src/host/Linux/db_memory.c

@@ -40,7 +40,7 @@ bool _DkCheckMemoryMappable (const void * addr, size_t size)
     return (addr < DATA_END && addr + size > TEXT_START);
 }
 
-int _DkVirtualMemoryAlloc (void ** paddr, uint64_t size, int alloc_type,
+int _DkVirtualMemoryAlloc (void ** paddr, size_t size, int alloc_type,
                            int prot)
 {
     void * addr = *paddr, * mem = addr;
@@ -58,14 +58,14 @@ int _DkVirtualMemoryAlloc (void ** paddr, uint64_t size, int alloc_type,
     return 0;
 }
 
-int _DkVirtualMemoryFree (void * addr, uint64_t size)
+int _DkVirtualMemoryFree (void * addr, size_t size)
 {
     int ret = INLINE_SYSCALL(munmap, 2, addr, size);
 
     return IS_ERR(ret) ? unix_to_pal_error(ERRNO(ret)) : 0;
 }
 
-int _DkVirtualMemoryProtect (void * addr, uint64_t size, int prot)
+int _DkVirtualMemoryProtect (void * addr, size_t size, int prot)
 {
     int ret = INLINE_SYSCALL(mprotect, 3, addr, size, HOST_PROT(prot));
 
@@ -80,7 +80,10 @@ static int read_proc_meminfo (const char * key, unsigned long * val)
         return -PAL_ERROR_DENIED;
 
     char buffer[40];
-    int r = 0, n, ret = 0, len = strlen(key);
+    int ret = 0;
+    size_t n;
+    size_t r = 0;
+    size_t len = strlen(key);
 
     ret = -PAL_ERROR_DENIED;
     while (1) {
@@ -101,7 +104,7 @@ static int read_proc_meminfo (const char * key, unsigned long * val)
         }
 
         if (!memcmp(key, buffer, len) && buffer[len] == ':') {
-            for (int i = len + 1; i < n ; i++)
+            for (size_t i = len + 1; i < n ; i++)
                 if (buffer[i] != ' ') {
                     *val = atol(buffer + i);
                     break;

+ 2 - 2
Pal/src/host/Linux/db_misc.c

@@ -146,14 +146,14 @@ size_t _DkRandomBitsRead (void * buffer, size_t size)
         pal_sec.random_device = fd;
     }
 
-    int total_bytes = 0;
+    size_t total_bytes = 0;
     do {
         int bytes = INLINE_SYSCALL(read, 3, pal_sec.random_device,
                                    buffer + total_bytes, size - total_bytes);
         if (IS_ERR(bytes))
             return -PAL_ERROR_DENIED;
 
-        total_bytes += bytes;
+        total_bytes += (size_t)bytes;
     } while (total_bytes < size);
 
     return 0;

+ 1 - 1
Pal/src/host/Linux/db_object.c

@@ -250,7 +250,7 @@ int _DkObjectsWaitAny (int count, PAL_HANDLE * handleArray, PAL_NUM timeout,
 
         for (j = 0 ; j < MAX_FDS ; j++)
             if ((HANDLE_HDR(hdl)->flags & (RFD(j)|WFD(j))) &&
-                hdl->generic.fds[j] == fds[i].fd)
+                hdl->generic.fds[j] == (PAL_IDX)fds[i].fd)
                 break;
 
         if (j == MAX_FDS)

+ 7 - 7
Pal/src/host/Linux/db_pipes.c

@@ -379,7 +379,7 @@ static int64_t pipe_read (PAL_HANDLE handle, uint64_t offset, uint64_t len,
 }
 
 /* 'write' operation of pipe stream. offset does not apply here. */
-static int64_t pipe_write (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+static int64_t pipe_write (PAL_HANDLE handle, uint64_t offset, size_t len,
                            const void * buffer)
 {
     if (offset)
@@ -424,14 +424,14 @@ static int64_t pipe_write (PAL_HANDLE handle, uint64_t offset, uint64_t len,
     PAL_FLG writeable = IS_HANDLE_TYPE(handle, pipeprv) ? WRITEABLE(1) :
                         WRITEABLE(0);
 
-    if (IS_ERR(bytes))
-        bytes = unix_to_pal_error(ERRNO(bytes));
-
-    if (bytes == len)
+    if (!IS_ERR(bytes) && (size_t)bytes == len)
         HANDLE_HDR(handle)->flags |= writeable;
     else
         HANDLE_HDR(handle)->flags &= ~writeable;
 
+    if (IS_ERR(bytes))
+        bytes = unix_to_pal_error(ERRNO(bytes));
+
     return bytes;
 }
 
@@ -579,11 +579,11 @@ static int pipe_attrsetbyhdl (PAL_HANDLE handle, PAL_STREAM_ATTR * attr)
 
 static int pipe_getname (PAL_HANDLE handle, char * buffer, size_t count)
 {
-    int old_count = count;
+    size_t old_count = count;
     int ret;
 
     const char * prefix = NULL;
-    int prefix_len = 0;
+    size_t prefix_len = 0;
 
     switch (PAL_GET_TYPE(handle)) {
         case pal_type_pipesrv:

+ 9 - 10
Pal/src/host/Linux/db_process.c

@@ -212,7 +212,7 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args)
 
     /* step 3: compose process parameter */
 
-    int parent_datasz = 0, exec_datasz = 0, manifest_datasz = 0;
+    size_t parent_datasz = 0, exec_datasz = 0, manifest_datasz = 0;
     void * parent_data = NULL;
     void * exec_data = NULL;
     void * manifest_data = NULL;
@@ -220,7 +220,7 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args)
     ret = handle_serialize(parent_handle, &parent_data);
     if (ret < 0)
         goto out;
-    parent_datasz = ret;
+    parent_datasz = (size_t)ret;
 
     if (exec) {
         ret = handle_serialize(exec, &exec_data);
@@ -228,7 +228,7 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args)
             free(parent_data);
             goto out;
         }
-        exec_datasz = ret;
+        exec_datasz = (size_t)ret;
     }
 
     if (pal_state.manifest_handle) {
@@ -238,12 +238,11 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args)
             free(exec_data);
             goto out;
         }
-        manifest_datasz = ret;
+        manifest_datasz = (size_t)ret;
     }
 
-    unsigned int datasz = parent_datasz + exec_datasz + manifest_datasz;
-    struct proc_args * proc_args =
-            __alloca(sizeof(struct proc_args) + datasz);
+    size_t datasz = parent_datasz + exec_datasz + manifest_datasz;
+    struct proc_args * proc_args = __alloca(sizeof(struct proc_args) + datasz);
 
     proc_args->parent_process_id = linux_state.parent_process_id;
     memcpy(&proc_args->pal_sec, &pal_sec, sizeof(struct pal_sec));
@@ -311,8 +310,7 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args)
                          proc_args,
                          sizeof(struct proc_args) + datasz);
 
-    if (IS_ERR(ret) ||
-        ret < sizeof(struct proc_args) + datasz) {
+    if (IS_ERR(ret) || (size_t)ret < sizeof(struct proc_args) + datasz) {
         ret = -PAL_ERROR_DENIED;
         goto out;
     }
@@ -546,7 +544,8 @@ static int64_t proc_write (PAL_HANDLE handle, uint64_t offset, uint64_t count,
                 return -PAL_ERROR_DENIED;
         }
 
-    if (bytes == count)
+    assert(!IS_ERR(bytes));
+    if ((size_t)bytes == count)
         HANDLE_HDR(handle)->flags |= WRITEABLE(1);
     else
         HANDLE_HDR(handle)->flags &= ~WRITEABLE(1);

+ 44 - 42
Pal/src/host/Linux/db_sockets.c

@@ -79,15 +79,15 @@ static size_t addr_size(const struct sockaddr* addr) {
 
 /* parsing the string of uri, and fill in the socket address structure.
    the latest pointer of uri, length of socket address are returned. */
-static int inet_parse_uri (char ** uri, struct sockaddr * addr, int * addrlen)
+static int inet_parse_uri (char ** uri, struct sockaddr * addr, size_t * addrlen)
 {
     char * tmp = *uri, * end;
     char * addr_str = NULL, * port_str;
     int af;
     void * addr_buf;
-    int addr_len;
+    size_t addr_len;
     __be16 * port_buf;
-    int slen;
+    size_t slen;
 
     if (tmp[0] == '[') {
         /* for IPv6, the address will be in the form of
@@ -149,10 +149,10 @@ inval:
 }
 
 /* create the string of uri from the given socket address */
-static int inet_create_uri (char * uri, int count, struct sockaddr * addr,
-                            int addrlen)
+static int inet_create_uri (char * uri, size_t count, struct sockaddr * addr,
+                            size_t addrlen)
 {
-    int len = 0;
+    size_t len = 0;
 
     if (addr->sa_family == AF_INET) {
         if (addrlen != sizeof(struct sockaddr_in))
@@ -196,8 +196,8 @@ static int inet_create_uri (char * uri, int count, struct sockaddr * addr,
    of uri will be either "bind-addr:bind-port:connect-addr:connect-port"
    or "addr:port". */
 static int socket_parse_uri (char * uri,
-                             struct sockaddr ** bind_addr, int * bind_addrlen,
-                             struct sockaddr ** dest_addr, int * dest_addrlen)
+                             struct sockaddr ** bind_addr, size_t * bind_addrlen,
+                             struct sockaddr ** dest_addr, size_t * dest_addrlen)
 {
     int ret;
 
@@ -238,8 +238,8 @@ static int socket_parse_uri (char * uri,
 /* fill in the PAL handle based on the file descriptors and address given. */
 static inline
 PAL_HANDLE socket_create_handle (int type, int fd, int options,
-                                 struct sockaddr * bind_addr, int bind_addrlen,
-                                 struct sockaddr * dest_addr, int dest_addrlen)
+                                 struct sockaddr * bind_addr, size_t bind_addrlen,
+                                 struct sockaddr * dest_addr, size_t dest_addrlen)
 {
     PAL_HANDLE hdl = malloc(HANDLE_SIZE(sock) + (bind_addr ? bind_addrlen : 0) +
                             (dest_addr ? dest_addrlen : 0));
@@ -275,7 +275,8 @@ PAL_HANDLE socket_create_handle (int type, int fd, int options,
         hdl->sock.receivebuf     = 0;
         hdl->sock.sendbuf        = 0;
     } else {
-        int ret, val, len = sizeof(int);
+        int ret, val;
+        socklen_t len = sizeof(int);
 
         ret = INLINE_SYSCALL(getsockopt, 5, fd, SOL_SOCKET, SO_RCVBUF,
                              &val, &len);
@@ -347,7 +348,7 @@ static bool check_any_addr (struct sockaddr * addr)
 static int tcp_listen (PAL_HANDLE * handle, char * uri, int options)
 {
     struct sockaddr buffer, * bind_addr = &buffer;
-    int bind_addrlen;
+    size_t bind_addrlen;
     int ret, fd = -1;
 
     if ((ret = socket_parse_uri(uri, &bind_addr, &bind_addrlen,
@@ -433,7 +434,7 @@ static int tcp_accept (PAL_HANDLE handle, PAL_HANDLE * client)
         return -PAL_ERROR_BADHANDLE;
 
     struct sockaddr * bind_addr = (struct sockaddr *) handle->sock.bind;
-    int bind_addrlen = addr_size(bind_addr);
+    size_t bind_addrlen = addr_size(bind_addr);
     struct sockaddr buffer;
     socklen_t addrlen = sizeof(struct sockaddr);
     int ret = 0;
@@ -452,7 +453,7 @@ static int tcp_accept (PAL_HANDLE handle, PAL_HANDLE * client)
         }
 
     struct sockaddr * dest_addr = &buffer;
-    int dest_addrlen = addrlen;
+    size_t dest_addrlen = addrlen;
 
     *client = socket_create_handle(pal_type_tcp, newfd, 0,
                                    bind_addr, bind_addrlen,
@@ -475,7 +476,7 @@ static int tcp_connect (PAL_HANDLE * handle, char * uri, int options)
 {
     struct sockaddr buffer[3];
     struct sockaddr * bind_addr = buffer, * dest_addr = buffer + 1;
-    int bind_addrlen, dest_addrlen;
+    size_t bind_addrlen, dest_addrlen;
     int ret, fd = -1;
 
     /* accepting two kind of different uri:
@@ -566,7 +567,7 @@ static int tcp_open (PAL_HANDLE *handle, const char * type, const char * uri,
         !WITHIN_MASK(create, PAL_CREATE_MASK))
         return -PAL_ERROR_INVAL;
 
-    int uri_len = strlen(uri) + 1;
+    size_t uri_len = strlen(uri) + 1;
 
     if (uri_len > PAL_SOCKADDR_SIZE)
         return -PAL_ERROR_TOOLONG;
@@ -584,7 +585,7 @@ static int tcp_open (PAL_HANDLE *handle, const char * type, const char * uri,
 }
 
 /* 'read' operation of tcp stream */
-static int64_t tcp_read (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+static int64_t tcp_read (PAL_HANDLE handle, uint64_t offset, size_t len,
                          void * buf)
 {
     if (offset)
@@ -620,7 +621,7 @@ static int64_t tcp_read (PAL_HANDLE handle, uint64_t offset, uint64_t len,
 }
 
 /* write' operation of tcp stream */
-static int64_t tcp_write (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+static int64_t tcp_write (PAL_HANDLE handle, uint64_t offset, size_t len,
                           const void * buf)
 {
     if (offset)
@@ -646,14 +647,14 @@ static int64_t tcp_write (PAL_HANDLE handle, uint64_t offset, uint64_t len,
 
     int64_t bytes = INLINE_SYSCALL(sendmsg, 3, handle->sock.fd, &hdr, MSG_NOSIGNAL);
 
-    if (IS_ERR(bytes))
-        bytes = unix_to_pal_error(ERRNO(bytes));
-
-    if (bytes == len)
+    if (!IS_ERR(bytes) && (size_t)bytes == len)
         HANDLE_HDR(handle)->flags |= WRITEABLE(0);
     else
         HANDLE_HDR(handle)->flags &= ~WRITEABLE(0);
 
+    if (IS_ERR(bytes))
+        bytes = unix_to_pal_error(ERRNO(bytes));
+
     return bytes;
 }
 
@@ -661,7 +662,7 @@ static int64_t tcp_write (PAL_HANDLE handle, uint64_t offset, uint64_t len,
 static int udp_bind (PAL_HANDLE * handle, char * uri, int options)
 {
     struct sockaddr buffer, * bind_addr = &buffer;
-    int bind_addrlen;
+    size_t bind_addrlen;
     int ret = 0, fd = -1;
 
     if ((ret = socket_parse_uri(uri, &bind_addr, &bind_addrlen,
@@ -726,7 +727,7 @@ static int udp_connect (PAL_HANDLE * handle, char * uri, int options)
 {
     struct sockaddr buffer[2];
     struct sockaddr * bind_addr = buffer, * dest_addr = buffer + 1;
-    int bind_addrlen, dest_addrlen;
+    size_t bind_addrlen, dest_addrlen;
     int ret, fd = -1;
 
     if ((ret = socket_parse_uri(uri, &bind_addr, &bind_addrlen,
@@ -797,7 +798,7 @@ static int udp_open (PAL_HANDLE *hdl, const char * type, const char * uri,
         return -PAL_ERROR_INVAL;
 
     char buf[PAL_SOCKADDR_SIZE];
-    int len = strlen(uri);
+    size_t len = strlen(uri);
 
     if (len >= PAL_SOCKADDR_SIZE)
         return -PAL_ERROR_TOOLONG;
@@ -813,7 +814,7 @@ static int udp_open (PAL_HANDLE *hdl, const char * type, const char * uri,
     return -PAL_ERROR_NOTSUPPORT;
 }
 
-static int64_t udp_receive (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+static int64_t udp_receive (PAL_HANDLE handle, uint64_t offset, size_t len,
                             void * buf)
 {
     if (offset)
@@ -845,7 +846,7 @@ static int64_t udp_receive (PAL_HANDLE handle, uint64_t offset, uint64_t len,
     return bytes;
 }
 
-static int64_t udp_receivebyaddr (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+static int64_t udp_receivebyaddr (PAL_HANDLE handle, uint64_t offset, size_t len,
                                   void * buf, char * addr, size_t addrlen)
 {
     if (offset)
@@ -889,7 +890,7 @@ static int64_t udp_receivebyaddr (PAL_HANDLE handle, uint64_t offset, uint64_t l
     return bytes;
 }
 
-static int64_t udp_send (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+static int64_t udp_send (PAL_HANDLE handle, uint64_t offset, size_t len,
                          const void * buf)
 {
     if (offset)
@@ -915,18 +916,18 @@ static int64_t udp_send (PAL_HANDLE handle, uint64_t offset, uint64_t len,
 
     int64_t bytes = INLINE_SYSCALL(sendmsg, 3, handle->sock.fd, &hdr, MSG_NOSIGNAL);
 
-    if (IS_ERR(bytes))
-        bytes = unix_to_pal_error(ERRNO(bytes));
-
-    if (bytes == len)
+    if (!IS_ERR(bytes) && (size_t)bytes == len)
         HANDLE_HDR(handle)->flags |= WRITEABLE(0);
     else
         HANDLE_HDR(handle)->flags &= ~WRITEABLE(0);
 
+    if (IS_ERR(bytes))
+        bytes = unix_to_pal_error(ERRNO(bytes));
+
     return bytes;
 }
 
-static int64_t udp_sendbyaddr (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+static int64_t udp_sendbyaddr (PAL_HANDLE handle, uint64_t offset, size_t len,
                                const void * buf, const char * addr, size_t addrlen)
 {
     if (offset)
@@ -948,7 +949,7 @@ static int64_t udp_sendbyaddr (PAL_HANDLE handle, uint64_t offset, uint64_t len,
     memcpy(addrbuf, addr, addrlen);
 
     struct sockaddr conn_addr;
-    int conn_addrlen;
+    size_t conn_addrlen;
 
     int ret = inet_parse_uri(&addrbuf, &conn_addr, &conn_addrlen);
     if (ret < 0)
@@ -968,14 +969,14 @@ static int64_t udp_sendbyaddr (PAL_HANDLE handle, uint64_t offset, uint64_t len,
 
     int64_t bytes = INLINE_SYSCALL(sendmsg, 3, handle->sock.fd, &hdr, MSG_NOSIGNAL);
 
-    if (IS_ERR(bytes))
-        bytes = unix_to_pal_error(ERRNO(bytes));
-
-    if (bytes == len)
+    if (!IS_ERR(bytes) && (size_t)bytes == len)
         HANDLE_HDR(handle)->flags |= WRITEABLE(0);
     else
         HANDLE_HDR(handle)->flags &= ~WRITEABLE(0);
 
+    if (IS_ERR(bytes))
+        bytes = unix_to_pal_error(ERRNO(bytes));
+
     return bytes;
 }
 
@@ -1193,11 +1194,11 @@ static int socket_attrsetbyhdl (PAL_HANDLE handle, PAL_STREAM_ATTR  * attr)
 
 static int socket_getname (PAL_HANDLE handle, char * buffer, size_t count)
 {
-    int old_count = count;
+    size_t old_count = count;
     int ret;
 
     const char * prefix = NULL;
-    int prefix_len = 0;
+    size_t prefix_len = 0;
     struct sockaddr * bind_addr = NULL, * dest_addr = NULL;
 
     switch (PAL_GET_TYPE(handle)) {
@@ -1402,7 +1403,8 @@ static int64_t mcast_send (PAL_HANDLE handle, uint64_t offset, uint64_t size,
                 return unix_to_pal_error(ERRNO(bytes));
         }
 
-    if (bytes == size)
+    assert(!IS_ERR(bytes));
+    if ((size_t)bytes == size)
         HANDLE_HDR(handle)->flags |= WRITEABLE(1);
     else
         HANDLE_HDR(handle)->flags &= ~WRITEABLE(1);
@@ -1410,7 +1412,7 @@ static int64_t mcast_send (PAL_HANDLE handle, uint64_t offset, uint64_t size,
     return bytes;
 }
 
-static int64_t mcast_receive (PAL_HANDLE handle, uint64_t offset, uint64_t size,
+static int64_t mcast_receive (PAL_HANDLE handle, uint64_t offset, size_t size,
                               void * buf)
 {
     if (offset)

+ 2 - 2
Pal/src/host/Linux/db_streams.c

@@ -396,7 +396,7 @@ int _DkReceiveHandle(PAL_HANDLE hdl, PAL_HANDLE * cargo)
 
     int ret = INLINE_SYSCALL(recvmsg, 3, ch, &hdr, 0);
 
-    if (IS_ERR(ret) || ret < sizeof(struct hdl_header)) {
+    if (IS_ERR(ret) || (size_t)ret < sizeof(struct hdl_header)) {
         if (!IS_ERR(ret))
             return -PAL_ERROR_TRYAGAIN;
 
@@ -406,7 +406,7 @@ int _DkReceiveHandle(PAL_HANDLE hdl, PAL_HANDLE * cargo)
 
     // initialize variables to get body
     void * buffer = __alloca(hdl_hdr.data_size);
-    int nfds = 0;
+    size_t nfds = 0;
 
     for (int i = 0 ; i < MAX_FDS ; i++)
         if (hdl_hdr.fds & (1U << i))

+ 1 - 1
Pal/src/host/Linux/db_threading.c

@@ -139,7 +139,7 @@ int _DkThreadDelayExecution (unsigned long * duration)
     struct timespec sleeptime;
     struct timespec remainingtime;
 
-    const long VERY_LONG_TIME_IN_US = 1000000L * 60 * 60 * 24 * 365 * 128;
+    const unsigned long VERY_LONG_TIME_IN_US = 1000000L * 60 * 60 * 24 * 365 * 128;
     if (*duration > VERY_LONG_TIME_IN_US) {
         /* avoid overflow with time_t */
         sleeptime.tv_sec  = VERY_LONG_TIME_IN_US / 1000000;

+ 1 - 1
Pal/src/host/Linux/sysdep-x86_64.h

@@ -160,7 +160,7 @@
 
 #undef INTERNAL_SYSCALL_ERROR_P
 #define INTERNAL_SYSCALL_ERROR_P(val) \
-  ((unsigned long) (val) >= -4095L)
+  ((unsigned long)(val) >= (unsigned long)-4095L)
 
 #undef INTERNAL_SYSCALL_ERRNO
 #define INTERNAL_SYSCALL_ERRNO(val) (-(val))

+ 9 - 6
Pal/src/security/Linux/manifest.c

@@ -104,16 +104,19 @@ next:
 int get_fs_paths (struct config_store * config, const char *** paths)
 {
     char * keys;
-    int nkeys;
+    size_t nkeys;
     ssize_t cfgsize;
+    int ret;
 
     cfgsize = get_config_entries_size(config, "fs.mount");
     if (cfgsize)
         return 0;
 
     keys = __alloca(cfgsize);
-    if ((nkeys = get_config_entries(config, "fs.mount", keys, cfgsize)) < 0)
+    if ((ret = get_config_entries(config, "fs.mount", keys, cfgsize)) < 0)
         nkeys = 0;
+    else
+        nkeys = (size_t)ret;
 
     *paths = malloc(sizeof(const char *) * (1 + nkeys));
     if (!(*paths))
@@ -128,13 +131,13 @@ int get_fs_paths (struct config_store * config, const char *** paths)
     char key[CONFIG_MAX], * k = keys, * n;
     char * tmp;
 
-    tmp = strcpy_static(key, "fs.mount.", CONFIG_MAX);
+    tmp = strcpy_static(key, "fs.mount.", (size_t)CONFIG_MAX);
 
-    for (int i = 0 ; i < nkeys ; i++) {
+    for (size_t i = 0 ; i < nkeys ; i++) {
         for (n = k ; *n ; n++);
-        int len = n - k;
+        size_t len = n - k;
         memcpy(tmp, k, len);
-        strcpy_static(tmp + len, ".uri", (key + CONFIG_MAX) - (tmp + len));
+        strcpy_static(tmp + len, ".uri", (size_t)((key + CONFIG_MAX) - (tmp + len)));
 
         const char * path = __get_path(config, key);
         if (path)