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 warnings: pixel set but not used, misleading indentation. #66

Open
AlbertoGP opened this issue Oct 7, 2022 · 2 comments
Open

Comments

@AlbertoGP
Copy link

It compiles and runs fine, this is just some warnings with GCC 10.2.1 20201203 on Linux ppc64le.
I’m preparing a pull request.

$ make
cc -O2 -Wall -W -Ilua/src `pkg-config --cflags sdl2 SDL2_gfx SDL2_image`   -c -o load81.o load81.c
load81.c: In function 'getpixelBinding':
load81.c:216:12: warning: variable 'pixel' set but not used [-Wunused-but-set-variable]
  216 |     Uint32 pixel;
      |            ^~~~~
cc -O2 -Wall -W -Ilua/src `pkg-config --cflags sdl2 SDL2_gfx SDL2_image`   -c -o editor.o editor.c
cc -O2 -Wall -W -Ilua/src `pkg-config --cflags sdl2 SDL2_gfx SDL2_image`   -c -o framebuffer.o framebuffer.c
(cd lua && make ansi)
make[1]: Entering directory '/tmp/ramdisk/load81/lua'
cd src && make ansi
make[2]: Entering directory '/tmp/ramdisk/load81/lua/src'
make all MYCFLAGS=-DLUA_ANSI
make[3]: Entering directory '/tmp/ramdisk/load81/lua/src'
gcc -O2 -Wall -DLUA_ANSI   -c -o lapi.o lapi.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lcode.o lcode.c
gcc -O2 -Wall -DLUA_ANSI   -c -o ldebug.o ldebug.c
gcc -O2 -Wall -DLUA_ANSI   -c -o ldo.o ldo.c
gcc -O2 -Wall -DLUA_ANSI   -c -o ldump.o ldump.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lfunc.o lfunc.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lgc.o lgc.c
gcc -O2 -Wall -DLUA_ANSI   -c -o llex.o llex.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lmem.o lmem.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lobject.o lobject.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lopcodes.o lopcodes.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lparser.o lparser.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lstate.o lstate.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lstring.o lstring.c
gcc -O2 -Wall -DLUA_ANSI   -c -o ltable.o ltable.c
gcc -O2 -Wall -DLUA_ANSI   -c -o ltm.o ltm.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lundump.o lundump.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lvm.o lvm.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lzio.o lzio.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lauxlib.o lauxlib.c
lauxlib.c: In function 'luaL_loadfile':
lauxlib.c:577:4: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
  577 |    while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
      |    ^~~~~
lauxlib.c:578:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
  578 |     lf.extraline = 0;
      |     ^~
gcc -O2 -Wall -DLUA_ANSI   -c -o lbaselib.o lbaselib.c
gcc -O2 -Wall -DLUA_ANSI   -c -o ldblib.o ldblib.c
gcc -O2 -Wall -DLUA_ANSI   -c -o liolib.o liolib.c
gcc -O2 -Wall -DLUA_ANSI   -c -o lmathlib.o lmathlib.c
gcc -O2 -Wall -DLUA_ANSI   -c -o loslib.o loslib.c
gcc -O2 -Wall -DLUA_ANSI   -c -o ltablib.o ltablib.c
ltablib.c: In function 'addfield':
ltablib.c:137:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  137 |   if (!lua_isstring(L, -1))
      |   ^~
ltablib.c:140:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  140 |     luaL_addvalue(b);
      |     ^~~~~~~~~~~~~
gcc -O2 -Wall -DLUA_ANSI   -c -o lstrlib.o lstrlib.c
gcc -O2 -Wall -DLUA_ANSI   -c -o loadlib.o loadlib.c
gcc -O2 -Wall -DLUA_ANSI   -c -o linit.o linit.c
ar rcu liblua.a lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o loadlib.o linit.o	# DLL needs all object files
ar: `u' modifier ignored since `D' is the default (see `U')
ranlib liblua.a
gcc -O2 -Wall -DLUA_ANSI   -c -o lua.o lua.c
gcc -o lua  lua.o liblua.a -lm 
/usr/bin/ld: liblua.a(loslib.o): in function `os_tmpname':
loslib.c:(.text+0x4e4): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
gcc -O2 -Wall -DLUA_ANSI   -c -o luac.o luac.c
gcc -O2 -Wall -DLUA_ANSI   -c -o print.o print.c
gcc -o luac  luac.o print.o liblua.a -lm 
make[3]: Leaving directory '/tmp/ramdisk/load81/lua/src'
make[2]: Leaving directory '/tmp/ramdisk/load81/lua/src'
make[1]: Leaving directory '/tmp/ramdisk/load81/lua'
cc   load81.o editor.o framebuffer.o lua/src/liblua.a  lua/src/liblua.a -lm `pkg-config --libs sdl2 SDL2_gfx SDL2_image` -o load81
@AlbertoGP
Copy link
Author

AlbertoGP commented Oct 7, 2022

The fix is in #67, but GitHub is not linking them automatically.

This leaves only one warning:

/usr/bin/ld: liblua.a(loslib.o): in function `os_tmpname':
loslib.c:(.text+0x4e4): warning: the use of `tmpnam' is dangerous, better use `mkstemp'

There is a note about this in lua/src/luaconf.h:

lua_tmpnam is the function that the OS library uses to create a temporary name.
LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.
CHANGE them if you have an alternative to tmpnam (which is considered insecure) or if you want the original tmpnam anyway.
By default, Lua uses tmpnam except when POSIX is available, where it uses mkstemp.

If I understand this correctly, when running on Linux it would not use tmpnam anyway. If so, it would be nice to quiet this warning too.

@AlbertoGP
Copy link
Author

Looking in lua/src/luaconf.h, LUA_USEMKSTEMP depends on LUA_USE_LINUX, which is set in lua/src/Makefile depending on the value of PLATS.

There it says “CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT” so I guess I’m supposed to set PLAT= linux.

However, setting PLAT=linux there does not have any effect when building from the project root load81/ because the Makefile there asks explicitly for the ansi target:

lua/src/liblua.a:
	-(cd lua && $(MAKE) ansi)

If I change ansi to linux here, the tmpnam warning goes away. It does need libreadline-dev/libreadline-devel installed though.

It still says ar: 'u' modifier ignored since 'D' is the default (see 'U') as before, I guess it is needed for other versions of ar.

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

1 participant