From 616c7dca2ba7e11436f1c49f366f1fae7071d21e Mon Sep 17 00:00:00 2001 From: AtariDreams <83477269+AtariDreams@users.noreply.github.com> Date: Mon, 4 Dec 2023 11:29:29 -0500 Subject: [PATCH] Replace __LA_DEAD with __LA_NORETURN (#2000) Also add the MSC_VER version of the macro. --- cat/bsdcat.c | 8 ++++++-- cat/bsdcat_platform.h | 12 +++++++----- cpio/cpio.c | 16 ++++++++-------- cpio/cpio_platform.h | 6 ++++-- libarchive/archive_check_magic.c | 2 +- libarchive/archive_private.h | 10 ++++++---- libarchive_fe/err.h | 10 ++++++---- libarchive_fe/passphrase.c | 2 +- tar/bsdtar.c | 10 ++++------ tar/bsdtar.h | 2 +- tar/bsdtar_platform.h | 12 +++++++----- tar/subst.c | 1 + test_utils/test_main.c | 1 - unzip/bsdunzip.c | 4 +--- unzip/bsdunzip_platform.h | 12 +++++++----- 15 files changed, 60 insertions(+), 48 deletions(-) diff --git a/cat/bsdcat.c b/cat/bsdcat.c index 69fa06fdf..42a93aa56 100644 --- a/cat/bsdcat.c +++ b/cat/bsdcat.c @@ -129,12 +129,16 @@ main(int argc, char **argv) switch (c) { case 'h': usage(stdout, 0); - break; + /* NOTREACHED */ + /* Fallthrough */ case OPTION_VERSION: version(); - break; + /* NOTREACHED */ + /* Fallthrough */ default: usage(stderr, 1); + /* Fallthrough */ + /* NOTREACHED */ } } diff --git a/cat/bsdcat_platform.h b/cat/bsdcat_platform.h index 5b58cd7ee..78a6113e6 100644 --- a/cat/bsdcat_platform.h +++ b/cat/bsdcat_platform.h @@ -52,12 +52,14 @@ /* How to mark functions that don't return. */ /* This facilitates use of some newer static code analysis tools. */ -#undef __LA_DEAD +#undef __LA_NORETURN #if defined(__GNUC__) && (__GNUC__ > 2 || \ - (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) -#define __LA_DEAD __attribute__((__noreturn__)) -#else -#define __LA_DEAD + (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) +#define __LA_NORETURN __attribute__((__noreturn__)) +#elif defined(_MSC_VER) +#define __LA_NORETURN __declspec(noreturn) +#else +#define __LA_NORETURN #endif #endif /* !BSDCAT_PLATFORM_H_INCLUDED */ diff --git a/cpio/cpio.c b/cpio/cpio.c index cf68029ad..d510c4811 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -107,22 +107,22 @@ static int entry_to_archive(struct cpio *, struct archive_entry *); static int file_to_archive(struct cpio *, const char *); static void free_cache(struct name_cache *cache); static void list_item_verbose(struct cpio *, struct archive_entry *); -static void long_help(void) __LA_DEAD; +static void long_help(void) __LA_NORETURN; static const char *lookup_gname(struct cpio *, gid_t gid); static int lookup_gname_helper(struct cpio *, const char **name, id_t gid); static const char *lookup_uname(struct cpio *, uid_t uid); static int lookup_uname_helper(struct cpio *, const char **name, id_t uid); -static void mode_in(struct cpio *) __LA_DEAD; -static void mode_list(struct cpio *) __LA_DEAD; +static void mode_in(struct cpio *) __LA_NORETURN; +static void mode_list(struct cpio *) __LA_NORETURN; static void mode_out(struct cpio *); static void mode_pass(struct cpio *, const char *); static const char *remove_leading_slash(const char *); static int restore_time(struct cpio *, struct archive_entry *, const char *, int fd); -static void usage(void) __LA_DEAD; -static void version(void) __LA_DEAD; +static void usage(void) __LA_NORETURN; +static void version(void) __LA_NORETURN; static const char * passphrase_callback(struct archive *, void *); static void passphrase_free(char *); @@ -250,7 +250,7 @@ main(int argc, char *argv[]) break; case 'h': long_help(); - break; + /* NOTREACHED */ case 'I': /* NetBSD/OpenBSD */ cpio->filename = cpio->argument; break; @@ -357,7 +357,7 @@ main(int argc, char *argv[]) break; case OPTION_VERSION: /* GNU convention */ version(); - break; + /* NOTREACHED */ #if 0 /* * cpio_getopt() handles -W specially, so it's not @@ -426,7 +426,7 @@ main(int argc, char *argv[]) mode_list(cpio); else mode_in(cpio); - break; + /* NOTREACHED */ case 'p': if (*cpio->argv == NULL || **cpio->argv == '\0') lafe_errc(1, 0, diff --git a/cpio/cpio_platform.h b/cpio/cpio_platform.h index 9cb577b82..263404b40 100644 --- a/cpio/cpio_platform.h +++ b/cpio/cpio_platform.h @@ -57,9 +57,11 @@ /* How to mark functions that don't return. */ #if defined(__GNUC__) && (__GNUC__ > 2 || \ (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) -#define __LA_DEAD __attribute__((__noreturn__)) +#define __LA_NORETURN __attribute__((__noreturn__)) +#elif defined(_MSC_VER) +#define __LA_NORETURN __declspec(noreturn) #else -#define __LA_DEAD +#define __LA_NORETURN #endif #endif /* !CPIO_PLATFORM_H_INCLUDED */ diff --git a/libarchive/archive_check_magic.c b/libarchive/archive_check_magic.c index f31f6a501..24dc6c505 100644 --- a/libarchive/archive_check_magic.c +++ b/libarchive/archive_check_magic.c @@ -61,7 +61,7 @@ errmsg(const char *m) } } -static __LA_DEAD void +static __LA_NORETURN void diediedie(void) { #if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) diff --git a/libarchive/archive_private.h b/libarchive/archive_private.h index b0096c035..41f40e876 100644 --- a/libarchive/archive_private.h +++ b/libarchive/archive_private.h @@ -38,10 +38,12 @@ #include "archive_string.h" #if defined(__GNUC__) && (__GNUC__ > 2 || \ - (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) -#define __LA_DEAD __attribute__((__noreturn__)) + (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) +#define __LA_NORETURN __attribute__((__noreturn__)) +#elif defined(_MSC_VER) +#define __LA_NORETURN __declspec(noreturn) #else -#define __LA_DEAD +#define __LA_NORETURN #endif #if defined(__GNUC__) && (__GNUC__ > 2 || \ @@ -151,7 +153,7 @@ int __archive_check_magic(struct archive *, unsigned int magic, return ARCHIVE_FATAL; \ } while (0) -void __archive_errx(int retvalue, const char *msg) __LA_DEAD; +void __archive_errx(int retvalue, const char *msg) __LA_NORETURN; void __archive_ensure_cloexec_flag(int fd); int __archive_mktemp(const char *tmpdir); diff --git a/libarchive_fe/err.h b/libarchive_fe/err.h index c663103b0..e1af236b6 100644 --- a/libarchive_fe/err.h +++ b/libarchive_fe/err.h @@ -27,10 +27,12 @@ #define LAFE_ERR_H #if defined(__GNUC__) && (__GNUC__ > 2 || \ - (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) -#define __LA_DEAD __attribute__((__noreturn__)) + (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) +#define __LA_NORETURN __attribute__((__noreturn__)) +#elif defined(_MSC_VER) +#define __LA_NORETURN __declspec(noreturn) #else -#define __LA_DEAD +#define __LA_NORETURN #endif #if defined(__GNUC__) && (__GNUC__ > 2 || \ @@ -46,7 +48,7 @@ #endif void lafe_warnc(int code, const char *fmt, ...) __LA_PRINTFLIKE(2, 3); -void lafe_errc(int eval, int code, const char *fmt, ...) __LA_DEAD +void lafe_errc(int eval, int code, const char *fmt, ...) __LA_NORETURN __LA_PRINTFLIKE(3, 4); const char * lafe_getprogname(void); diff --git a/libarchive_fe/passphrase.c b/libarchive_fe/passphrase.c index b6dff4867..9d95d5270 100644 --- a/libarchive_fe/passphrase.c +++ b/libarchive_fe/passphrase.c @@ -329,7 +329,7 @@ lafe_readpassphrase(const char *prompt, char *buf, size_t bufsiz) break; default: lafe_errc(1, errno, "Couldn't read passphrase"); - break; + /* NOTREACHED */ } } return (p); diff --git a/tar/bsdtar.c b/tar/bsdtar.c index 60cb6bad9..87544dc65 100644 --- a/tar/bsdtar.c +++ b/tar/bsdtar.c @@ -113,11 +113,11 @@ need_report(void) } #endif -static void long_help(void) __LA_DEAD; +static void long_help(void) __LA_NORETURN; static void only_mode(struct bsdtar *, const char *opt, const char *valid); static void set_mode(struct bsdtar *, char opt); -static void version(void) __LA_DEAD; +static void version(void) __LA_NORETURN; /* A basic set of security flags to request from libarchive. */ #define SECURITY \ @@ -399,8 +399,7 @@ main(int argc, char **argv) break; case OPTION_HELP: /* GNU tar, others */ long_help(); - exit(0); - break; + /* NOTREACHED*/ case OPTION_HFS_COMPRESSION: /* Mac OS X v10.6 or later */ bsdtar->extract_flags |= ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED; @@ -737,7 +736,7 @@ main(int argc, char **argv) break; case OPTION_VERSION: /* GNU convention */ version(); - break; + /* NOTREACHED */ #if 0 /* * The -W longopt feature is handled inside of @@ -803,7 +802,6 @@ main(int argc, char **argv) /* If no "real" mode was specified, treat -h as --help. */ if ((bsdtar->mode == '\0') && possible_help_request) { long_help(); - exit(0); } /* Otherwise, a mode is required. */ diff --git a/tar/bsdtar.h b/tar/bsdtar.h index 4f9378f82..ea6e131f1 100644 --- a/tar/bsdtar.h +++ b/tar/bsdtar.h @@ -206,7 +206,7 @@ void tar_mode_r(struct bsdtar *bsdtar); void tar_mode_t(struct bsdtar *bsdtar); void tar_mode_u(struct bsdtar *bsdtar); void tar_mode_x(struct bsdtar *bsdtar); -void usage(void) __LA_DEAD; +void usage(void) __LA_NORETURN; int yes(const char *fmt, ...) __LA_PRINTF(1, 2); #if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) diff --git a/tar/bsdtar_platform.h b/tar/bsdtar_platform.h index 04cb752e9..a4f37d95e 100644 --- a/tar/bsdtar_platform.h +++ b/tar/bsdtar_platform.h @@ -109,12 +109,14 @@ /* How to mark functions that don't return. */ /* This facilitates use of some newer static code analysis tools. */ -#undef __LA_DEAD +#undef __LA_NORETURN #if defined(__GNUC__) && (__GNUC__ > 2 || \ - (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) -#define __LA_DEAD __attribute__((__noreturn__)) -#else -#define __LA_DEAD + (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) +#define __LA_NORETURN __attribute__((__noreturn__)) +#elif defined(_MSC_VER) +#define __LA_NORETURN __declspec(noreturn) +#else +#define __LA_NORETURN #endif #endif /* !BSDTAR_PLATFORM_H_INCLUDED */ diff --git a/tar/subst.c b/tar/subst.c index 3322245c1..6152f8672 100644 --- a/tar/subst.c +++ b/tar/subst.c @@ -158,6 +158,7 @@ add_substitution(struct bsdtar *bsdtar, const char *rule_text) break; default: lafe_errc(1, 0, "Invalid replacement flag %c", *end_pattern); + /* NOTREACHED */ } } } diff --git a/test_utils/test_main.c b/test_utils/test_main.c index ffc33e4e0..16b677a94 100644 --- a/test_utils/test_main.c +++ b/test_utils/test_main.c @@ -4175,7 +4175,6 @@ main(int argc, char **argv) free(refdir_alloc); free(testprogdir); usage(progname); - return (1); } for (i = 0; i < test_num; i++) { tests_run++; diff --git a/unzip/bsdunzip.c b/unzip/bsdunzip.c index 6c6e50ae2..a47196519 100644 --- a/unzip/bsdunzip.c +++ b/unzip/bsdunzip.c @@ -1230,10 +1230,8 @@ main(int argc, char *argv[]) */ nopts = getopts(argc, argv); - if (version_opt == 1) { + if (version_opt == 1) version(); - exit(EXIT_SUCCESS); - } /* * When more of the zipinfo mode options are implemented, this diff --git a/unzip/bsdunzip_platform.h b/unzip/bsdunzip_platform.h index 5bfc71a68..d4fcbb1ae 100644 --- a/unzip/bsdunzip_platform.h +++ b/unzip/bsdunzip_platform.h @@ -52,12 +52,14 @@ /* How to mark functions that don't return. */ /* This facilitates use of some newer static code analysis tools. */ -#undef __LA_DEAD +#undef __LA_NORETURN #if defined(__GNUC__) && (__GNUC__ > 2 || \ - (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) -#define __LA_DEAD __attribute__((__noreturn__)) -#else -#define __LA_DEAD + (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) +#define __LA_NORETURN __attribute__((__noreturn__)) +#elif defined(_MSC_VER) +#define __LA_NORETURN __declspec(noreturn) +#else +#define __LA_NORETURN #endif #endif /* !BSDUNZIP_PLATFORM_H_INCLUDED */ -- 2.47.2