2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 09:57:41 +00:00

Use C23 [[__fallthrough__]] and [[__noreturn__]] attributes if supported.

If the C23 attributes are not supported, use gcc-style attributes
where possible.
This commit is contained in:
Todd C. Miller 2022-11-29 16:28:27 -07:00
parent cfdcd96b63
commit 16ae61dcd7
3 changed files with 50 additions and 14 deletions

View File

@ -1476,11 +1476,18 @@
#endif
/* For functions that call exit() directly. */
#ifdef __has_c_attribute
# if __has_c_attribute(__noreturn__)
# define sudo_noreturn [[__noreturn__]]
# endif
#endif
#ifndef sudo_noreturn
# if __GNUC_PREREQ__(2, 5)
# define sudo_noreturn __attribute__((__noreturn__))
# else
# define sudo_noreturn
# endif
#endif
/* For malloc-like functions that return uninitialized or zeroed memory. */
#if __GNUC_PREREQ__(2, 96)
@ -1507,6 +1514,20 @@
# define sudo_attr_fmt_arg(_f)
#endif
/* C23 defines a fallthrough attribute, gcc 7.0 and clang 10 have their own. */
#ifdef __has_c_attribute
# if __has_c_attribute(__fallthrough__)
# define FALLTHROUGH [[__fallthrough__]]
# endif
#endif
#ifndef FALLTHROUGH
# if defined(HAVE_FALLTHROUGH_ATTRIBUTE)
# define FALLTHROUGH __attribute__((__fallthrough__))
# else
# define FALLTHROUGH do { } while (0)
# endif
#endif
/* Symbol visibility controls. */
#ifdef HAVE_DSO_VISIBILITY
# if defined(__GNUC__)

View File

@ -5571,11 +5571,18 @@ AH_BOTTOM([#ifndef __GNUC_PREREQ__
#endif
/* For functions that call exit() directly. */
#ifdef __has_c_attribute
# if __has_c_attribute(__noreturn__)
# define sudo_noreturn [[__noreturn__]]
# endif
#endif
#ifndef sudo_noreturn
# if __GNUC_PREREQ__(2, 5)
# define sudo_noreturn __attribute__((__noreturn__))
# else
# define sudo_noreturn
# endif
#endif
/* For malloc-like functions that return uninitialized or zeroed memory. */
#if __GNUC_PREREQ__(2, 96)
@ -5602,6 +5609,20 @@ AH_BOTTOM([#ifndef __GNUC_PREREQ__
# define sudo_attr_fmt_arg(_f)
#endif
/* C23 defines a fallthrough attribute, gcc 7.0 and clang 10 have their own. */
#ifdef __has_c_attribute
# if __has_c_attribute(__fallthrough__)
# define FALLTHROUGH [[__fallthrough__]]
# endif
#endif
#ifndef FALLTHROUGH
# if defined(HAVE_FALLTHROUGH_ATTRIBUTE)
# define FALLTHROUGH __attribute__((__fallthrough__))
# else
# define FALLTHROUGH do { } while (0)
# endif
#endif
/* Symbol visibility controls. */
#ifdef HAVE_DSO_VISIBILITY
# if defined(__GNUC__)

View File

@ -37,12 +37,6 @@
* Macros and functions that may be missing on some operating systems.
*/
#ifdef HAVE_FALLTHROUGH_ATTRIBUTE
# define FALLTHROUGH __attribute__((__fallthrough__))
#else
# define FALLTHROUGH do { } while (0)
#endif
/*
* Given the pointer x to the member m of the struct s, return
* a pointer to the containing structure.