Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: fixed unreachable if statements in zlib #24190

Closed
wants to merge 2 commits into from

Conversation

dYale
Copy link
Contributor

@dYale dYale commented Nov 6, 2018

Refactored assertions in lib/zlib to be reachable

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows [commit guidelines]

@nodejs-github-bot nodejs-github-bot added the zlib Issues and PRs related to the zlib subsystem. label Nov 6, 2018
@addaleax addaleax added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Nov 6, 2018
@@ -350,8 +350,7 @@ Object.defineProperty(Zlib.prototype, 'bytesRead', {
// `params()` function should not happen while a write is currently in progress
// on the threadpool.
function paramsAfterFlushCallback(level, strategy, callback) {
if (!this._handle)
Copy link
Member

@lpinca lpinca Nov 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was an optimization to avoid an unnecessary function call in the common case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should not be a significant overhead. Such a micro optimization should not have any impact on a real application.

lib/zlib.js Outdated
} else if (have < 0) {
assert(false, 'have should not go down');
} else {
assert(have >= 0, 'have should not go down');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert(have >= 0, 'have should not go down');
assert(have === 0, 'have should not go down');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not obvious from looking at the code why that check is sufficient. Do you have a small description why? :)

lib/zlib.js Outdated
} else if (have < 0) {
assert(false, 'have should not go down');
} else {
assert(have >= 0, 'have should not go down');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert(have >= 0, 'have should not go down');
assert(have === 0, 'have should not go down');

@gireeshpunathil
Copy link
Member

ping @dYale to consider @lpinca 's suggestions.

@Trott
Copy link
Member

Trott commented Nov 14, 2018

@Trott Trott added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Nov 14, 2018
@devsnek
Copy link
Member

devsnek commented Nov 14, 2018

you could also change these to CHECK/DCHECK

@Trott
Copy link
Member

Trott commented Nov 15, 2018

@Trott
Copy link
Member

Trott commented Nov 15, 2018

@Trott
Copy link
Member

Trott commented Nov 15, 2018

Took a problematic Windows host offline. Resume Build one more time: https://ci.nodejs.org/job/node-test-pull-request/18635/

@Trott
Copy link
Member

Trott commented Nov 15, 2018

Landed in 4e6d28a

Thanks for the contribution! 🎉

(If you're interested in other possible contributions to Node.js but don't have a good idea of where to start looking, some ideas are posted at https://www.nodetodo.org/next-steps/.)

@Trott Trott closed this Nov 15, 2018
Trott pushed a commit to Trott/io.js that referenced this pull request Nov 15, 2018
PR-URL: nodejs#24190
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
BridgeAR pushed a commit that referenced this pull request Nov 15, 2018
PR-URL: #24190
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
codebytere pushed a commit that referenced this pull request Jan 12, 2019
PR-URL: #24190
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@codebytere codebytere mentioned this pull request Jan 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. zlib Issues and PRs related to the zlib subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants