diff mbox series

[uclibc-ng-devel,1/2] utils/getconf: Fix compilation error

Message ID 20200909071804.35932-2-damien.lemoal@wdc.com
State Accepted
Headers show
Series Fix compilation errors | expand

Commit Message

Damien Le Moal Sept. 9, 2020, 7:18 a.m. UTC
In the main() function, all cases of the "switch (specs[i].num)"
switch-case are all conditionally defined. Depending on the target
environementi, none of them may endup being defined, resulting in the
code block before the no-op default case to generate a
"warning: statement will never be executed" compilation error.

Avoid this by conditionally defining this code block with the macro
DO_GETCONF_NAME which is itself defined if any of the switc cases is
defined too.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 utils/getconf.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/utils/getconf.c b/utils/getconf.c
index 3dd3d75d9..b8d00f90f 100644
--- a/utils/getconf.c
+++ b/utils/getconf.c
@@ -1154,7 +1154,6 @@  environment SPEC.\n\n");
 
   const char *spec = NULL;
   char buf[sizeof "POSIX_V6_LPBIG_OFFBIG"];
-  char *argv0 = argv[0];
   if (argc > 1 && strncmp (argv[1], "-v", 2) == 0)
     {
       if (argv[1][2] == '\0')
@@ -1199,42 +1198,56 @@  environment SPEC.\n\n");
 
       switch (specs[i].num)
 	{
+#undef DO_GETCONF_NAME
 #if !defined(_XBS5_ILP32_OFF32) && defined(_SC_XBS5_ILP32_OFF32)
+#define DO_GETCONF_NAME
 	case _SC_XBS5_ILP32_OFF32:
 #endif
 #if !defined(_XBS5_ILP32_OFFBIG) && defined(_SC_XBS5_ILP32_OFFBIG)
+#define DO_GETCONF_NAME
 	case _SC_XBS5_ILP32_OFFBIG:
 #endif
 #if !defined(_XBS5_LP64_OFF64) && defined(_SC_XBS5_LP64_OFF64)
+#define DO_GETCONF_NAME
 	case _SC_XBS5_LP64_OFF64:
 #endif
 #if !defined(_XBS5_LPBIG_OFFBIG) && defined(_SC_XBS5_LPBIG_OFFBIG)
+#define DO_GETCONF_NAME
 	case _SC_XBS5_LPBIG_OFFBIG:
 #endif
 #if !defined(_POSIX_V6_ILP32_OFF32) && defined(_SC_V6_ILP32_OFF32)
+#define DO_GETCONF_NAME
 	case _SC_V6_ILP32_OFF32:
 #endif
 #if !defined(_POSIX_V6_ILP32_OFFBIG) && defined(_SC_V6_ILP32_OFFBIG)
+#define DO_GETCONF_NAME
 	case _SC_V6_ILP32_OFFBIG:
 #endif
 #if !defined(_POSIX_V6_LP64_OFF64) && defined(_SC_V6_LP64_OFF64)
+#define DO_GETCONF_NAME
 	case _SC_V6_LP64_OFF64:
 #endif
 #if !defined(_POSIX_V6_LPBIG_OFFBIG) && defined(_SC_V6_LPBIG_OFFBIG)
+#define DO_GETCONF_NAME
 	case _SC_V6_LPBIG_OFFBIG:
 #endif
 #if !defined(_POSIX_V7_ILP32_OFF32) && defined(_SC_V7_ILP32_OFF32)
+#define DO_GETCONF_NAME
 	case _SC_V7_ILP32_OFF32:
 #endif
 #if !defined(_POSIX_V7_ILP32_OFFBIG) && defined(_SC_V7_ILP32_OFFBIG)
+#define DO_GETCONF_NAME
 	case _SC_V7_ILP32_OFFBIG:
 #endif
 #if !defined(_POSIX_V7_LP64_OFF64) && defined(_SC_V7_LP64_OFF64)
+#define DO_GETCONF_NAME
 	case _SC_V7_LP64_OFF64:
 #endif
 #if !defined(_POSIX_V7_LPBIG_OFFBIG) && defined(_SC_V7_LPBIG_OFFBIG)
+#define DO_GETCONF_NAME
 	case _SC_V7_LPBIG_OFFBIG:
 #endif
+#ifdef DO_GETCONF_NAME
 	    {
 	      const char *args[argc + 3];
 	      size_t spec_len = strlen (spec);
@@ -1242,14 +1255,15 @@  environment SPEC.\n\n");
 	      memcpy (mempcpy (mempcpy (getconf_name, getconf_dir,
 					getconf_dirlen),
 			       "/", 1), spec, spec_len + 1);
-	      args[0] = argv0;
+	      args[0] = argv[0];
 	      args[1] = "-v";
 	      args[2] = spec;
 	      memcpy (&args[3], &argv[1], argc * sizeof (argv[1]));
 	      execv (getconf_name, (char * const *) args);
 	      error (4, errno, _("Couldn't execute %s"), getconf_name);
 	    }
-	  default:
+#endif
+	default:
 	    break;
 	}
     }