Skip to contentSkip to conversation

fs/ntfscomp.c:82:11: error: ‘flg’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

DISCUSSION PGNet Dev 4 participants 8 messages Mar 26, 2020 – Mar 31, 2020

lore
Share & tools
lore

PGNet Dev

author
#0 lore raw

building

cd grub
git log | head -n5
commit 552c9fd08122a3036c724ce96dfe68aa2f75705f
Author: Patrick Steinhardt <[email protected]>
Date: Sat Mar 7 17:29:09 2020 +0100

gnulib: Fix build of base64 when compiling with memory debugging

with

	gcc --version
		gcc (SUSE Linux) 10.0.1 20200324 (experimental) [revision 75c24a08d697d6442fe6c26142f0559f803af977]

patched

patch -p1 < /tmp/grub_patches/grub_patches/0001-mdraid1x_linux-Fix-gcc10-error-Werror-array-bounds.patch
patching file grub-core/disk/mdraid1x_linux.c
patch -p1 < /tmp/grub_patches/grub_patches/0002-zfs-Fix-gcc10-error-Werror-zero-length-bounds.patch
patching file grub-core/fs/zfs/zfs.c
patching file include/grub/zfs/zap_leaf.h

from

	https://lists.gnu.org/archive/html/grub-devel/2020-03/msg00222.html

config's ok

unset CC CPP
./bootstrap
./autogen.sh
./configure

build FAILs

	make V=1

		gcc -DHAVE_CONFIG_H -I.  -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub-core/fs/ntfscomp.c\" -I. -I. -I. -I. -I./include -I./include -I./grub-core/lib/libgcrypt-grub/src/  -I./grub-core/lib/minilzo -I./grub-core/lib/xzembed -I./grub-core/lib/zstd -DMINILZO_HAVE_CONFIG_H -O3 -Wall -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fmessage-length=0 -grecord-gcc-switches -march=native -mtune=native -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64 -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -Wcast-align  -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -Werror  -fno-builtin -Wno-undef -O3 -Wall -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fmessage-length=0 -grecord-gcc-switches -march=native -mtune=native -MT grub-core/fs/libgrubmods_a-ntfscomp.o -MD -MP -MF grub-core/fs/.deps-util/libgrubmods_a-ntfscomp.Tpo -c -o grub-core/fs/libgrubmods_a-ntfscomp.o `test -f 'grub-core/fs/ntfscomp.c' || echo './'`grub-core/fs/ntfscomp.c
		grub-core/fs/ntfscomp.c: In function ‘read_block’:
		grub-core/fs/ntfscomp.c:82:11: error: ‘flg’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
		   82 |       if (flg & 0x8000)
		      |           ^~~
		grub-core/fs/ntfscomp.c:74:17: note: ‘flg’ was declared here
		   74 |   grub_uint16_t flg, cnt;
		      |                 ^~~
		cc1: all warnings being treated as errors
		make[2]: *** [Makefile:7647: grub-core/fs/libgrubmods_a-ntfscomp.o] Error 1
		make[2]: Leaving directory '/usr/local/src/grub'
		make[1]: *** [Makefile:11920: all-recursive] Error 1
		make[1]: Leaving directory '/usr/local/src/grub'
		make: *** [Makefile:3772: all] Error 2
#1 lore raw

Dear PGNet Dev,

Thank you for your report.

Am 26.03.20 um 04:50 schrieb PGNet Dev:

Quoted 36 lines

building

cd grub
git log | head -n5
commit 552c9fd08122a3036c724ce96dfe68aa2f75705f
Author: Patrick Steinhardt <[email protected]>
Date: Sat Mar 7 17:29:09 2020 +0100

gnulib: Fix build of base64 when compiling with memory debugging

with

	gcc --version
		gcc (SUSE Linux) 10.0.1 20200324 (experimental) [revision 75c24a08d697d6442fe6c26142f0559f803af977]

patched

patch -p1 < /tmp/grub_patches/grub_patches/0001-mdraid1x_linux-Fix-gcc10-error-Werror-array-bounds.patch
patching file grub-core/disk/mdraid1x_linux.c
patch -p1 < /tmp/grub_patches/grub_patches/0002-zfs-Fix-gcc10-error-Werror-zero-length-bounds.patch
patching file grub-core/fs/zfs/zfs.c
patching file include/grub/zfs/zap_leaf.h

from

	https://lists.gnu.org/archive/html/grub-devel/2020-03/msg00222.html

config's ok

unset CC CPP
./bootstrap
./autogen.sh
./configure

build FAILs

Quoted 16 lines
	make V=1

		gcc -DHAVE_CONFIG_H -I.  -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub-core/fs/ntfscomp.c\" -I. -I. -I. -I. -I./include -I./include -I./grub-core/lib/libgcrypt-grub/src/  -I./grub-core/lib/minilzo -I./grub-core/lib/xzembed -I./grub-core/lib/zstd -DMINILZO_HAVE_CONFIG_H -O3 -Wall -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fmessage-length=0 -grecord-gcc-switches -march=native -mtune=native -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64 -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -Wcast-align  -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -Werror  -fno-builtin -Wno-undef -O3 -Wall -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fmessage-length=0 -grecord-gcc-switches -march=native -mtune=native -MT grub-core/fs/libgrubmods_a-ntfscomp.o -MD -MP -MF grub-core/fs/.deps-util/libgrubmods_a-ntfscomp.Tpo -c -o grub-core/fs/libgrubmods_a-ntfscomp.o `test -f 'grub-core/fs/ntfscomp.c' || echo './'`grub-core/fs/ntfscomp.c
		grub-core/fs/ntfscomp.c: In function ‘read_block’:
		grub-core/fs/ntfscomp.c:82:11: error: ‘flg’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
		   82 |       if (flg & 0x8000)
		      |           ^~~
		grub-core/fs/ntfscomp.c:74:17: note: ‘flg’ was declared here
		   74 |   grub_uint16_t flg, cnt;
		      |                 ^~~
		cc1: all warnings being treated as errors
		make[2]: *** [Makefile:7647: grub-core/fs/libgrubmods_a-ntfscomp.o] Error 1
		make[2]: Leaving directory '/usr/local/src/grub'
		make[1]: *** [Makefile:11920: all-recursive] Error 1
		make[1]: Leaving directory '/usr/local/src/grub'
		make: *** [Makefile:3772: all] Error 2

I am unable to reproduce this with

    $ gcc --version
    gcc (Debian 10-20200324-1) 10.0.1 20200324 (experimental) [master 
revision 596c90d3559:023579257f5:906b3eb9df6c577d3f6e9c3ea5c9d7e4d1e90536]

Here is the code in question:

``
static grub_err_t
decomp_get16 (struct grub_ntfs_comp *cc, grub_uint16_t * res) {
grub_uint8_t c1 = 0, c2 = 0;

if ((decomp_getch (cc, &c1)) || (decomp_getch (cc, &c2)))

    return grub_errno;

*res = ((grub_uint16_t) c2) * 256 + ((grub_uint16_t) c1); return 0;
}

[…]
grub_uint16_t flg, cnt;

  if (decomp_get16 (cc, &flg))
    return grub_errno;
  cnt = (flg & 0xFFF) + 1;

if (dest)

    {
      if (flg & 0x8000)

[…]
```

In the code, the if (decomp_get16 (cc, &flg)) ensures, that flg is initialized, doesn’t it?

Why is it complaining complaining in line 82 and not 78, where flg is already accessed?

Kind regards,

Paul

#2 lore raw
Quoted 60 lines · Paul Menzel

Dear PGNet Dev,

Thank you for your report.

Am 26.03.20 um 04:50 schrieb PGNet Dev:

Quoted 36 lines

building

cd grub
git log | head -n5
commit 552c9fd08122a3036c724ce96dfe68aa2f75705f
Author: Patrick Steinhardt <[email protected]>
Date: Sat Mar 7 17:29:09 2020 +0100

gnulib: Fix build of base64 when compiling with memory debugging

with

	gcc --version
		gcc (SUSE Linux) 10.0.1 20200324 (experimental) [revision 75c24a08d697d6442fe6c26142f0559f803af977]

patched

patch -p1 < /tmp/grub_patches/grub_patches/0001-mdraid1x_linux-Fix-gcc10-error-Werror-array-bounds.patch
patching file grub-core/disk/mdraid1x_linux.c
patch -p1 < /tmp/grub_patches/grub_patches/0002-zfs-Fix-gcc10-error-Werror-zero-length-bounds.patch
patching file grub-core/fs/zfs/zfs.c
patching file include/grub/zfs/zap_leaf.h

from

	https://lists.gnu.org/archive/html/grub-devel/2020-03/msg00222.html

config's ok

unset CC CPP
./bootstrap
./autogen.sh
./configure

build FAILs

Quoted 16 lines
	make V=1

		gcc -DHAVE_CONFIG_H -I.  -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub-core/fs/ntfscomp.c\" -I. -I. -I. -I. -I./include -I./include -I./grub-core/lib/libgcrypt-grub/src/  -I./grub-core/lib/minilzo -I./grub-core/lib/xzembed -I./grub-core/lib/zstd -DMINILZO_HAVE_CONFIG_H -O3 -Wall -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fmessage-length=0 -grecord-gcc-switches -march=native -mtune=native -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64 -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -Wcast-align  -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -Werror  -fno-builtin -Wno-undef -O3 -Wall -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fmessage-length=0 -grecord-gcc-switches -march=native -mtune=native -MT grub-core/fs/libgrubmods_a-ntfscomp.o -MD -MP -MF grub-core/fs/.deps-util/libgrubmods_a-ntfscomp.Tpo -c -o grub-core/fs/libgrubmods_a-ntfscomp.o `test -f 'grub-core/fs/ntfscomp.c' || echo './'`grub-core/fs/ntfscomp.c
		grub-core/fs/ntfscomp.c: In function ‘read_block’:
		grub-core/fs/ntfscomp.c:82:11: error: ‘flg’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
		   82 |       if (flg & 0x8000)
		      |           ^~~
		grub-core/fs/ntfscomp.c:74:17: note: ‘flg’ was declared here
		   74 |   grub_uint16_t flg, cnt;
		      |                 ^~~
		cc1: all warnings being treated as errors
		make[2]: *** [Makefile:7647: grub-core/fs/libgrubmods_a-ntfscomp.o] Error 1
		make[2]: Leaving directory '/usr/local/src/grub'
		make[1]: *** [Makefile:11920: all-recursive] Error 1
		make[1]: Leaving directory '/usr/local/src/grub'
		make: *** [Makefile:3772: all] Error 2
Quoted 5 lines

I am unable to reproduce this with

    $ gcc --version
    gcc (Debian 10-20200324-1) 10.0.1 20200324 (experimental) [master
revision 596c90d3559:023579257f5:906b3eb9df6c577d3f6e9c3ea5c9d7e4d1e90536]

Looking into build log, the build option seems to have been overridden with CFLAGS settings like this.

CFLAGS="-O3 -Wall -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fmessage-length=0 -grecord-gcc-switches -march=native -mtune=native"

I'm not sure if -O3 is considered as supported since that will result in larger binaries we are striving to reduce all the time. Also the optimization it brings would require careful review if we don't enable it by default.

In addition, -fstack-protector-strong breaks the build even harder with a lot of __stack_chk_fail undefined symbol in the modules.

If going with default build option, I also don't have this compliation error.

Quoted 25 lines

Here is the code in question:

``
static grub_err_t
decomp_get16 (struct grub_ntfs_comp *cc, grub_uint16_t * res) {
grub_uint8_t c1 = 0, c2 = 0;

if ((decomp_getch (cc, &c1)) || (decomp_getch (cc, &c2)))

    return grub_errno;

*res = ((grub_uint16_t) c2) * 256 + ((grub_uint16_t) c1); return 0;
}

[…]
grub_uint16_t flg, cnt;

  if (decomp_get16 (cc, &flg))
    return grub_errno;
  cnt = (flg & 0xFFF) + 1;

if (dest)

    {
      if (flg & 0x8000)
Quoted 8 lines

[…]
```

In the code, the if (decomp_get16 (cc, &flg)) ensures, that flg is initialized, doesn’t it?

Why is it complaining complaining in line 82 and not 78, where flg is already accessed?

The code also looks sanity to me. It certainly has things to do with the -O3 optimization, but I couldn't tell more beyond that fact either. :(

Regards,
Michael

Quoted 9 lines

Kind regards,

Paul
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

author
#3 lore raw
Quoted 1 line · Paul Menzel

I am unable to reproduce this with

1st sanity re-check:

I _am_ able to reproduce this consistently, with same error.

I've tested now on multiple machines; not identical, but all similarly opensuse + GCC10 dev envs ...

Quoted 1 line

Here is the code in question:

snip

Quoted 1 line

Why is it complaining complaining in line 82 and not 78, where flg is already accessed?

Quoted 12 lines · Michael Chang

Looking into build log, the build option seems to have been overridden with CFLAGS settings like this.

CFLAGS="-O3 -Wall -fstack-protector-strong -funwind-tables

(quoted diff) +0 -2
-fasynchronous-unwind-tables -fmessage-length=0 -grecord-gcc-switches
-march=native -mtune=native"

I'm not sure if -O3 is considered as supported since that will result in larger binaries we are striving to reduce all the time. Also the optimization it brings would require careful review if we don't enable it by default.

Quoted 5 lines

In addition, -fstack-protector-strong breaks the build even harder with a lot of __stack_chk_fail undefined symbol in the modules.

If going with default build option, I also don't have this compliation error.

indeed.

building with

unset CC CPP
+ unset LD CFLAGS CPPFLAGS CXXFLAGS

	./bootstrap
	./autogen.sh

	./configure \
	--prefix=/usr/local/grub-build-test

	make V=1

completes without error, and installs,

	/usr/local/grub-build-test/bin/grub-mkrescue --version
		/usr/local/grub-build-test/bin/grub-mkrescue (GRUB) 2.05

which I can certainly manage easily enough for local build.

Quoted 1 line

If going with default build option

_is_ a 'clear' env expected/recommended/required for a grub2 build? if so, does this need to be handled at config time?

in either case, this

Quoted 1 line

Why is it complaining complaining in line 82 and not 78, where flg is already accessed?

doesn't make sense to me; code looks straightforward enough. the -03 optimization sounds a good 1st guess.

also,
Michael, fyi, I _think_ this^ started for me with linked GCC10 builds of grub2 on opensuse OBS ... where, iirc, the builds 1st failed, and I started testing locally.

#4 lore raw
Quoted 65 lines · PGNet Dev
Quoted 1 line · Paul Menzel

I am unable to reproduce this with

1st sanity re-check:

I _am_ able to reproduce this consistently, with same error.

I've tested now on multiple machines; not identical, but all similarly opensuse + GCC10 dev envs ...

Quoted 1 line

Here is the code in question:

snip

Quoted 1 line

Why is it complaining complaining in line 82 and not 78, where flg is already accessed?

Quoted 12 lines · Michael Chang

Looking into build log, the build option seems to have been overridden with CFLAGS settings like this.

CFLAGS="-O3 -Wall -fstack-protector-strong -funwind-tables

(quoted diff) +0 -2
-fasynchronous-unwind-tables -fmessage-length=0 -grecord-gcc-switches
-march=native -mtune=native"

I'm not sure if -O3 is considered as supported since that will result in larger binaries we are striving to reduce all the time. Also the optimization it brings would require careful review if we don't enable it by default.

Quoted 5 lines

In addition, -fstack-protector-strong breaks the build even harder with a lot of __stack_chk_fail undefined symbol in the modules.

If going with default build option, I also don't have this compliation error.

indeed.

building with

unset CC CPP

(quoted diff) +1 -0
+	unset LD CFLAGS CPPFLAGS CXXFLAGS
	./bootstrap
	./autogen.sh

	./configure \
	--prefix=/usr/local/grub-build-test

	make V=1

completes without error, and installs,

	/usr/local/grub-build-test/bin/grub-mkrescue --version
		/usr/local/grub-build-test/bin/grub-mkrescue (GRUB) 2.05
Quoted 5 lines

which I can certainly manage easily enough for local build.

Quoted 1 line

If going with default build option

_is_ a 'clear' env expected/recommended/required for a grub2 build?

You control your own build environment. So, if you add options which are not supported by the GRUB then there is pretty good chance that the build or generated output will fall apart at some point. However, if you think a given compiler option should be supported by the GRUB or even used by default please provide a patch with good explanation why we should take it.

Quoted 1 line

if so, does this need to be handled at config time?

I am not sure what do you mean by that.

Daniel

author
#5 lore raw
Quoted 8 lines · Daniel Kiper
Quoted 1 line

_is_ a 'clear' env expected/recommended/required for a grub2 build?

You control your own build environment. So, if you add options which are not supported by the GRUB then there is pretty good chance that the build or generated output will fall apart at some point. However, if you think a given compiler option should be supported by the GRUB or even used by default please provide a patch with good explanation why we should take it.

sure.

builds using opensuse buildservice online are currently failing using 'default' build env.

atm, that appears to be just to due to the patches, discussed here, not yet landing in release used.

i can't yet say what, if anything, of the default _flags_ in use cause a problem -- need to check again if optimization, as causing a problem here, is among them.

Quoted 3 lines
Quoted 1 line

if so, does this need to be handled at config time?

I am not sure what do you mean by that.

just a simple check at 'configure' ... e.g. if optimization is set, raise an error.

thx

#6 lore raw
Quoted 10 lines · PGNet Dev
Quoted 8 lines · Daniel Kiper
Quoted 1 line

_is_ a 'clear' env expected/recommended/required for a grub2 build?

You control your own build environment. So, if you add options which are not supported by the GRUB then there is pretty good chance that the build or generated output will fall apart at some point. However, if you think a given compiler option should be supported by the GRUB or even used by default please provide a patch with good explanation why we should take it.

Quoted 3 lines

sure.

builds using opensuse buildservice online are currently failing using 'default' build env.

I'm using openSUSE build serive too and (with the package maintainer's hats on) I am sure we didn't use those build options/flags you were testing here as default. Neither I could tell where your build options came from.

Quoted 1 line

atm, that appears to be just to due to the patches, discussed here, not yet landing in release used.

No. I don't think so. Simply you should go check your build options, not the patch here.

Regards,
Michael

Quoted 11 lines

i can't yet say what, if anything, of the default _flags_ in use cause a problem -- need to check again if optimization, as causing a problem here, is among them.

Quoted 3 lines
Quoted 1 line

if so, does this need to be handled at config time?

I am not sure what do you mean by that.

just a simple check at 'configure' ... e.g. if optimization is set, raise an error.

thx

#7 lore raw
In reply to PGNet Dev
Quoted 10 lines · PGNet Dev
Quoted 8 lines · Daniel Kiper
Quoted 1 line

_is_ a 'clear' env expected/recommended/required for a grub2 build?

You control your own build environment. So, if you add options which are not supported by the GRUB then there is pretty good chance that the build or generated output will fall apart at some point. However, if you think a given compiler option should be supported by the GRUB or even used by default please provide a patch with good explanation why we should take it.

Quoted 5 lines

sure.

builds using opensuse buildservice online are currently failing using 'default' build env.

atm, that appears to be just to due to the patches, discussed here, not yet landing in release used.

Patches are in right now. Please test...

Daniel