From: Ansis Atteka Date: Tue, 8 Jul 2014 04:11:53 +0000 (+0000) Subject: util: fix compile warnings X-Git-Tag: v2.3~35 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=27be9423015cadb2cf808fc1bf3f1f558614c3f8 util: fix compile warnings 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 Reported-By: Lorand Jakab Signed-Off-By: Ansis Atteka Acked-by: Joe Stringer --- diff --git a/lib/util.c b/lib/util.c index 1a30757d6..26ec174ee 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 4d0ba76ba..4282007c8 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__