check before operator #13290

issue fbthrift opened this issue on May 21, 2018
  1. fbthrift commented at 5:49 AM on May 21, 2018: none

    <!-- This issue tracker is only for technical issues related to Bitcoin Core. General bitcoin questions and/or support requests are best directed to the Bitcoin StackExchange at https://bitcoin.stackexchange.com. For reporting security issues, please read instructions at https://bitcoincore.org/en/contact/. If the node is "stuck" during sync or giving "block checksum mismatch" errors, please ensure your hardware is stable by running memtest and observe CPU temperature with a load-test tool such as linpack before creating an issue! -->

    <!-- Describe the issue -->

    version: 0.16.0 source: /src/arith_uint256.cpp line 179 : if (pn[pos] & 1 << nbits)

    when ( pn[pos] & 1) =1 and nbits = 31, can result in overflow

    <!--- What behavior did you expect? -->

    <!--- What was the actual behavior (provide screenshots if the issue is GUI-related)? -->

    <!--- How reliably can you reproduce the issue, what are the steps to do so? -->

    <!-- What version of Bitcoin Core are you using, where did you get it (website, self-compiled, etc)? -->

    <!-- What type of machine are you observing the error on (OS/CPU and disk type)? -->

    <!-- Any extra information that might be useful in the debugging process. -->

    <!--- This is normally the contents of a `debug.log` or `config.log` file. Raw text or a link to a pastebin type site are preferred. -->

  2. ken2812221 commented at 5:59 AM on May 21, 2018: contributor

    Why?

  3. fbthrift commented at 6:15 AM on May 21, 2018: none

    the operation '<<' on signed integer cam result in overlow when the left operand's value is '1' and the right operand's(nbits) value is '31'

  4. Empact commented at 8:09 AM on May 21, 2018: member

    This is unsigned integer math, as indicated in the class and file names.

  5. sipa commented at 5:02 PM on May 21, 2018: member

    @Empact No, this is in the internal implementation of uint256; the type of pn[pos] is uint32_t. @wudigithub1 The expression pn[pos] & 1 is uint32_t, which is unsigned so shifting up by 31 bits is fine.

  6. MarcoFalke commented at 5:24 PM on May 21, 2018: member

    I suggest closing this issue, since it seems to be a bug in the static analyser.

  7. Empact commented at 5:47 PM on May 21, 2018: member

    @sipa yes we're in agreement. The underlying data is unsigned so the concern does not apply.

  8. fbthrift commented at 7:44 AM on May 23, 2018: none

    thanks,i understand and close the issue

  9. fbthrift closed this on May 23, 2018

  10. fanquake locked this on Jun 1, 2018

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-29 03:15 UTC

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