]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
env: remove asserts
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 26 Mar 2021 21:06:26 +0000 (14:06 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 26 Mar 2021 22:17:28 +0000 (15:17 -0700)
The assertions didn’t help catch the most recent bug which
was in their area, and kind of get in the way.
* src/env.c: Do not include <assert.h>, and remove all assertions.
These seem to have been put in to pacify gcov, but surely there’s
a better way.
(escape_char): Pacify GCC with 'assume' instead.

src/env.c

index e13a312cdd6f404b76e084545a2ded62e7669a0f..262c02852af9a600ecd2657b761acbbae476b122 100644 (file)
--- a/src/env.c
+++ b/src/env.c
@@ -23,7 +23,6 @@
 #include <c-ctype.h>
 #include <signal.h>
 
-#include <assert.h>
 #include "system.h"
 #include "die.h"
 #include "error.h"
@@ -210,7 +209,7 @@ escape_char (const char c)
     case 'r': return '\r';
     case 't': return '\t';
     case 'v': return '\v';
-    default:  assert (0);                           /* LCOV_EXCL_LINE */
+    default: assume (false);
     }
 }
 
@@ -221,7 +220,6 @@ escape_char (const char c)
 static const char* _GL_ATTRIBUTE_PURE
 scan_varname (const char* str)
 {
-  assert (str && *str == '$');                      /* LCOV_EXCL_LINE */
   if ( *(str+1) == '{' && (c_isalpha (*(str+2)) || *(str+2) == '_'))
     {
       const char* end = str+3;
@@ -280,8 +278,6 @@ validate_split_str (const char* str, size_t* /*out*/ bufsize,
   size_t buflen;
   int cnt = 1;
 
-  assert (str && str[0] && !c_isspace (str[0]));     /* LCOV_EXCL_LINE */
-
   dq = sq = sp = false;
   buflen = strlen (str)+1;
 
@@ -303,12 +299,10 @@ validate_split_str (const char* str, size_t* /*out*/ bufsize,
       switch (*str)
         {
         case '\'':
-          assert (!(sq && dq));                           /* LCOV_EXCL_LINE */
           sq = !sq && !dq;
           break;
 
         case '"':
-          assert (!(sq && dq));                           /* LCOV_EXCL_LINE */
           dq = !sq && !dq;
           break;
 
@@ -395,8 +389,6 @@ build_argv (const char* str, int extra_argc)
       }                                         \
   } while (0)
 
-  assert (str && str[0] && !c_isspace (str[0]));          /* LCOV_EXCL_LINE */
-
   validate_split_str (str, &buflen, &newargc);
 
   /* allocate buffer. +6 for the "DUMMY\0" executable name, +1 for NUL. */
@@ -486,7 +478,6 @@ build_argv (const char* str, int extra_argc)
           /* Store the ${VARNAME} value. */
           {
             char *n = extract_varname (str);
-            assert (n);  /* ${VARNAME} already validated. */
             char *v = getenv (n);
             if (v)
               {