From 271d4d251556ae2f9fd7b32c5801b06f651a645d Mon Sep 17 00:00:00 2001 From: zijunzhao Date: Thu, 20 Apr 2023 20:46:01 +0000 Subject: [PATCH] Nullability check for sem module. Bugs: b/245972273 Test: adb shell Change-Id: Ie29aa34c449300c53591557c99b6ec08ebe3efcf --- libc/include/sys/sem.h | 12 ++++++------ tests/sys_sem_test.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/libc/include/sys/sem.h b/libc/include/sys/sem.h index cd6224221..f4256e220 100644 --- a/libc/include/sys/sem.h +++ b/libc/include/sys/sem.h @@ -45,18 +45,18 @@ __BEGIN_DECLS union semun { int val; - struct semid_ds* buf; - unsigned short* array; - struct seminfo* __buf; - void* __pad; + struct semid_ds* _Nullable buf; + unsigned short* _Nullable array; + struct seminfo* _Nullable __buf; + void* _Nullable __pad; }; int semctl(int __sem_id, int __sem_num, int __cmd, ...) __INTRODUCED_IN(26); int semget(key_t __key, int __sem_count, int __flags) __INTRODUCED_IN(26); -int semop(int __sem_id, struct sembuf* __ops, size_t __op_count) __INTRODUCED_IN(26); +int semop(int __sem_id, struct sembuf* _Nonnull __ops, size_t __op_count) __INTRODUCED_IN(26); #if defined(__USE_GNU) -int semtimedop(int __sem_id, struct sembuf* __ops, size_t __op_count, const struct timespec* __timeout) __INTRODUCED_IN(26); +int semtimedop(int __sem_id, struct sembuf* _Nonnull __ops, size_t __op_count, const struct timespec* _Nullable __timeout) __INTRODUCED_IN(26); #endif __END_DECLS diff --git a/tests/sys_sem_test.cpp b/tests/sys_sem_test.cpp index b98926b4b..4bac92fc8 100644 --- a/tests/sys_sem_test.cpp +++ b/tests/sys_sem_test.cpp @@ -87,15 +87,21 @@ TEST(sys_sem, semctl_failure) { } TEST(sys_sem, semop_failure) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wnonnull" errno = 0; ASSERT_EQ(-1, semop(-1, nullptr, 0)); ASSERT_TRUE(errno == EINVAL || errno == ENOSYS); +#pragma clang diagnostic pop } TEST(sys_sem, semtimedop_failure) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wnonnull" errno = 0; ASSERT_EQ(-1, semtimedop(-1, nullptr, 0, nullptr)); ASSERT_TRUE(errno == EINVAL || errno == ENOSYS); +#pragma clang diagnostic pop } TEST(sys_sem, union_semun) {