fix -Wformat warnings all over the source #1885

pull Diapolo wants to merge 1 commits into bitcoin:master from Diapolo:fix_Wformat changing 5 files +5 −5
  1. Diapolo commented at 10:14 AM on September 29, 2012: none

    #1807 revealed some things that need fixing and I tried to do this. This pull currently does not re-enaable the -Wformat warnings, as I was not sure, if I perhaps missed some warnings.

  2. in src/main.h:None in 0635602a1b outdated
    1128 | @@ -1129,7 +1129,7 @@ class CBlockIndex
    1129 |      std::string ToString() const
    1130 |      {
    1131 |          return strprintf("CBlockIndex(pprev=%08x, pnext=%08x, nFile=%u, nBlockPos=%-6u nHeight=%d, merkle=%s, hashBlock=%s)",
    1132 | -            pprev, pnext, nFile, nBlockPos, nHeight,
    1133 | +            (unsigned int)pprev, (unsigned int)pnext, nFile, nBlockPos, nHeight,
    


    laanwj commented at 12:45 PM on September 29, 2012:

    No need for casts --I've added the PRIszx / PRIszu / PRIszd macros in util.h for for these.


    Diapolo commented at 1:43 PM on September 29, 2012:

    I didn't know that, will update tomorrow as I'm not at home now.


    Diapolo commented at 8:49 AM on September 30, 2012:

    @laanwj

    <pre> return strprintf("CBlockIndex(pprev="PRIszx", pnext="PRIszx", nFile=%u, nBlockPos=%-6u nHeight=%d, merkle=%s, hashBlock=%s)", pprev, pnext, nFile, nBlockPos, nHeight, hashMerkleRoot.ToString().substr(0,10).c_str(), GetBlockHash().ToString().substr(0,20).c_str()); </pre>

    This does not work as it should, see: Warning:format '%Ix' expects argument of type 'size_t', but argument 3 has type 'CBlockIndex*' [-Wformat]

    I'm rather sure this won't work without a cast then?

    Edit: And I find it somewhat weird, that #define PRIszx "%Ix" includes % whereas #define PRI64d "I64d" does not.


    laanwj commented at 9:19 AM on September 30, 2012:

    For a pointer you need %p


    Diapolo commented at 9:26 AM on September 30, 2012:

    Sorry, you need to help me, how does it need to look now, I'm really confused. Can you post the correct formatting code please.


    laanwj commented at 9:38 AM on September 30, 2012:
    • Pointers (such as CBlockIndex*): use %p

    • (s)size_t: use %"PRIsz*"

    • (u)int64_t: use %"PRI64*"

    • unsigned int: use %u

    • signed int: use %d or %i ...

      #define PRIszx "%Ix" includes % whereas #define PRI64d "I64d" does not.

    True. Feel free to remove the %, I added those macros in a hurry just to demonstrate it, but it would be closer to the standard that PRI64x sets by removing it.


    Diapolo commented at 9:54 AM on September 30, 2012:

    Thanks, I was really unsure about %p as I never used that before. Pull is now updated!

  3. fix -Wformat warnings all over the source 3070a6e9d9
  4. Diapolo commented at 10:00 AM on September 30, 2012: none

    Can another dev comment, if there are open warnings left that need fixing. My compiler is not giving me anymore warnings.

  5. laanwj commented at 10:56 AM on September 30, 2012: member

    I think you get this few warnings because you're building on 32 bit?

  6. laanwj commented at 12:02 PM on September 30, 2012: member

    I'm going to have a shot at fixing the others

  7. laanwj commented at 12:49 PM on September 30, 2012: member

    See #1892

  8. laanwj closed this on Sep 30, 2012

  9. BitcoinPullTester commented at 2:57 PM on September 30, 2012: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/0635602a1bb977d53210cad17c2af6121f0a054c for binaries and test log.

  10. KolbyML referenced this in commit 40278cb688 on Dec 5, 2020
  11. DrahtBot locked this on Sep 8, 2021

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-13 18:16 UTC

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