fix sendmmsg emulation return value for zero-length vector
[musl] / src / ipc / semctl.c
index 49927e2..673a9a8 100644 (file)
@@ -3,7 +3,7 @@
 #include "syscall.h"
 #include "ipc.h"
 
-struct semun {
+union semun {
        int val;
        struct semid_ds *buf;
        unsigned short *array;
@@ -11,11 +11,15 @@ struct semun {
 
 int semctl(int id, int num, int cmd, ...)
 {
-       struct semun arg;
+       union semun arg = {0};
        va_list ap;
-       va_start(ap, cmd);
-       arg = va_arg(ap, struct semun);
-       va_end(ap);
+       switch (cmd) {
+       case SETVAL: case GETALL: case SETALL: case IPC_STAT: case IPC_SET:
+       case IPC_INFO: case SEM_INFO: case SEM_STAT:
+               va_start(ap, cmd);
+               arg = va_arg(ap, union semun);
+               va_end(ap);
+       }
 #ifdef SYS_semctl
        return syscall(SYS_semctl, id, num, cmd | IPC_64, arg.buf);
 #else