address: fix stack overflow bug when printing error
Commit 24e673ae
introduced a bug that cause the Error() function to
call itself recursively forever, causing a stack overflow. We explicitly
cast the error to its base type to avoid the recursion and add a small
test case that would've triggered the bug before.
This commit is contained in:
parent
90ffd449a4
commit
4ebb6a9960
2 changed files with 10 additions and 2 deletions
|
@ -23,7 +23,7 @@ import (
|
||||||
type UnsupportedWitnessVerError byte
|
type UnsupportedWitnessVerError byte
|
||||||
|
|
||||||
func (e UnsupportedWitnessVerError) Error() string {
|
func (e UnsupportedWitnessVerError) Error() string {
|
||||||
return fmt.Sprintf("unsupported witness version: %#x", e)
|
return fmt.Sprintf("unsupported witness version: %#x", byte(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnsupportedWitnessProgLenError describes an error where a segwit address
|
// UnsupportedWitnessProgLenError describes an error where a segwit address
|
||||||
|
@ -31,7 +31,7 @@ func (e UnsupportedWitnessVerError) Error() string {
|
||||||
type UnsupportedWitnessProgLenError int
|
type UnsupportedWitnessProgLenError int
|
||||||
|
|
||||||
func (e UnsupportedWitnessProgLenError) Error() string {
|
func (e UnsupportedWitnessProgLenError) Error() string {
|
||||||
return fmt.Sprintf("unsupported witness program length: %d", e)
|
return fmt.Sprintf("unsupported witness program length: %d", int(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -859,6 +859,14 @@ func TestAddresses(t *testing.T) {
|
||||||
test.name)
|
test.name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// If there is an error, make sure we can print it
|
||||||
|
// correctly.
|
||||||
|
errStr := err.Error()
|
||||||
|
if errStr == "" {
|
||||||
|
t.Errorf("%v: error was non-nil but message is"+
|
||||||
|
"empty: %v", test.name, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !test.valid {
|
if !test.valid {
|
||||||
|
|
Loading…
Add table
Reference in a new issue