On Wed, 4 Dec 2024 16:04:01 GMT, SendaoYan <s...@openjdk.org> wrote: >> Hi all, >> The file src/java.base/share/native/libjli/java.c generate false positive >> compile warning by gcc14 with gcc options `-fsanitize=undefined -O2`, and >> make jdk build error when configure with option `--enable-asan >> --enable-ubsan`. So I think it's necessory to disable the false positive >> compile warning to make jdk build normally with configure option >> `--enable-asan --enable-ubsan`. >> >> This PR use gcc `_Pragma` to disbale the `-Wformat-truncation` compile >> warning, to make the disable code area as small as possible, and make the >> change looks ugly. There is another solution to disable the compile warning >> seen as below, but it will disable the compile warning of java.c. So I use >> the first solution. >> >> >> >> diff --git a/make/modules/java.base/lib/CoreLibraries.gmk >> b/make/modules/java.base/lib/CoreLibraries.gmk >> index 61ac495968a..5bc83cf0978 100644 >> --- a/make/modules/java.base/lib/CoreLibraries.gmk >> +++ b/make/modules/java.base/lib/CoreLibraries.gmk >> @@ -178,6 +178,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJLI, \ >> OPTIMIZATION := HIGH, \ >> CFLAGS := $(LIBJLI_CFLAGS) $(LIBZ_CFLAGS), \ >> DISABLED_WARNINGS_gcc := unused-function unused-variable, \ >> + DISABLED_WARNINGS_gcc_java.c := format-truncation, \ >> DISABLED_WARNINGS_clang := deprecated-non-prototype format-nonliteral \ >> unused-function, \ >> DISABLED_WARNINGS_clang_java_md_macosx.m := unused-variable, \ > > SendaoYan has updated the pull request incrementally with one additional > commit since the last revision: > > Fix compile warning C4068: unknown pragma 'GCC' on windows
The part that I don't understand is why the `s` is being considered as having a `NULL` value for the gcc compiler to generate that warning for the `snprintf` call: if (s == NULL) return; s = JLI_WildcardExpandClasspath(s); if (sizeof(format) - 2 + JLI_StrLen(s) < JLI_StrLen(s)) // s is became corrupted after expanding wildcards return; size_t defSize = sizeof(format) - 2 /* strlen("%s") */ + JLI_StrLen(s); def = JLI_MemAlloc(defSize); snprintf(def, defSize, format, s); ``` It looks like the compiler is considering `s = JLI_WildcardExpandClasspath(s);` to be returning `NULL` (if I comment that line out) the warning is gone. The other part to this is, I can't get the warning to be generated with gcc 13.x. So I don't know if this is a bug in gcc 14.x or some kind of improvement in detecting some genuine issue. ------------- PR Comment: https://git.openjdk.org/jdk/pull/22546#issuecomment-2545418968