Skip to content

Commit c7e1a53

Browse files
Fix imuln/muln with zero (#313)
Co-authored-by: CanardMandarin <[email protected]>
1 parent 4cc0bfa commit c7e1a53

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
fetch-depth: 1
1717

1818
- name: Restore node_modules cache
19-
uses: actions/cache@v1
19+
uses: actions/cache@v4
2020
with:
2121
path: ~/.npm
2222
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
@@ -37,7 +37,7 @@ jobs:
3737
fetch-depth: 1
3838

3939
- name: Restore node_modules cache
40-
uses: actions/cache@v1
40+
uses: actions/cache@v4
4141
with:
4242
path: ~/.npm
4343
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}

lib/bn.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,7 @@
20082008
this.words[i] = carry;
20092009
this.length++;
20102010
}
2011+
this.length = num === 0 ? 1 : this.length;
20112012

20122013
return isNegNum ? this.ineg() : this;
20132014
};

test/arithmetic-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,16 @@ describe('BN.js/Arithmetic', function () {
305305
assert.equal(b.clone().imuln(-42).toString(16), b.clone().neg().muln(42).toString(16));
306306
assert.equal(b.clone().muln(-42).toString(16), b.clone().neg().muln(42).toString(16));
307307
});
308+
309+
it('should strip length on zero multiplication', function () {
310+
var a = new BN(42);
311+
assert.equal(a.clone().imuln(0).isZero(), true);
312+
assert.equal(a.clone().muln(0).isZero(), true);
313+
314+
var b = new BN('1222222225255589');
315+
assert.equal(b.clone().imuln(0).isZero(), true);
316+
assert.equal(b.clone().muln(0).isZero(), true);
317+
});
308318
});
309319

310320
describe('.pow()', function () {

0 commit comments

Comments
 (0)