]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
expr: lint cleanup, and introducing main_exit
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Jan 2022 16:42:07 +0000 (08:42 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Jan 2022 20:07:38 +0000 (12:07 -0800)
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.

src/expr.c
src/system.h

index b8f216243779bd02c830a34e40938af216e33310..d0cffe3f738de3d6ab5211a70cd2c5b7495487ff 100644 (file)
@@ -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];
index 9f10579dc2d9872ba6b32639f5da4734367ea49f..16fcc38e7b454ea5ee770171a93886a5185a4a66 100644 (file)
@@ -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)