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

Compilation warning in sqlite3-binding.c

Open justonlyme1 opened this issue 2 years ago • 2 comments

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.

justonlyme1 avatar May 26 '23 21:05 justonlyme1