Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation warning in sqlite3-binding.c #1165

Open
justonlyme1 opened this issue May 26, 2023 · 2 comments
Open

Compilation warning in sqlite3-binding.c #1165

justonlyme1 opened this issue May 26, 2023 · 2 comments

Comments

@justonlyme1
Copy link

Description
I encountered a compilation warning while attempting to build the github.com/mattn/go-sqlite3 package. The warning message is related to the sqlite3-binding.c file, specifically within the sqlite3SelectNew function. The warning suggests that the function may be returning the address of a local variable, which can lead to undefined behavior.

Steps to Reproduce
Clone the github.com/mattn/go-sqlite3 repository.
Build the package using the go build command.
Observe the compilation warning displayed.
Expected Behavior
The package should compile without any warnings, ensuring that there are no potential issues or undefined behavior within the code.

Actual Behavior
During compilation, the following warning is displayed:

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;
| ^~~~~~~
Environment
Go version: [Specify your Go version]
Operating System: [Specify your OS]
Additional Information
[Provide any additional information or context that may be relevant to the issue.]

Impact
The warning may indicate a potential issue in the code, where the function sqlite3SelectNew in sqlite3-binding.c returns the address of a local variable. This can lead to undefined behavior and should be addressed to ensure the code's correctness and stability.

Possible Solution
One possible solution would be to dynamically allocate memory for the relevant variable using malloc or a similar function and return the dynamically allocated memory. However, since the code is in a third-party package, modifying it directly may not be ideal.

@bcrant
Copy link

bcrant commented May 27, 2023

I am also getting this error, as go-sqlite3 is in the dependency chain for project I am working on using github.com/influxdata/flux

/go/bin/pkg-config: exit status 1
# github.com/mattn/go-sqlite3
sqlite3-binding.c: In function 'sqlite3SelectNew':
sqlite3-binding.c:125322:10: warning: function may return address of local variable [-Wreturn-local-addr]
125322 |   return pNew;
       |          ^~~~
sqlite3-binding.c:125282:10: note: declared here
125282 |   Select standin;
       |          ^~~~~~~

This is out of my depth so unfortunately I have no solutions to offer, just wanted to raise awareness to this issue in builds.

Edit: Saw in a related post proof to see that proper C installation exists:

root@f5170abaa86f:/go# go env | grep "CGO"
GCCGO="gccgo"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
root@f5170abaa86f:/go# gcc --version
gcc (Debian 10.2.1-6) 10.2.1 20210110

@gitchg
Copy link

gitchg commented Jun 14, 2023

gcc version should not above v10.0 or go-sqlite3 under v2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants