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

Atomic::CmpxchgByteUsingInt::set_byte_in_int needs an explicit cast

    XMLWordPrintable

Details

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

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: