util: fix compile warnings
authorAnsis Atteka <aatteka@nicira.com>
Tue, 8 Jul 2014 04:11:53 +0000 (04:11 +0000)
committerJoe Stringer <joestringer@nicira.com>
Mon, 7 Jul 2014 22:21:54 +0000 (10:21 +1200)
This patch fixes two compile warnings introduced by commit
64b73291 ("util: create a copy of program_name"):
1. ../lib/util.c:457:5: error: passing argument 1 of 'free'
   discards 'const' qualifier from pointer target type; And
2. ../lib/util.c:463:5: error: ISO C90 forbids mixed declarations
   and code [-Werror=declaration-after-statement] (affected only
   branch-2.3 that is C90 compliant and not the master)

Reported-By: Joe Stringer <jstringer@nicira.com>
Reported-By: Lorand Jakab <lojakab@cisco.com>
Signed-Off-By: Ansis Atteka <aatteka@nicira.com>
Acked-by: Joe Stringer <joestringer@nicira.com>
lib/util.c
lib/util.h

index 7f2b284..4493ee0 100644 (file)
@@ -43,7 +43,7 @@ VLOG_DEFINE_THIS_MODULE(util);
 COVERAGE_DEFINE(util_xalloc);
 
 /* argv[0] without directory names. */
-const char *program_name;
+char *program_name;
 
 /* Name for the currently running thread or process, for log messages, process
  * listings, and debuggers. */
@@ -455,10 +455,8 @@ void
 set_program_name__(const char *argv0, const char *version, const char *date,
                    const char *time)
 {
-    free(CONST_CAST(char *, program_name));
-
-#ifdef _WIN32
     char *basename;
+#ifdef _WIN32
     size_t max_len = strlen(argv0) + 1;
 
     SetErrorMode(GetErrorMode() | SEM_NOGPFAULTERRORBOX);
@@ -466,14 +464,14 @@ set_program_name__(const char *argv0, const char *version, const char *date,
 
     basename = xmalloc(max_len);
     _splitpath_s(argv0, NULL, 0, NULL, 0, basename, max_len, NULL, 0);
-    assert_single_threaded();
-    program_name = basename;
 #else
     const char *slash = strrchr(argv0, '/');
-    assert_single_threaded();
-    program_name = xstrdup(slash ? slash + 1 : argv0);
+    basename = xstrdup(slash ? slash + 1 : argv0);
 #endif
 
+    assert_single_threaded();
+    free(program_name);
+    program_name = basename;
     free(program_version);
 
     if (!strcmp(version, VERSION)) {
index b626c0b..dc34ee5 100644 (file)
@@ -86,7 +86,7 @@ void ovs_assert_failure(const char *, const char *, const char *) NO_RETURN;
     ((void) sizeof ((int) ((POINTER) == (TYPE) (POINTER))),     \
      (TYPE) (POINTER))
 
-extern const char *program_name;
+extern char *program_name;
 
 #define __ARRAY_SIZE_NOCHECK(ARRAY) (sizeof(ARRAY) / sizeof((ARRAY)[0]))
 #ifdef __GNUC__