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

Warning and note in sqlite3-binding.c

Open KrisCarr opened this issue 5 years ago • 18 comments

Every time my application starts or tests are run I get the following in my output:

# 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 can get round this by adding -w to the CFLAGS option inside sqlite3.go

Is there a better way to get rid of this warning and note?

I am running on Fedora 32 x86_64

KrisCarr avatar Apr 14 '20 17:04 KrisCarr

I have added -Wno-return-local-addr" to my environment variables in .bashrc which has got rid of all that mess for the time being.

export CGO_CFLAGS="-g -O2 -Wno-return-local-addr"

KrisCarr avatar Apr 14 '20 18:04 KrisCarr

A user of a product I am one of the maintainers for complained about the same thing. If you're able I'm interested in your gcc, glibc, and libsqlite3 versions; as it works fine for me.

For ref my versions are 9.3, 2.31, and 3.31.1

james-d-elliott avatar May 07 '20 23:05 james-d-elliott

with

sqlite3 --version
	3.31.1 2020-01-27 19:55:54 3bfa9cc97da10598521b342961df8f5f68c7388fa117345eeb516eaa837balt1

build with gcc10

	echo $CC $CXX $CPP
		/usr/bin/gcc-10 /usr/bin/g++-10 /usr/bin/cpp-10
	$CC --version
		gcc-10 (SUSE Linux) 10.1.1 20200507 [revision dd38686d9c810cecbaa80bb82ed91caaa58ad635]
	go build github.com/mattn/go-sqlite3
		# 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;
		       |          ^~~~~~~

and, build with gcc9

	echo $CC $CXX $CPP
		/usr/bin/gcc-9 /usr/bin/g++-9 /usr/bin/cpp-9
	$CC --version
		gcc-9 (SUSE Linux) 9.3.1 20200406 [revision 6db837a5288ee3ca5ec504fbd5a765817e556ac2]
	go build github.com/mattn/go-sqlite3

=====> NO SQLITE3 ERROR <====

pgnd avatar May 08 '20 03:05 pgnd

Yeah, looks like a gcc 10 issue, 9.3 works fine. It's likely the issue lies with libsqlite3-0 3.31.1 and gcc 10.x. Either a new warning being detected or a problem with 10.x - a lot of issues were resolved in 10.1 marked as regressions introduced between 9.3 and 10.0 (~700) so it could be that.

james-d-elliott avatar May 08 '20 03:05 james-d-elliott

looks likely

git clone https://github.com/sqlite/sqlite.git
cd sqlite
git checkout version-3.31.1
gcc --version
	gcc (SUSE Linux) 10.1.1 20200507 [revision dd38686d9c810cecbaa80bb82ed91caaa58ad635]
./configure
make
	...
	libtool: link: /usr/bin/gcc-10 -O3 -Wall -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fmessage-length=0 -grecord-gcc-switches -march=native -mtune=native -D_FORTIFY_SOURCE=2 -O3 -Wall -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fmessage-length=0 -grecord-gcc-switches -march=native -mtune=native -DSQLITE_OS_UNIX=1 -I. -I/usr/local/src/sqlite/src -I/usr/local/src/sqlite/ext/rtree -I/usr/local/src/sqlite/ext/icu -I/usr/local/src/sqlite/ext/fts3 -I/usr/local/src/sqlite/ext/async -I/usr/local/src/sqlite/ext/session -I/usr/local/src/sqlite/ext/userauth -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 -DSQLITE_HAVE_ZLIB=1 -DHAVE_READLINE=0 -DHAVE_EDITLINE=1 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_OFFSET_SQL_FUNC -DSQLITE_ENABLE_DESERIALIZE -o sqlite3 shell.c sqlite3.c  -ledit -ldl -lz -lpthread -Wl,-rpath -Wl,/usr/local/sqlite-gcc10-test/lib64
	In function 'zipfileComparePath',
	    inlined from 'zipfileUpdate' at shell.c:5784:11:
	shell.c:5656:17: warning: '__builtin_memcmp_eq' specified size between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
	 5656 |   if( nA==nB && memcmp(zA, zB, nA)==0 ) return 0;
	      |                 ^~~~~~~~~~~~~~~~~~
	sqlite3.c: In function ‘sqlite3SelectNew’:
	sqlite3.c:128048:10: warning: function may return address of local variable [-Wreturn-local-addr]
	128048 |   return pNew;
	       |          ^~~~
	sqlite3.c:128008:10: note: declared here
	128008 |   Select standin;
	       |          ^~~~~~~
	sqlite3.c:128008:10: note: declared here
	sqlite3.c: In function 'sqlite3SelectNew':
	sqlite3.c:128048:10: warning: function may return address of local variable [-Wreturn-local-addr]
	128048 |   return pNew;
	       |          ^~~~
	sqlite3.c:128008:10: note: declared here
	128008 |   Select standin;
	       |          ^~~~~~~
	sqlite3.c:128008:10: note: declared here
	...

pgnd avatar May 08 '20 03:05 pgnd

In my case...

$ go get -u -v github.com/mattn/go-sqlite3
# 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;
       |          ^~~~~~~

ClearLinux version:

$ swupd check-update 
Current OS version: 33100
Latest server version: 33100
There are no updates available

GCC Version

$ gcc --version
gcc (Clear Linux OS for Intel Architecture) 10.1.1 20200513 releases/gcc-10.1.0-36-gf2b77b928a
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

rbucker avatar May 15 '20 16:05 rbucker

windows 10 x64 2004 has the same issue

cnmade avatar May 18 '20 02:05 cnmade

This is an upstream bug with libsqlite3, not sure where their bug tracker is.

james-d-elliott avatar May 18 '20 03:05 james-d-elliott

This is an upstream bug with libsqlite3, not sure where their bug tracker is.

https://www3.sqlite.org/cgi/src/ticket

subpop avatar May 18 '20 13:05 subpop

There's a discussion on the SQLite Forum about this issue, including a candidate patch.

LawnGnome avatar May 27 '20 21:05 LawnGnome

Facing this issue with GoORM, which uses this sqlite3 driver. Any workarounds?

Update - adding this env variable fixed it, export CGO_CFLAGS="-g -O2 -Wno-return-local-addr"

payloadartist avatar Mar 03 '21 07:03 payloadartist

fixed in sqlite3 release 3.33, so go-sqlite3 1.14.1 and later doesn't have this issue

P. S. actual go-sqlite3 release is 1.14.7, not 2.0.x

edo1 avatar Apr 29 '21 17:04 edo1

export CGO_CFLAGS="-g -O2 -Wno-return-local-addr"

itz work

qweccc avatar May 06 '21 01:05 qweccc

Don't disable these warnings, people. You want to see them.

It's like seeing a small fire, closing your eyes and pretending it's not there!

awfulcooking avatar Oct 28 '21 14:10 awfulcooking

Don't disable these warnings, people. You want to see them.

It's like seeing a small fire, closing your eyes and pretending it's not there!

You have described the whole tech industry

image

pablodz avatar Feb 07 '22 21:02 pablodz

Hello I am facing the same problem while I try to install gophish. I use sudo go install github.com/gophish/gophish@latest ( Because get is deprecated from go dependecies and should add the value @latest or version.

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; | ^~~~~~~ This is the error I get. Please is there any workaround?

shalota1 avatar Aug 11 '22 20:08 shalota1

@shalota1 gophish is using v2.0.3 of this library, which is quite old. You will need to ask the maintainer to upgrade to the latest version (v1.14.14) and try that.

rittneje avatar Aug 11 '22 20:08 rittneje

For Windows user

go env -w CGO_CFLAGS="-g -O2 -Wno-return-local-addr"

PetengDedet avatar Sep 17 '22 05:09 PetengDedet