RFR: 8281525: Enable Zc:strictStrings flag in Visual Studio build
Magnus Ihse Bursie
ihse at openjdk.java.net
Tue Feb 22 11:36:52 UTC 2022
On Mon, 21 Feb 2022 19:55:14 GMT, Daniel Jeliński <djelinski at openjdk.org> wrote:
> Please review this PR that enables [Zc:strictStrings](https://docs.microsoft.com/en-us/cpp/build/reference/zc-strictstrings-disable-string-literal-type-conversion?view=msvc-170) compiler flag, which makes assigning a string literal to a non-const pointer a compile-time error.
>
> This type of assignment is [disallowed by C++ standard since C++11](https://en.cppreference.com/w/cpp/language/string_literal). Writing to a string literal through a non-const pointer [produces a run-time error](https://docs.microsoft.com/en-us/cpp/cpp/string-and-character-literals-cpp?view=msvc-170#microsoft-specific-1).
>
> The included code changes are trivial; I added `const` keyword to variable and parameter declarations where needed, and added explicit casts to non-const pointers where adding `const` was not feasible.
>
> I verified that the build passes both with and without `--enable-debug`, both with VS2017 and VS2019.
make/autoconf/flags-cflags.m4 line 136:
> 134: CFLAGS_WARNINGS_ARE_ERRORS="-WX"
> 135:
> 136: WARNINGS_ENABLE_ALL="-W3 -Zc:strictStrings"
This is not strictly a flag to enable warnings. I'd recommend you move it to line 499 and 500 in the same file, which would align it with the -Zc:wchar_t- switch. Make sure you add it to both TOOLCHAIN_CFLAGS_JVM and TOOLCHAIN_CFLAGS_JDK.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7565
More information about the security-dev
mailing list