Coverity analysis defect 146093: Bad bit shift operation

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Storage Execution
    • ALL
    • Storage Execution 2025-09-29
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Bad bit shift operation

      The operation may have an undefined behavior or yield an unexpected result. A bit shift operation has a shift amount which is too large or has a negative value.
      /data/mci/9292c3def3822c0dfd66af88847bcc64/bazel_cache/004acac643584f695e6309f72694e5ad/execroot/_main/src/mongo/db/storage/key_string.cpp:946: BAD_SHIFT 146093 Function call "mongo::countLeadingZeros64(integerPart << 1)" may return 64.
      /data/mci/9292c3def3822c0dfd66af88847bcc64/bazel_cache/004acac643584f695e6309f72694e5ad/execroot/_main/src/mongo/db/storage/key_string.cpp:946: BAD_SHIFT 146093 Assigning: "fractionalBytes" = "mongo::countLeadingZeros64(integerPart << 1) / 8". The value of "fractionalBytes" is now 8.
      /data/mci/9292c3def3822c0dfd66af88847bcc64/bazel_cache/004acac643584f695e6309f72694e5ad/execroot/_main/src/mongo/db/storage/key_string.cpp:960: BAD_SHIFT 146093 In expression "integerPart + 1UL << fractionalBytes * 8UL", left shifting by more than 63 bits has undefined behavior. The shift amount, "fractionalBytes * 8UL", is 64.

            Assignee:
            Wei Hu
            Reporter:
            Coverity Collector User
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: