fix util_tests.cpp clang warnings #6241

pull jonasschnelli wants to merge 1 commits into bitcoin:master from jonasschnelli:2015/06/util_test_clang changing 1 files +2 −2
  1. jonasschnelli commented at 3:06 PM on June 5, 2015: contributor

    was introduced with #6121.

    Fixes two warnings:

    test/util_tests.cpp:353:64: warning: integer literal is too large to be represented in a signed integer type, interpreting as unsigned [-Wimplicitly-unsigned-literal]
        BOOST_CHECK(ParseInt64("-9223372036854775808", &n) && n == 9223372036854775808LL);
    
    test/util_tests.cpp:353:61: warning: comparison of integers of different signs: 'int64_t' (aka 'long long') and 'unsigned long long' [-Wsign-compare]
        BOOST_CHECK(ParseInt64("-9223372036854775808", &n) && n == 9223372036854775808LL);
    
  2. laanwj commented at 4:39 PM on June 5, 2015: member

    I don't get it. Why do you need unsigned integer here? If these are truly outside the 64 bit signed integer range, these tests should not be passing. As I understand it, the range of int64_t should be -2^63 to 2^63-1, or .-9223372036854775808 to 9223372036854775807. These are the limits that I'm testing. Am I mistaken?

  3. in src/test/util_tests.cpp:None in 0fd01949ed outdated
     348 | @@ -349,8 +349,8 @@ BOOST_AUTO_TEST_CASE(test_ParseInt64)
     349 |      BOOST_CHECK(ParseInt64("01234", &n) && n == 1234LL); // no octal
     350 |      BOOST_CHECK(ParseInt64("2147483647", &n) && n == 2147483647LL);
     351 |      BOOST_CHECK(ParseInt64("-2147483648", &n) && n == -2147483648LL);
     352 | -    BOOST_CHECK(ParseInt64("9223372036854775807", &n) && n == 9223372036854775807LL);
     353 | -    BOOST_CHECK(ParseInt64("-9223372036854775808", &n) && n == 9223372036854775808LL);
    


    laanwj commented at 4:40 PM on June 5, 2015:

    OH wait! This should be n == -9223372036854775808LL (missed the -). There should be no need to make it unsigned, though.

  4. laanwj added the label Tests on Jun 5, 2015
  5. jonasschnelli force-pushed on Jun 5, 2015
  6. jonasschnelli commented at 6:44 PM on June 5, 2015: contributor

    I really had my brain in "off mode" when i was writing this PR. I just added the same changes clang did warn about. Now i have changed it from 9223372036854775807L to (int64_t)9223372036854775807 which should be the same IMO. Fixed also the - sign in front of the min check (-9223372036854775808).

    Still get a warning: But it looks like that there is a bug in clang, because: (int64_t)-9223372036854775808 -> shows warning (...is too large to be represented in a signed integer type...) (int64_t)-9223372036854775807 -> OK This is definitively wrong somehow.

  7. jonasschnelli force-pushed on Jun 5, 2015
  8. theuni commented at 12:07 AM on June 6, 2015: member

    I believe you need to use (int64_t)-9223372036854775807-1, otherwise it tries to negate 9223372036854775808, which itself doesn't fit to be negated.

    *_MIN are usually defined that way, anyway:

    #   define LLONG_MIN    (-LLONG_MAX - 1LL)
    
  9. laanwj commented at 7:15 AM on June 6, 2015: member

    I believe you need to use (int64_t)-9223372036854775807-1, otherwise it tries to negate 9223372036854775808, which itself doesn't fit to be negated.

    -9223372036854775807LL-1LL, then. I don't think you need the cast.

    So I'm starting to understand. The C compiler itself uses 64 bit integers internally, and it parses the token '9223372036854775808' not -9223372036854775808. The value then overflows while parsing, in the end there's no difference but it likes to warn about it.

    That means there is no way to represent the smallest integer without doing arithmetic, that's kind of stupid. But ok, fine with shutting up this warning, I just don't want another issue about this where it causes a warning in yet another compiler.

  10. fix util_tests.cpp clang warnings
    was introduced with #6121
    c946ebed5e
  11. jonasschnelli force-pushed on Jun 6, 2015
  12. jonasschnelli commented at 8:13 AM on June 6, 2015: contributor

    @theuni Okay. I see and understand this now better. Thanks. Changed PR the follow the arithmetical way.

  13. laanwj commented at 8:18 AM on June 6, 2015: member

    utACK

  14. laanwj commented at 9:30 AM on June 6, 2015: member

    Ok, thanks, it passes travis. Going to merge this. If there is another compiler that starts to complain about that line we're just going to ignore it. We're writing software for users, not to make compilers happy.

  15. laanwj merged this on Jun 6, 2015
  16. laanwj closed this on Jun 6, 2015

  17. laanwj referenced this in commit 55294a9fb6 on Jun 6, 2015
  18. zkbot referenced this in commit a2e69fac97 on Feb 5, 2017
  19. zkbot referenced this in commit 50807c5dc4 on Feb 7, 2017
  20. zkbot referenced this in commit 9a6ebaba36 on Feb 10, 2017
  21. zkbot referenced this in commit a7b8d93656 on Feb 10, 2017
  22. zkbot referenced this in commit e51bd1b556 on Feb 10, 2017
  23. MarcoFalke 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-24 12:15 UTC

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