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 <[email protected]>
Reported-By: Lorand Jakab <[email protected]>
Signed-Off-By: Ansis Atteka <[email protected]>
---
lib/util.c | 14 ++++++--------
lib/util.h | 2 +-
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/lib/util.c b/lib/util.c
index 1a30757..26ec174 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -42,7 +42,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. */
@@ -454,24 +454,22 @@ 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);
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)) {
diff --git a/lib/util.h b/lib/util.h
index 4d0ba76..4282007 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -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__
--
1.7.9.5
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev