go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

[WARNING] sqlite3-binding.c: In function ‘sqlite3SelectNew’

Open vzool opened this issue 4 years ago • 4 comments

Hi, while I'm developing an appliation using gorm I noticed new messages shown in my terminal and said there is an issues in this package:

# github.com/mattn/go-sqlite3
sqlite3-binding.c: In function ‘sqlite3SelectNew’:
sqlite3-binding.c:128049:10: warning: function may return address of local variable [-Wreturn-local-addr]
128049 |   return pNew;
       |          ^~~~
sqlite3-binding.c:128009:10: note: declared here
128009 |   Select standin;
       |          ^~~~~~~

I hope this message helps you out to fix the issue. Thanks

vzool avatar Jun 07 '20 08:06 vzool

#803

vzool avatar Jun 07 '20 08:06 vzool

Anyone know of an alternative way to fix the warning messages that doesn't require env vars?

Using these cgo flags mentioned in #803 does work to silence the warnings but it's not ideal:

CGO_CFLAGS="-g -O2 -Wno-return-local-addr" go run main.go

miguelmota avatar Jul 04 '20 21:07 miguelmota

@miguelmota That depends what you consider to be a fix. As mentioned in the linked issue, this warning is a false positive that could be addressed by changing how SQLite itself is implemented, but it is unclear whether such a change will be made. Alternatively, that flag could be added to this wrapper library so you don't need to manually set an environment variable.

https://github.com/mattn/go-sqlite3/blob/aa77c03e2fcb7ed283920d09a0fb6b873488b5be/sqlite3.go#L12-L24

#cgo CFLAGS: -Wno-return-local-addr

rittneje avatar Jul 05 '20 05:07 rittneje

@rittneje that worked perfectly, thanks!

miguelmota avatar Jul 10 '20 21:07 miguelmota