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

Atomic::CmpxchgByteUsingInt::set_byte_in_int needs an explicit cast

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 17
    • 13
    • hotspot
    • b21

      JDK-8231612 added Atomic::CmpxchgByteUsingInt::set_byte_in_int, and SonarCloud instance reports a problem there: "Add an explicit cast to the result of the "<<" operator."

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

      I think when "b << bitsIdx" is done, "b" is promoted to int first. Probably casting to uint32_t first is safer.

            avoitylov Aleksei Voitylov
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: