strconv.ParseFloat panic

233 views
Skip to first unread message

blade...@gmail.com

unread,
Nov 6, 2020, 3:00:32 AM11/6/20
to golang-nuts
i check my code, and strconv.ParseFloat(s, 64), s is a string, it is correct, but  after run my program for a while, it's panic and report some output info. i cant't find why , anyone can help me 


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

goroutine 2948735 [running]:
strconv.special(0x0, 0x4, 0x0, 0x3ff2e147ae147ae1, 0x1)
strconv/atof.go:48 +0x34
strconv.atof64(0x0, 0x4, 0x41421d, 0xc05323c380, 0xc05dd95ab0, 0xa)
strconv/atof.go:612 +0x50
strconv.parseFloatPrefix(0x0, 0x4, 0x40, 0x3, 0xc078741b48, 0xc05dd95ab0, 0xc078741b40)
strconv/atof.go:695 +0x95
strconv.ParseFloat(0x0, 0x4, 0x40, 0xa, 0xc078741bc8, 0xc05dd95a01)
strconv/atof.go:683 +0x45
xxxxxx/api.handleDPriceRange(0xc01777c820)
xxxxxx/api/PriceCalendar.go:1008 +0x212
xxxxxx/api.priceCalendarItemExpand(0xc016e34a80, 0xc96, 0xc96)
xxxxxx/api/PriceCalendar.go:1104 +0xb9b
xxxxxx/api.FlightlineRT(0xc001bd9d98, 0xc0002294f0, 0x1306020, 0xc04f1415c0, 0xc05e653a70, 0x10000c000229518, 0xc05193dc00)
xxxxxx/api/external_api.go:146 +0x108
xxxxxx/api.aaa.func2(0xc04f1456b0, 0xc04f102340, 0xc05d23aa68, 0x3, 0xc05465c230, 0x63, 0xc04f13c301, 0x7, 0x0, 0x0, ...)
xxxxxx/api/external_api.go:343 +0x25b
created by xxxxxx/api.AppMainpage
xxxxxx/api/external_api.go:330 +0x57e

Brian Candler

unread,
Nov 6, 2020, 3:25:36 AM11/6/20
to golang-nuts
On Friday, 6 November 2020 08:00:32 UTC, blade...@gmail.com wrote:
anyone can help me 

You will need to give some basic info.  At very least show the code that causes this crash, i.e. the code in external_api.go at line 330 with a few lines of context either side.  Also say what version of Go you are building with, and the OS you are running under.

Does your code have concurrent goroutines? Have you tried running it with the race detector enabled?

Dan Kortschak

unread,
Nov 6, 2020, 3:34:21 AM11/6/20
to golang-nuts
The full panic would help, but somehow you have a string with a nil
pointer that is 4 bytes long. Where is the string generated? Are you
using Cgo? Have you run with the race detector? Also, what version of
Go are you using?
> --
> You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/9c672d72-7daa-4fe1-9f84-136c2eaa2065n%40googlegroups.com
> .


blade...@gmail.com

unread,
Nov 6, 2020, 4:10:44 AM11/6/20
to golang-nuts
go version is 1.15 , cross compile on darwin  and run on linux,  i will try to run with race deector

Dan Kortschak

unread,
Nov 6, 2020, 4:28:51 PM11/6/20
to golang-nuts
OK, so you're not using Cgo, that leaves some other unsafe use, a data
race or unlikely some weird compiler bug.

I'd start looking in api.handleDPriceRange to see where the string
input to strconv.ParseFloat is being constructed.

blade...@gmail.com

unread,
Nov 9, 2020, 10:03:56 PM11/9/20
to golang-nuts
thanks all, i find a race problem, and fix it. 
Reply all
Reply to author
Forward
0 new messages