Opened 9 months ago
Last modified 6 months ago
#69384 assigned defect
gklib @20230327: error: 'lnlen' may be used uninitialized in this function
Reported by: | rmottola (Riccardo) | Owned by: | catap (Kirill A. Korinsky) |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | ports | Version: | |
Keywords: | tiger leopard snowleopard | Cc: | |
Port: | gklib |
Description
I suppose it is not a specific PPC issue, but a fact that GCC is being used instead of clang.
CMakeFiles/GKlib.dir/itemsets.c.o.d -o CMakeFiles/GKlib.dir/itemsets.c.o -c /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_math_gklib/gklib/work/GKlib-8bd6bad750b2b0d90800c632cf18e8ee93ad72d7/itemsets.c /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_math_gklib/gklib/work/GKlib-8bd6bad750b2b0d90800c632cf18e8ee93ad72d7/io.c: In function 'gk_readfile': /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_math_gklib/gklib/work/GKlib-8bd6bad750b2b0d90800c632cf18e8ee93ad72d7/io.c:113:24: error: 'lnlen' may be used uninitialized in this function [-Werror=maybe-uninitialized] if (*lineptr == NULL || *n == 0) { ~~~~~~~~~~~~~~~~~^~~~~~~~~~
Change History (5)
comment:1 Changed 9 months ago by rmottola (Riccardo)
comment:2 Changed 9 months ago by jmroot (Joshua Root)
Owner: | set to catap |
---|---|
Status: | new → assigned |
I'm not sure if it works to add something like -Wno-error
without specifying a warning class. You might have to patch the CMakeLists.txt to not add -Werror
in the first place. Of course if the variable really can be used uninitialized, that should be reported upstream.
comment:3 Changed 6 months ago by rmottola (Riccardo)
I have this error too. Compilation is being done with gcc7
/opt/local/bin/gcc-mp-7 -DGKlib_EXPORTS -I/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_math_gklib/gklib/work/GKlib-8bd6bad750b2b0d90800c632cf18e8ee93ad72d7/. -I/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_math_gklib/gklib/work/GKlib-8bd6bad750b2b0d90800c632cf18e8ee93ad72d7/test -pipe -Os -DNDEBUG -I/opt/local/include -DLINUX -D_FILE_OFFSET_BITS=64 -std=c99 -fno-strict-aliasing -mtune=native -fPIC -Werror -Wall -pedantic -Wno-unused-function -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unknown-pragmas -Wno-unused-label -DNO_X86=ON -DNDEBUG -DNDEBUG2 -DHAVE_EXECINFO_H -O3 -arch ppc -mmacosx-version-min=10.5 -fPIC -MD -MT CMakeFiles/GKlib.dir/io.c.o -MF CMakeFiles/GKlib.dir/io.c.o.d -o CMakeFiles/GKlib.dir/io.c.o -c /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_math_gklib/gklib/work/GKlib-8bd6bad750b2b0d90800c632cf18e8ee93ad72d7/io.c /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_math_gklib/gklib/work/GKlib-8bd6bad750b2b0d90800c632cf18e8ee93ad72d7/io.c: In function 'gk_readfile': /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_math_gklib/gklib/work/GKlib-8bd6bad750b2b0d90800c632cf18e8ee93ad72d7/io.c:113:24: error: 'lnlen' may be used uninitialized in this function [-Werror=maybe-uninitialized] if (*lineptr == NULL || *n == 0) {
I doubt this is a PPC only, but more a compiler issue which spits out a warning. Maybe on intel we usually have a different gcc or clang version.
Should maybe warning=errors should be removed or specific initialization warnings suppressed?
comment:4 Changed 6 months ago by rmottola (Riccardo)
Out of curiosity I tried using gcc 4.8 (only other available MP compiler there)
gcc-mp-4.8: error: unrecognized command line option '-arch'
comment:5 Changed 6 months ago by ryandesign (Ryan Carsten Schmidt)
Keywords: | tiger snowleopard added; gcc removed |
---|---|
Summary: | gklib fails on 10.5 PPC → gklib @20230327: error: 'lnlen' may be used uninitialized in this function |
Please attach the main.log file.
I am not able to reproduce the problem on macOS 12 building using Xcode clang or MacPorts gcc 13. I can't test gcc 7 because it's too old for this OS.
Replying to rmottola:
io.c: In function 'gk_readfile': io.c:113:24: error: 'lnlen' may be used uninitialized in this function [-Werror=maybe-uninitialized] if (*lineptr == NULL || *n == 0) { ~~~~~~~~~~~~~~~~~^~~~~~~~~~
gk_readfile
uses lnlen
only once, at the end of this chunk:
https://github.com/KarypisLab/GKlib/blob/8bd6bad750b2b0d90800c632cf18e8ee93ad72d7/io.c#L147-L159
char **gk_readfile(char *fname, size_t *r_nlines) { size_t lnlen, nlines=0; char *line=NULL, **lines=NULL; FILE *fpin; gk_getfilestats(fname, &nlines, NULL, NULL, NULL); if (nlines > 0) { lines = (char **)gk_malloc(nlines*sizeof(char *), "gk_readfile: lines"); fpin = gk_fopen(fname, "r", "gk_readfile"); nlines = 0; while (gk_getline(&line, &lnlen, fpin) != -1) {
As we see at the top of the function, at this point line
is a NULL
pointer and lnlen
is uninitialized.
gk_getline
in turn does this:
https://github.com/KarypisLab/GKlib/blob/8bd6bad750b2b0d90800c632cf18e8ee93ad72d7/io.c#L101C1-L113
ssize_t gk_getline(char **lineptr, size_t *n, FILE *stream) { #ifdef HAVE_GETLINE return getline(lineptr, n, stream); #else size_t i; int ch; if (feof(stream)) return -1; /* Initial memory allocation if *lineptr is NULL */ if (*lineptr == NULL || *n == 0) {
The way I read this, in this call, *lineptr
(aka line
) is NULL
, so the second part of the condition checking if *n
(aka lnlen
which is uninitialized) is 0
is not evaluated, so I don't think the variable is being used uninitialized. You could still report the problem to the developers; it would be simple to just initialize the variable anyway.
HAVE_GETLINE
is true on Mac OS X 10.7 or later, so this problem only affects Mac OS X 10.6 and earlier, which is probably why not more people have reported it.
I tried removing these lines from GKlibSystem.cmake (because I could find no way to override this result on the command line):
check_function_exists(getline HAVE_GETLINE) if(HAVE_GETLINE) set(GKlib_COPTIONS "${GKlib_COPTIONS} -DHAVE_GETLINE") endif(HAVE_GETLINE)
Even so, I did not see a build error on macOS 12 with Xcode clang or MacPorts gcc 13. Maybe this warning was improved in later GCC versions to be more accurate.
The build system sets -Werror
only when the compiler is GCC. I submitted a PR to stop doing that:
what is the best way to reduce warnings in the portfile? Maybe this is a false flag-