From: Paul Eggert Date: Mon, 31 Jan 2022 16:42:07 +0000 (-0800) Subject: expr: lint cleanup, and introducing main_exit X-Git-Tag: v9.1~119 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=afa93e88044ef8d384b9b8b65b646add0fce905a;p=thirdparty%2Fcoreutils.git expr: lint cleanup, and introducing main_exit This introduces a new macro main_exit, which is useful for pacifying gcc -fsanitizer=lint and in some cases means we can remove some ‘IF_LINT’ and ‘ifdef lint’ code. * src/expr.c (main): Use main_exit, not return. (docolon): Omit an IF_LINT that GCC no longer needs. * src/system.h (main_exit): New macro. --- diff --git a/src/expr.c b/src/expr.c index b8f2162437..d0cffe3f73 100644 --- a/src/expr.c +++ b/src/expr.c @@ -357,7 +357,7 @@ main (int argc, char **argv) printv (v); - return null (v); + main_exit (null (v)); } /* Return a VALUE for I. */ @@ -585,7 +585,7 @@ trace (fxn) static VALUE * docolon (VALUE *sv, VALUE *pv) { - VALUE *v IF_LINT ( = NULL); + VALUE *v; char const *errmsg; struct re_pattern_buffer re_buffer; char fastmap[UCHAR_MAX + 1]; diff --git a/src/system.h b/src/system.h index 9f10579dc2..16fcc38e7b 100644 --- a/src/system.h +++ b/src/system.h @@ -465,13 +465,25 @@ enum # define PID_T_MAX TYPE_MAXIMUM (pid_t) #endif -/* Use this to suppress gcc's '...may be used before initialized' warnings. */ +/* Use this to suppress gcc warnings. */ #ifdef lint # define IF_LINT(Code) Code #else # define IF_LINT(Code) /* empty */ #endif +/* main_exit should be called only from the main function. It is + equivalent to 'exit'. When checking for lint it calls 'exit', to + pacify gcc -fsanitize=lint which would otherwise have false alarms + for pointers in the main function's activation record. Otherwise + it simply returns from 'main'; this used to be what gcc's static + checking preferred and may yet be again. */ +#ifdef lint +# define main_exit(status) exit (status) +#else +# define main_exit(status) return status +#endif + #ifdef __GNUC__ # define LIKELY(cond) __builtin_expect ((cond), 1) # define UNLIKELY(cond) __builtin_expect ((cond), 0)