Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8178348

left_n_bits(0) invokes undefined behavior

    XMLWordPrintable

Details

    • b14
    • generic
    • generic

    Description

      The current definition of left_n_bits is

      #define left_n_bits(n) \
        (right_n_bits(n) << (((n) >= BitsPerWord) ? 0 : (BitsPerWord - (n))))

      When n == 0, this reduces to

        (right_n_bits(0) << BitsPerWord)

      According to C++03 5.8/2, the behavior of a shift expression is undefined if the right operand is greater than or equal to the length in bits of the promoted left operand. So a shift by BitsPerWord invokes undefined behavior.

      Attachments

        Issue Links

          Activity

            People

              hseigel Harold Seigel (Inactive)
              kbarrett Kim Barrett
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: