Skip to content

Conversation

practicalswift
Copy link
Contributor

Suppress two -Wmaybe-uninitialized warnings in indirect_ptr(...):

[…]
./prevector.h: In function ‘bool IsWitnessStandard(const CTransaction&, const CCoinsViewCache&)’:
./prevector.h:162:79: warning: ‘prevScript.prevector<28, unsigned char>::_union.prevector<28, unsigned char>::direct_or_indirect::<anonymous>.prevector<28, unsigned char>
     ::direct_or_indirect::<unnamed struct>::indirect’ may be used uninitialized in this 
     function [-Wmaybe-uninitialized]

     T* indirect_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.indirect) + pos; }
                                                                        ~~~~~~~^~~~~~~~

[…]
In file included from ./hash.h:11:0,
                 from ./pubkey.h:10,
                 from ./key.h:10,
                 from test/script_p2sh_tests.cpp:7:
./prevector.h: In member function ‘void script_p2sh_tests::sign::test_method()’:
./prevector.h:162:79: warning: ‘sigSave.prevector<28, unsigned char>::_union.prevector<28, unsigned char>::direct_or_indirect::<anonymous>.prevector<28, unsigned char>::direct_or_indirect::<unnamed struct>::indirect’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     T* indirect_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.indirect) + pos; }
                                                                        ~~~~~~~^~~~~~~~
./prevector.h:181:69: warning: ‘sigSave.prevector<28, unsigned char>::_union.prevector<28, unsigned char>::direct_or_indirect::<anonymous>.prevector<28, unsigned char>::direct_or_indirect::<unnamed struct>::indirect’ may be used uninitialized in this function [-Wmaybe-uninitialized]
                 _union.indirect = static_cast<char*>(realloc(_union.indirect, ((size_t)sizeof(T)) * new_capacity));
                                                              ~~~~~~~^~~~~~~~
[…]

@practicalswift practicalswift force-pushed the ignore-Wmaybe-uninitialized-in-prevector branch from 6200d22 to 6e523c9 Compare August 7, 2018 13:27
@practicalswift
Copy link
Contributor Author

Related change from @TheBlueMatt in c73b8be.

Ping @sipa who wrote the original prevector code :-)

@Empact
Copy link
Contributor

Empact commented Aug 7, 2018

What version of gcc are you using? I think this might be related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36750 which was fixed in GCC 5.

@practicalswift
Copy link
Contributor Author

practicalswift commented Aug 8, 2018

@Empact I'm using vanilla gcc 7.3.0 under Ubuntu 18.04.1 LTS:

$ g++ --version
g++ (Ubuntu 7.3.0-16ubuntu3) 7.3.0
Copyright (C) 2017 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.

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
$ dpkg -s g++ | grep -E Ver\|Dep
Version: 4:7.3.0-3ubuntu2
Depends: cpp (>= 4:7.3.0-3ubuntu2), gcc (>= 4:7.3.0-3ubuntu2), g++-7 (>= 7.3.0-12~), gcc-7 (>= 7.3.0-12~)

Nothing fancy – as vanilla as it gets :-)

@laanwj
Copy link
Member

laanwj commented Aug 22, 2018

I strongly dislike this solution,
if this warning points to a real issue, that issue should be solved instead
but let's not riddle the source code with compiler-specific pragmas

@practicalswift
Copy link
Contributor Author

practicalswift commented Aug 23, 2018

@laanwj Is it a real issue? I thought it was a false positive

@Empact
Copy link
Contributor

Empact commented Aug 23, 2018

I'm not a fan either, better to fix, if an issue exists, and take it up with the compiler if it's a false positive. Does the issue exist with GCC 8.2?

@Empact
Copy link
Contributor

Empact commented Aug 23, 2018

Possible cause: only the default constructor explicitly initializes _union

@Empact
Copy link
Contributor

Empact commented Aug 23, 2018

@practicalswift maybe see if #14028 fixes the warning?

@practicalswift
Copy link
Contributor Author

@Empact The fix in #14028 fixes the warning. Thanks!

@practicalswift
Copy link
Contributor Author

Closing this in favor of #14028. Thanks @Empact!

@practicalswift practicalswift deleted the ignore-Wmaybe-uninitialized-in-prevector branch April 10, 2021 19:35
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants