Skip to content

math/big: signal SIGSEGV: segmentation violation when using multi-line strings. #60233

@agiUnderground

Description

@agiUnderground

What version of Go are you using (go version)?

$ go version
go version go1.20.4 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
macos Ventura 13.3.1 Darwin Kernel Version 22.4.0
x86_64

What did you do?

package main

import (
	"fmt"
	mb "math/big"
)

func main() {
	a := mb.NewInt(0)
	b := mb.NewInt(0)
	c := mb.NewInt(0)
	a, _ = a.SetString(`93495878923078976349082734823469324758967234678569
                           62387685983479898989898989899899898998989889899898
                           98989898989989898989898989899898988989898989898989
                           89898988989898989889898989989898989879879879`, 10);
	b, _ = b.SetString(`9999999949532798763428068937249324976893467324785
                           67843264876432598734698572634856923599999999983493
                           49683247986789324769438726463080980980908998798798
                           797897987987987979878978979878897987897789789`, 10);
	c.Add(a, b);
	fmt.Println(c);
}

https://play.golang.com/p/06JOoCfsT0D

What did you expect to see?

193495878418406963983363424195962574527901907926426408203347478058863368847162484691349989898897348339582237885788314668428625453070879879898897788697787796976977886969768877969868796977777669668

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x484d7d]

goroutine 1 [running]:
math/big.(*Int).Add(0xc000060020, 0x4b84a0?, 0x116?)
	/usr/local/go-faketime/src/math/big/int.go:135 +0x1d
main.main()
	/tmp/sandbox4028842665/prog.go:20 +0xe5

It is working with a regular strings formatted in one line, but with this multi-line backtick format it fails.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions