From fe7a851c44b3774874cc816d309e669ae9a86fb7 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 21 Aug 2023 10:49:02 +0200 Subject: [PATCH 1/4] fix(math): fix panic in `.Size()` --- math/int.go | 4 ++++ math/int_test.go | 1 + 2 files changed, 5 insertions(+) diff --git a/math/int.go b/math/int.go index e32b8ef3e0e8..da430d05452f 100644 --- a/math/int.go +++ b/math/int.go @@ -442,6 +442,10 @@ var ( ) func (i *Int) Size() (size int) { + if i == nil || i.i == nil { + return 0 + } + sign := i.Sign() if sign == 0 { // It is zero. // log*(0) is undefined hence return early. diff --git a/math/int_test.go b/math/int_test.go index e76cafc577d7..2fc01dfb6771 100644 --- a/math/int_test.go +++ b/math/int_test.go @@ -531,6 +531,7 @@ var sizeTests = []struct { s string want int }{ + {"", 0}, {"0", 1}, {"-0", 1}, {"-10", 3}, From af8242a68d7816a7c74c63e2044d7bce2de1125e Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 21 Aug 2023 10:51:22 +0200 Subject: [PATCH 2/4] changelog --- math/CHANGELOG.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/math/CHANGELOG.md b/math/CHANGELOG.md index d742b8e4abe4..a26572dc2331 100644 --- a/math/CHANGELOG.md +++ b/math/CHANGELOG.md @@ -34,7 +34,13 @@ Ref: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.j # Changelog -## [math/v1.1.0](https://github.com/cosmos/cosmos-sdk/releases/tag/math/v1.1.0) - 2023-08-18 +## [math/v1.1.1](https://github.com/cosmos/cosmos-sdk/releases/tag/math/v1.1.0) - 2023-08-18 + +### Bug Fixes + +* [#17480](https://github.com/cosmos/cosmos-sdk/pull/17480) Fix panic when calling `.Size()` on a nil `math.Int` value. + +## [math/v1.1.0](https://github.com/cosmos/cosmos-sdk/releases/tag/math/v1.1.0) - 2023-08-19 ### Features @@ -48,7 +54,7 @@ Ref: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.j ### Bug Fixes * [#17352](https://github.com/cosmos/cosmos-sdk/pull/17352) Ensure that modifying the argument to `NewIntFromBigInt` doesn't mutate the returned value. -* [#16266](https://github.com/cosmos/cosmos-sdk/pull/16266) fix: legacy dec power mut zero exponent precision. +* [#16266](https://github.com/cosmos/cosmos-sdk/pull/16266) Fix legacy dec power mut zero exponent precision. ## [math/v1.0.1](https://github.com/cosmos/cosmos-sdk/releases/tag/math/v1.0.1) - 2023-05-15 From c3c134ef1614f5b8998f05707e6c4a5824defb2b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 21 Aug 2023 10:51:51 +0200 Subject: [PATCH 3/4] updates --- math/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/CHANGELOG.md b/math/CHANGELOG.md index a26572dc2331..54c0ba994cb3 100644 --- a/math/CHANGELOG.md +++ b/math/CHANGELOG.md @@ -34,7 +34,7 @@ Ref: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.j # Changelog -## [math/v1.1.1](https://github.com/cosmos/cosmos-sdk/releases/tag/math/v1.1.0) - 2023-08-18 +## [math/v1.1.1](https://github.com/cosmos/cosmos-sdk/releases/tag/math/v1.1.1) - 2023-08-21 ### Bug Fixes From 196561853a719a1f0d739ca4c9c845df0d651b08 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 21 Aug 2023 10:55:35 +0200 Subject: [PATCH 4/4] updates --- math/int.go | 2 +- math/int_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/math/int.go b/math/int.go index da430d05452f..cbbeb740f845 100644 --- a/math/int.go +++ b/math/int.go @@ -443,7 +443,7 @@ var ( func (i *Int) Size() (size int) { if i == nil || i.i == nil { - return 0 + return 1 } sign := i.Sign() diff --git a/math/int_test.go b/math/int_test.go index 2fc01dfb6771..302e9ae2ee62 100644 --- a/math/int_test.go +++ b/math/int_test.go @@ -531,7 +531,7 @@ var sizeTests = []struct { s string want int }{ - {"", 0}, + {"", 1}, {"0", 1}, {"-0", 1}, {"-10", 3},