From e3d22c0c0920cdaa2d2c22b12f3694e32a875a10 Mon Sep 17 00:00:00 2001 From: Dan Corman Date: Tue, 6 Nov 2018 16:54:47 +0000 Subject: [PATCH 1/2] lib: fixed unreachable if statements in zlib --- lib/zlib.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/zlib.js b/lib/zlib.js index c833afff14f4b9..356a6eba69ad78 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -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) - assert(false, 'zlib binding closed'); + assert(this._handle, 'zlib binding closed'); this._handle.params(level, strategy); if (!this._hadError) { this._level = level; @@ -507,8 +506,8 @@ function processChunkSync(self, chunk, flushFlag) { else buffers.push(out); nread += out.byteLength; - } else if (have < 0) { - assert(false, 'have should not go down'); + } else { + assert(have >= 0, 'have should not go down'); } // exhausted the output buffer, or used all the input create a new one. @@ -545,8 +544,7 @@ function processChunkSync(self, chunk, flushFlag) { function processChunk(self, chunk, flushFlag, cb) { var handle = self._handle; - if (!handle) - assert(false, 'zlib binding closed'); + assert(handle, 'zlib binding closed'); handle.buffer = chunk; handle.cb = cb; @@ -593,8 +591,8 @@ function processCallback() { var out = self._outBuffer.slice(self._outOffset, self._outOffset + have); self._outOffset += have; self.push(out); - } else if (have < 0) { - assert(false, 'have should not go down'); + } else { + assert(have >= 0, 'have should not go down'); } if (self.destroyed) { From 481471711818bfbc0b60c79a54b5c4d20018fd92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CDan?= Date: Wed, 14 Nov 2018 09:42:36 -0500 Subject: [PATCH 2/2] lib: improved conditional check in zlib --- lib/zlib.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/zlib.js b/lib/zlib.js index 356a6eba69ad78..559f6c2d5f3056 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -507,7 +507,7 @@ function processChunkSync(self, chunk, flushFlag) { buffers.push(out); nread += out.byteLength; } else { - assert(have >= 0, 'have should not go down'); + assert(have === 0, 'have should not go down'); } // exhausted the output buffer, or used all the input create a new one. @@ -592,7 +592,7 @@ function processCallback() { self._outOffset += have; self.push(out); } else { - assert(have >= 0, 'have should not go down'); + assert(have === 0, 'have should not go down'); } if (self.destroyed) {