Browse Source

[LibOS,Pal] Miscellaneous small fixes for readability

- Pal/src/host/Linux/db_main.c: calloc instead of malloc + memset
- LibOS/shim/test/regression/large_dir_read.c: snprintf instead of sprintf
- LibOS/shim/src/ipc/shim_ipc_sysv.c: sizeof based on object instead of type
- LibOS/shim/src/sys/shim_socket.c: explicit struct init instead of memcpy
Isaku Yamahata 4 years ago
parent
commit
8096b03d63

+ 1 - 1
LibOS/shim/src/ipc/shim_ipc_sysv.c

@@ -616,7 +616,7 @@ int ipc_sysv_semctl_callback(IPC_CALLBACK_ARGS) {
 
         case SETVAL: {
             ret = -EINVAL;
-            if (msgin->valsize != sizeof(unsigned short))
+            if (msgin->valsize != sizeof(sem->sems[msgin->semnum].val))
                 break;
             if (msgin->semnum >= sem->nsems)
                 break;

+ 5 - 5
LibOS/shim/src/sys/shim_socket.c

@@ -361,11 +361,11 @@ static void inet_save_addr(int domain, struct addr_inet* addr, const struct sock
         if (saddr->sa_family == AF_INET) {
             const struct sockaddr_in* in           = (const struct sockaddr_in*)saddr;
             addr->port                             = __ntohs(in->sin_port);
-            uint32_t s_addr[4] = {
-                /* in->sin_addr.s_addr is already network byte order */
-                __htonl(0), __htonl(0), __htonl(0x0000ffff), in->sin_addr.s_addr
-            };
-            memcpy(&addr->addr.v6.s6_addr, s_addr, sizeof(s_addr));
+            addr->addr.v6.s6_addr32[0] = __htonl(0);
+            addr->addr.v6.s6_addr32[1] = __htonl(0);
+            addr->addr.v6.s6_addr32[2] = __htonl(0x0000ffff);
+            /* in->sin_addr.s_addr is already network byte order */
+            addr->addr.v6.s6_addr32[3] = in->sin_addr.s_addr;
         } else {
             const struct sockaddr_in6* in6 = (const struct sockaddr_in6*)saddr;
             addr->port                     = __ntohs(in6->sin6_port);

+ 2 - 2
LibOS/shim/test/regression/large_dir_read.c

@@ -18,7 +18,7 @@ static int is_dot_or_dotdot(const char* name) {
 
 int main(int argc, char* argv[]) {
     int fd = 0, ret = 1;
-    char name[21]     = {0};
+    char name[21]       = {0};
     DIR* dir            = NULL;
     struct dirent* dent = NULL;
     unsigned long i     = 0;
@@ -53,7 +53,7 @@ int main(int argc, char* argv[]) {
     }
 
     for (i = 0; i < FILES_NO; i++) {
-        sprintf(name, "%010lu", i);
+        snprintf(name, sizeof(name), "%010lu", i);
         fd = open(name, O_CREAT | O_EXCL | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO);
         if (fd < 0) {
             fprintf(stderr, "error: cannot create file %lu: %s\n", i, strerror(errno));

+ 1 - 2
Pal/src/host/Linux/db_main.c

@@ -238,10 +238,9 @@ void pal_linux_main (void * args)
     SET_HANDLE_TYPE(first_thread, thread);
     first_thread->thread.tid = INLINE_SYSCALL(gettid, 0);
 
-    void * alt_stack = malloc(ALT_STACK_SIZE);
+    void * alt_stack = calloc(1, ALT_STACK_SIZE);
     if (!alt_stack)
         INIT_FAIL(PAL_ERROR_NOMEM, "Out of memory");
-    memset(alt_stack, 0, ALT_STACK_SIZE);
     first_thread->thread.stack = alt_stack;
 
     // Initialize TCB at the top of the alternative stack.