On Tue, Nov 08, 2022 at 04:14:13PM +0000, Tudor Cretu wrote:
Accessing elements in an empty va_list is undefined behaviour. Therefore, remove the variadicness from safe_semctl as it always calls semctl with the union semun argument included.
Adapt the SAFE_SEMCTL macro to handle the change by passing a zero-initialised union semun if it's omitted.
Signed-off-by: Tudor Cretu tudor.cretu@arm.com
include/tst_safe_sysv_ipc.h | 14 +++++++++++--- lib/tst_safe_sysv_ipc.c | 10 +--------- 2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/include/tst_safe_sysv_ipc.h b/include/tst_safe_sysv_ipc.h index 7804ce192..41af7aeaa 100644 --- a/include/tst_safe_sysv_ipc.h +++ b/include/tst_safe_sysv_ipc.h @@ -10,6 +10,8 @@ #include <sys/msg.h> #include <sys/shm.h> #include <sys/sem.h> +#include "lapi/sem.h" +#include "safe_vararg_macros.h" int safe_msgget(const char *file, const int lineno, key_t key, int msgflg); #define SAFE_MSGGET(key, msgflg) \ @@ -58,10 +60,16 @@ int safe_semget(const char *file, const int lineno, key_t key, int nsems, safe_semget(__FILE__, __LINE__, (key), (nsems), (semflg)) int safe_semctl(const char *file, const int lineno, int semid, int semnum,
int cmd, ...);
int cmd, union semun un);
New line ?
+#define _SAFE_SEMCTL_3(semid, semnum, cmd) \
- safe_semctl(__FILE__, __LINE__, (semid), (semnum), (cmd), (union semun){0})
+#define _SAFE_SEMCTL_4(semid, semnum, cmd, un) \
- safe_semctl(__FILE__, __LINE__, (semid), (semnum), (cmd), (un))
#define SAFE_SEMCTL(semid, semnum, cmd, ...) ({ \
- int tst_ret_ = safe_semctl(__FILE__, __LINE__, (semid), (semnum), \
(cmd), ##__VA_ARGS__); \
- int tst_ret_ = SAFE_WRAPPER_COND_HANDLER(, ##__VA_ARGS__, _SAFE_SEMCTL_4, \
_SAFE_SEMCTL_3) ((semid), (semnum), (cmd), ##__VA_ARGS__); \
Aligning arguments, similar to other patches in this series.
--- BR B.
(semid) = ((cmd) == IPC_RMID ? -1 : (semid)); \ tst_ret_; }) diff --git a/lib/tst_safe_sysv_ipc.c b/lib/tst_safe_sysv_ipc.c index 5eaa82539..f99f6db5e 100644 --- a/lib/tst_safe_sysv_ipc.c +++ b/lib/tst_safe_sysv_ipc.c @@ -228,17 +228,9 @@ int safe_semget(const char *file, const int lineno, key_t key, int nsems, } int safe_semctl(const char *file, const int lineno, int semid, int semnum,
int cmd, ...)
int cmd, union semun un)
{ int rval;
- va_list va;
- union semun un;
- va_start(va, cmd);
- un = va_arg(va, union semun);
- va_end(va);
rval = semctl(semid, semnum, cmd, un); -- 2.25.1
linux-morello-ltp mailing list -- linux-morello-ltp@op-lists.linaro.org To unsubscribe send an email to linux-morello-ltp-leave@op-lists.linaro.org