Utils and libraries: Leveldb compile warnings #12562

pull bedri wants to merge 2 commits into bitcoin:master from bedri:leveldbCompileWarnings changing 6 files +1495 −1
  1. bedri commented at 8:42 PM on February 27, 2018: none

    Warning messages:

    leveldb/util/logging.cc: In function ‘bool leveldb::ConsumeDecimalNumber(leveldb::Slice*, uint64_t*)’:
    leveldb/util/logging.cc:58:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
               (v == kMaxUint64/10 && delta > kMaxUint64%10)) {
                                      ~~~~~~^~~~~~~~~~~~~~~
    
    
    
    leveldb/port/port_posix.cc: In function ‘bool leveldb::port::HasAcceleratedCRC32C()’:
    leveldb/port/port_posix.cc:60:15: warning: ‘ecx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
       return (ecx & (1 << 20)) != 0;
              ~~~~~^~~~~~~~~~~~
    
    

    Fixes:

    leveldb/port/port_posix.cc:60:15: warning: ‘ecx’ may be used uninitialized in this function

    Code part:

      unsigned int eax, ebx, ecx, edx;
      ecx = 0;
      __get_cpuid(1, &eax, &ebx, &ecx, &edx);
      return (ecx & (1 << 20)) != 0;
    
    

    Explanation: Simply initiated ecx variable.

    ecx = 0; 
    

    leveldb/util/logging.cc:58:40: warning: comparison between signed and unsigned integer expressions

    Code part:

        if (c >= '0' && c <= '9') {
          ++digits;
          const int delta = (c - '0');
          static const uint64_t kMaxUint64 = ~static_cast<uint64_t>(0);
          if (v > kMaxUint64/10 ||
             (v == kMaxUint64/10 && (uint64_t) delta > kMaxUint64%10)) {
            // Overflow
            return false;
          }
    
    

    Explanation: if statement comparing c >= '0' forces c to be definite positive or zero. 'delta' constant value assignment ( delta = (c - '0') ) and the comparison of it with a modular division also shows that 'delta' is definite positive or zero. So we can make an inline type change from int to uint64_t for 'delta' such that

    (v == kMaxUint64/10 && (uint64_t) delta > kMaxUint64%10)) {
    
  2. fixes "leveldb/port/port_posix.cc:60:15: warning: ‘ecx’ may be used uninitialized in this function" comile warning messages a8b470eac0
  3. Fixes "leveldb/util/logging.cc:58:40: warning: comparison between signed and unsigned integer expressions" compile warning messages 95add95b5c
  4. bedri commented at 8:48 PM on February 27, 2018: none

    Hope I did PR correctly this time. CONTRIBUTING.md kinda confused me since explanation for upstream repository exists there.

  5. sipa commented at 8:50 PM on February 27, 2018: member

    Two comments:

    • This is still in the wrong repository. Changes to LevelDB should go to the https://github.com/bitcoin-core/leveldb repository at least, and ideally through https://github.com/google/leveldb. We regularly pull in new versions from those repositories, but don't make local changes here directly.
    • You seem to have added a number of unrelated files to the repository.
  6. eklitzke commented at 9:12 PM on February 27, 2018: contributor

    I just built upstream LevelDB (at commit 41172a24016bc29fc795ed504737392587f54e3d) and all of these have been fixed there.

  7. bedri commented at 10:11 PM on February 27, 2018: none

    OK. Thank you.

  8. fanquake closed this on Feb 28, 2018

  9. DrahtBot locked this on Sep 8, 2021
Contributors

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-04-14 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me