RFR: 8261300: jpackage: rewrite while(0)/while(false) to proper blocks [v3]
Aleksey Shipilev
shade at openjdk.java.net
Tue Feb 9 08:58:23 UTC 2021
> After JDK-8254702, SonarCloud instance complains about blocks like these: "Change this loop body so that it can be executed more than once."
>
> int initJvmlLauncherData(JvmlLauncherData* ptr) const {
> // Store path to JLI library just behind JvmlLauncherData header.
> char* curPtr = reinterpret_cast<char*>(ptr + 1);
> do {
> const size_t count = sizeof(char)
> * (jliLibPath.size() + 1 /* trailing zero */);
> if (ptr) {
> std::memcpy(curPtr, jliLibPath.c_str(), count);
> ptr->jliLibPath = curPtr;
> }
> curPtr += count;
> } while (false); // <---- here
>
> There is no sense in having `while(false)` here, where the syntactic `{}` block would do. There are also other uses in the jpackage code that employ `while(0)` for this, and then they also trigger the inspection about the implicit conversion of zero int to boolean.
>
> Additional testing:
> - [x] Linux x86_64 (Ubuntu) tools/jpackage
Aleksey Shipilev has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:
- Fix Windows build failure: illegal break (where while loop used to be)
- Merge branch 'master' into JDK-8261300-jpackage-while-0
- More cleanup in tstrings.cpp
- Replace with {}
-------------
Changes:
- all: https://git.openjdk.java.net/jdk/pull/2454/files
- new: https://git.openjdk.java.net/jdk/pull/2454/files/d895c44a..535024b8
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=jdk&pr=2454&range=02
- incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=2454&range=01-02
Stats: 3817 lines in 211 files changed: 2333 ins; 236 del; 1248 mod
Patch: https://git.openjdk.java.net/jdk/pull/2454.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/2454/head:pull/2454
PR: https://git.openjdk.java.net/jdk/pull/2454
More information about the core-libs-dev
mailing list