# HG changeset patch # User goetz # Date 1393844075 -3600 # Node ID 81da73d822eab5396cea0bcde6597a68be507f13 # Parent 2edca307b15a05698376c48f99b8422f7a9e775e 8036122: Fix warning 'format not a string literal' diff --git a/make/bsd/makefiles/gcc.make b/make/bsd/makefiles/gcc.make --- a/make/bsd/makefiles/gcc.make +++ b/make/bsd/makefiles/gcc.make @@ -260,7 +260,7 @@ WARNINGS_ARE_ERRORS += -Wno-empty-body endif -WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef -Wunused-function -Wformat=2 -Wno-error=format-nonliteral +WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef -Wunused-function -Wformat=2 ifeq ($(USE_CLANG),) # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit diff --git a/make/linux/makefiles/gcc.make b/make/linux/makefiles/gcc.make --- a/make/linux/makefiles/gcc.make +++ b/make/linux/makefiles/gcc.make @@ -215,7 +215,7 @@ WARNINGS_ARE_ERRORS += -Wno-return-type -Wno-empty-body endif -WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef -Wunused-function -Wunused-value -Wformat=2 -Wno-error=format-nonliteral +WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef -Wunused-function -Wunused-value -Wformat=2 ifeq ($(USE_CLANG),) # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit diff --git a/make/solaris/makefiles/gcc.make b/make/solaris/makefiles/gcc.make --- a/make/solaris/makefiles/gcc.make +++ b/make/solaris/makefiles/gcc.make @@ -118,7 +118,7 @@ # Compiler warnings are treated as errors WARNINGS_ARE_ERRORS = -Werror # Enable these warnings. See 'info gcc' about details on these options -WARNING_FLAGS = -Wpointer-arith -Wconversion -Wsign-compare -Wundef -Wformat=2 -Wno-error=format-nonliteral +WARNING_FLAGS = -Wpointer-arith -Wconversion -Wsign-compare -Wundef -Wformat=2 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS) # Special cases CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp --- a/src/os/linux/vm/os_linux.cpp +++ b/src/os/linux/vm/os_linux.cpp @@ -5284,7 +5284,6 @@ static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { static bool proc_task_unchecked = true; - static const char *proc_stat_path = "/proc/%d/stat"; pid_t tid = thread->osthread()->thread_id(); char *s; char stat[2048]; @@ -5297,6 +5296,8 @@ long ldummy; FILE *fp; + snprintf(proc_name, 64, "/proc/%d/stat", tid); + // The /proc//stat aggregates per-process usage on // new Linux kernels 2.6+ where NPTL is supported. // The /proc/self/task//stat still has the per-thread usage. @@ -5308,12 +5309,11 @@ proc_task_unchecked = false; fp = fopen("/proc/self/task", "r"); if (fp != NULL) { - proc_stat_path = "/proc/self/task/%d/stat"; + snprintf(proc_name, 64, "/proc/self/task/%d/stat", tid); fclose(fp); } } - sprintf(proc_name, proc_stat_path, tid); fp = fopen(proc_name, "r"); if ( fp == NULL ) return -1; statlen = fread(stat, 1, 2047, fp); diff --git a/src/share/vm/compiler/compilerOracle.cpp b/src/share/vm/compiler/compilerOracle.cpp --- a/src/share/vm/compiler/compilerOracle.cpp +++ b/src/share/vm/compiler/compilerOracle.cpp @@ -374,25 +374,8 @@ "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff" #define RANGE0 "[*" RANGEBASE "]" -#define RANGEDOT "[*" RANGEBASE ".]" #define RANGESLASH "[*" RANGEBASE "/]" - -// Accept several syntaxes for these patterns -// original syntax -// cmd java.lang.String foo -// PrintCompilation syntax -// cmd java.lang.String::foo -// VM syntax -// cmd java/lang/String[. ]foo -// - -static const char* patterns[] = { - "%*[ \t]%255" RANGEDOT " " "%255" RANGE0 "%n", - "%*[ \t]%255" RANGEDOT "::" "%255" RANGE0 "%n", - "%*[ \t]%255" RANGESLASH "%*[ .]" "%255" RANGE0 "%n", -}; - static MethodMatcher::Mode check_mode(char name[], const char*& error_msg) { int match = MethodMatcher::Exact; while (name[0] == '*') { @@ -421,12 +404,10 @@ int* bytes_read, const char*& error_msg) { *bytes_read = 0; error_msg = NULL; - for (uint i = 0; i < ARRAY_SIZE(patterns); i++) { - if (2 == sscanf(line, patterns[i], class_name, method_name, bytes_read)) { - *c_mode = check_mode(class_name, error_msg); - *m_mode = check_mode(method_name, error_msg); - return *c_mode != MethodMatcher::Unknown && *m_mode != MethodMatcher::Unknown; - } + if (2 == sscanf(line, "%*[ \t]%255" RANGESLASH "%*[ ]" "%255" RANGE0 "%n", class_name, method_name, bytes_read)) { + *c_mode = check_mode(class_name, error_msg); + *m_mode = check_mode(method_name, error_msg); + return *c_mode != MethodMatcher::Unknown && *m_mode != MethodMatcher::Unknown; } return false; }