starwing / luautf8

a utf-8 support module for Lua and LuaJIT.
MIT License
406 stars 67 forks source link

remove GCC '... may be used uninitialized' warnings #3

Closed CheyiLin closed 9 years ago

CheyiLin commented 10 years ago

It's a minor refactoring that reduces GCC warnings, so my users will not be scared when they are upgrading. Hope you would consider the pull request, very appreciated!

starwing commented 10 years ago

okay, I will look into this :)

starwing commented 9 years ago

I have checked the code, now it should be no any warnings in -O3 -Wall -Wextra :)

starwing commented 9 years ago

@CheyiLin

CheyiLin commented 9 years ago

I still got those warnings :sob: Maybe this issue is related to my compiler?

CentOS 6.6 x86_64, gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)

$ gcc -O3 -fPIC -Wall -Wextra -shared -o utf8.so -I$(LUADIR) lutf8lib.c

lutf8lib.c: In function 'Lutf8_widthindex':
lutf8lib.c:604: warning: 'ch' may be used uninitialized in this function
lutf8lib.c: In function 'matchbracketclass':
lutf8lib.c:747: warning: 'ch' may be used uninitialized in this function
lutf8lib.c:755: warning: 'next' may be used uninitialized in this function
lutf8lib.c: In function 'Lutf8_codepoint':
lutf8lib.c:386: warning: 'code' may be used uninitialized in this function
lutf8lib.c: In function 'Lutf8_width':
lutf8lib.c:586: warning: 'ch' may be used uninitialized in this function
lutf8lib.c: In function 'convert':
lutf8lib.c:330: warning: 'ch' may be used uninitialized in this function
lutf8lib.c: In function 'Lutf8_escape':
lutf8lib.c:445: warning: 'ch' may be used uninitialized in this function
lutf8lib.c: In function 'Lutf8_byte':
lutf8lib.c:360: warning: 'ch' may be used uninitialized in this function
lutf8lib.c: In function 'match':
lutf8lib.c:875: warning: 'ch' may be used uninitialized in this function
lutf8lib.c:788: warning: 'ch' may be used uninitialized in this function
lutf8lib.c:788: note: 'ch' was declared here
lutf8lib.c:788: warning: 'begin' may be used uninitialized in this function
lutf8lib.c:788: note: 'begin' was declared here
lutf8lib.c:788: warning: 'end' may be used uninitialized in this function
lutf8lib.c:788: note: 'end' was declared here
lutf8lib.c:696: warning: 'ch' may be used uninitialized in this function
lutf8lib.c:696: note: 'ch' was declared here
lutf8lib.c:696: warning: 'ch' may be used uninitialized in this function
lutf8lib.c:696: note: 'ch' was declared here
lutf8lib.c:773: warning: 'ch' may be used uninitialized in this function
lutf8lib.c:773: note: 'ch' was declared here
lutf8lib.c:773: warning: 'ch' may be used uninitialized in this function
lutf8lib.c:773: note: 'ch' was declared here
lutf8lib.c:773: warning: 'pch' may be used uninitialized in this function
lutf8lib.c:773: note: 'pch' was declared here
lutf8lib.c:773: warning: 'ch' may be used uninitialized in this function
lutf8lib.c:773: note: 'ch' was declared here
lutf8lib.c:773: warning: 'pch' may be used uninitialized in this function
lutf8lib.c:773: note: 'pch' was declared here
lutf8lib.c: In function 'Lutf8_gsub':
lutf8lib.c:1249: warning: 'ch' may be used uninitialized in this function
lutf8lib.c:1166: warning: 'ch' may be used uninitialized in this function
lutf8lib.c:1166: note: 'ch' was declared here
lutf8lib.c: In function 'Lutf8_next':
lutf8lib.c:510: warning: 'ch' may be used uninitialized in this function
lutf8lib.c:510: note: 'ch' was declared here
lutf8lib.c: In function 'Lutf8_charpos':
lutf8lib.c:510: warning: 'ch' may be used uninitialized in this function
lutf8lib.c:510: note: 'ch' was declared here
lutf8lib.c:510: warning: 'ch' may be used uninitialized in this function
lutf8lib.c:510: note: 'ch' was declared here
starwing commented 9 years ago

you use gcc 4.4? that may be too old, I only have gcc 4.8.2 and 4.9.2, all don't have warnings.

CheyiLin commented 9 years ago

Unfortunately in CentOS 6, the default gcc compiler is still 4.4.7. :disappointed: I can install newer gcc packages from unofficial sources (means neither CentOS nor RedHat) but it increase the config complexity and dependencies, which is what I want to avoid.

Could you please consider mergeing this PR again? If yes I would commit the patch later, thanks.

starwing commented 9 years ago

Maybe you can build this library with -w to Inhibit warnings? I mean, not adding these initialize value is good if we really forget to initialize a variable, so add these initialize is not so good.

Or, if you really want it don't have warnings at gcc 4.4, I will try that (I can download a MinGW version and fix it), but I need do it at weekend :(

CheyiLin commented 9 years ago

Or, if you really want it don't have warnings at gcc 4.4, I will try that

That would be great! Please do this when you have some extra time. :smiley: Very appreciated!

starwing commented 9 years ago

I have a CentOS 6.5 server today, and it have gcc 4.4.7, so I tried compile luautf8, but I doesn't seem any warnings :(

this is the log:

sw@10-6-23-155: ~/prebuilt/luautf8 master!
 $ gcc -shared -fPIC -Wall lutf8lib.c -o lua-utf8.so                 [12:58:07]

sw@10-6-23-155: ~/prebuilt/luautf8 master!
 $ gcc -v                                                            [12:58:17]
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
CheyiLin commented 9 years ago

Sorry, I conformed that the warnings are exactly caused by gcc 4.4 optimization flag -O3.

starwing commented 9 years ago

Okay, I have found the bug cause the warnings, you can try the git HEAD. Thank you very much for reporting :)

CheyiLin commented 9 years ago

Tested and no warning!! I never thought that would be a bug before. :sweat_smile: Thanks.