Stephane-D / SGDK

SGDK - A free and open development kit for the Sega Mega Drive
https://www.patreon.com/SGDK
MIT License
1.73k stars 186 forks source link

Varargs warning on sprintf #133

Closed jackbonaguro closed 4 years ago

jackbonaguro commented 5 years ago

On Windows 10 64-bit

make a new project with only one file - main.c:

#include <genesis.h>

int main() {
    char * text = "";
    sprintf(text, "Hello World");
    return 0;
}

/*
Now run:
    %GDK_WIN%/bin/make -f %GDK_WIN%/makefile.gen
*/

And run the command %GDK_WIN%/bin/make -f %GDK_WIN%/makefile.gen from the project root.

I am getting the following warning:

C:/sgdk/src/string.c: In function 'sprintf.constprop':
C:/sgdk/src/string.c:648:5: warning: second parameter of 'va_start' not last named argument [-Wvarargs]
     va_start(args, fmt);
     ^

I'm pretty sure this warning is incorrect.

jackbonaguro commented 5 years ago

Seems like a compiler issue, but I don't know what version of gcc is used.

Stephane-D commented 5 years ago

Weird error message, I think you have another GCC installation conflicting, you can try to type "gcc --version" without any path on the command line to see which one is used by default :)

jackbonaguro commented 5 years ago

Got this output:

gcc (GCC) 6.3.0
Copyright (C) 2016 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.

where gcc yields C:\sgdk\bin\gcc.exe which gcc yields /cygdrive/c/sgdk/bin/gcc, since I have cygwin.

However this shouldn't be an issue, as I am never using my default gcc for SGDK. I'm only using makefile.gen, which explicitly sets CC= $(BIN)/gcc, and never explicity calls gcc otherwise.

Stephane-D commented 5 years ago

indeed that was what i though after posting my reply, sometime just the different make can do weird behaviors. but as i can't reproduce it, i can't really understand why you obtain this. But as this is a warning, i guess it doesn't bring much troubles for compilation ?

matteusbeus commented 5 years ago

I've had this problem myself in the past! usually due to having the wrong SGDK version installed or not rebuilding the library after an SGDK version upgrade. Have a good clean out, remove temp builds, etc

jaytagdamian commented 4 years ago

I have exactly the same issue with SGDK 1.51, even when having no other gcc version installed on my workstation.

If I comment out this line of code: sprintf(str_player_score,"%d",player_score);

The error disappears.

The version of string.c at a522d56 has the same issue.

Stephane-D commented 4 years ago

Too bad, i was optimist about the last changes to resolve the issues. Did you rebuild the library in between as i didn't pushed last lib binaries after the change ?

jaytagdamian commented 4 years ago

Resolved.

Before:

PS C:\Users\Damian McMillan\dev\megadrive\14_tiles> d:/sgdk/bin/make -f d:\sgdk\makefile.gen
D:/sgdk/bin/mkdir -p src/boot

D:/sgdk/bin/mkdir -p out
D:/sgdk/bin/mkdir -p out/src
D:/sgdk/bin/mkdir -p out/res
echo "out/res/sprites.o out/res/tiles.o out/src/main.o" > out/cmd_
D:/sgdk/bin/gcc -BD:/sgdk/bin -n -T D:/sgdk/md.ld -nostdlib out/sega.o @out/cmd_ D:/sgdk/lib/libmd.a D:/sgdk/lib/libgc
c.a -o out/rom.out
D:/sgdk/src/string.c: In function 'sprintf.constprop':
D:/sgdk/src/string.c:640:5: warning: second parameter of 'va_start' not last named argument [-Wvarargs]
     va_start(args, fmt);
     ^
D:/sgdk/bin/rm out/cmd_
D:/sgdk/bin/objcopy -O binary out/rom.out out/rom.bin
D:/sgdk/bin/sizebnd out/rom.bin -sizealign 131072
D:/sgdk/bin/nm --plugin=liblto_plugin-0.dll -n out/rom.out > out/symbol.txt

After:

PS C:\Users\Damian McMillan\dev\megadrive\14_tiles> d:/sgdk/bin/make -f d:\sgdk\makefile.gen
D:/sgdk/bin/mkdir -p src/boot
D:/sgdk/bin/mkdir -p out
D:/sgdk/bin/mkdir -p out/src
D:/sgdk/bin/mkdir -p out/res
echo "out/res/sprites.o out/res/tiles.o out/src/main.o" > out/cmd_
D:/sgdk/bin/gcc -BD:/sgdk/bin -n -T D:/sgdk/md.ld -nostdlib out/sega.o @out/cmd_ D:/sgdk/lib/libmd.a D:/sgdk/lib/libgc
c.a -o out/rom.out
D:/sgdk/bin/rm out/cmd_
D:/sgdk/bin/objcopy -O binary out/rom.out out/rom.bin
D:/sgdk/bin/sizebnd out/rom.bin -sizealign 131072
D:/sgdk/bin/nm --plugin=liblto_plugin-0.dll -n out/rom.out > out/symbol.txt

I had previously downloaded https://github.com/Stephane-D/SGDK/releases/download/v1.51/sgdk151.7z and followed the instructions at: https://github.com/Stephane-D/SGDK/wiki/SGDK-Installation

This time, to ensure I was using the latest configuration and libraries, I cloned the repository, and then ran build_lib.bat.

Now, when I d:/sgdk/bin/make -f d:\sgdk\makefile.gen the error is gone.

As a test, I tried running build_lib.bat from the existing directory, but the error persists.

Solution:

Stephane-D commented 4 years ago

Yeah the fix is only available through direct repository content (not in SGDK 1.51) and it really requires rebuilding the library, still i don't understand why the build_lib.bat batch didn't made it ! At least it seems the bug is resolved :)