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

Stop mixing signed and unsigned types in bit operations

    XMLWordPrintable

Details

    • b22

    Backports

      Description

        Only use unsigned types in [gs]et_byte_in_int (atomic.hpp). In the code below, bitsIdx ought to be uint32_t instead of int.

        ```
        inline uint32_t Atomic::CmpxchgByteUsingInt::set_byte_in_int(uint32_t n,
                                                                     uint8_t b,
                                                                     uint32_t idx) {
          int bitsIdx = BitsPerByte * idx;
          return (n & ~(static_cast<uint32_t>(0xff) << bitsIdx))
                  | (static_cast<uint32_t>(b) << bitsIdx);
        }

        inline uint8_t Atomic::CmpxchgByteUsingInt::get_byte_in_int(uint32_t n,
                                                                    uint32_t idx) {
          int bitsIdx = BitsPerByte * idx;
          return (uint8_t)(n >> bitsIdx);
        }
        ```

        Attachments

          Issue Links

            Activity

              People

                lkorinth Leo Korinth
                lkorinth Leo Korinth
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: