prevector: Suppress two -Wmaybe-uninitialized (gcc) warnings in indirect_ptr(...) #13902

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:ignore-Wmaybe-uninitialized-in-prevector changing 1 files +11 −1
  1. practicalswift commented at 1:26 PM on August 7, 2018: 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));
                                                                  ~~~~~~~^~~~~~~~
    […]
    
  2. prevector: Suppress -Wmaybe-uninitialized (gcc) warning in indirect_ptr(...) 6e523c9296
  3. practicalswift force-pushed on Aug 7, 2018
  4. fanquake added the label Refactoring on Aug 7, 2018
  5. practicalswift commented at 1:49 PM on August 7, 2018: contributor

    Related change from @TheBlueMatt in c73b8be2440e424f304fda22e43240e8b90f9b00.

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

  6. Empact commented at 3:57 PM on August 7, 2018: member

    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.

  7. practicalswift commented at 7:07 AM on August 8, 2018: contributor

    @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 :-)

  8. laanwj commented at 9:15 AM on August 22, 2018: member

    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

  9. practicalswift commented at 7:55 AM on August 23, 2018: contributor

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

  10. Empact commented at 8:12 AM on August 23, 2018: member

    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?

  11. Empact commented at 8:32 AM on August 23, 2018: member

    Possible cause: only the default constructor explicitly initializes _union

  12. Empact cross-referenced this on Aug 23, 2018 from issue Explicitly initialize prevector _union by Empact
  13. Empact commented at 9:25 AM on August 23, 2018: member

    @practicalswift maybe see if #14028 fixes the warning?

  14. practicalswift commented at 5:47 PM on August 23, 2018: contributor

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

  15. practicalswift commented at 9:15 AM on August 24, 2018: contributor

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

  16. practicalswift closed this on Aug 24, 2018

  17. frolosofsky cross-referenced this on May 2, 2019 from issue Fix GCC warnings in prevector.h by initializing class fields by cmihai
  18. practicalswift deleted the branch on Apr 10, 2021
  19. bitcoin locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:55 UTC