Skip to content

[libc] fix -Wcast-function-type via union rather than reinterpret_cast #76875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions libc/src/signal/linux/signal_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ namespace LIBC_NAMESPACE {
// handler taking siginfo_t * argument, one can set sa_handler to sa_sigaction
// if SA_SIGINFO is set in sa_flags.
struct KernelSigaction {
using HandlerType = void(int);
using SiginfoHandlerType = void(int, siginfo_t *, void *);

LIBC_INLINE KernelSigaction &operator=(const struct sigaction &sa) {
sa_flags = sa.sa_flags;
sa_restorer = sa.sa_restorer;
sa_mask = sa.sa_mask;
if (sa_flags & SA_SIGINFO) {
sa_handler = reinterpret_cast<HandlerType *>(sa.sa_sigaction);
sa_sigaction = sa.sa_sigaction;
} else {
sa_handler = sa.sa_handler;
}
Expand All @@ -48,13 +45,16 @@ struct KernelSigaction {
sa.sa_mask = sa_mask;
sa.sa_restorer = sa_restorer;
if (sa_flags & SA_SIGINFO)
sa.sa_sigaction = reinterpret_cast<SiginfoHandlerType *>(sa_handler);
sa.sa_sigaction = sa_sigaction;
else
sa.sa_handler = sa_handler;
return sa;
}

HandlerType *sa_handler;
union {
void (*sa_handler)(int);
void (*sa_sigaction)(int, siginfo_t *, void *);
};
unsigned long sa_flags;
void (*sa_restorer)(void);
// Our public definition of sigset_t matches that of the kernel's definition.
Expand Down