Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1248

pointer subtraction in TMemoryBuffer relies on undefined behavior

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.5
    • Fix Version/s: 0.9.3
    • Component/s: C++ - Library
    • Labels:
      None
    • Patch Info:
      Patch Available

      Description

      The ensureCanWrite function in TMemoryBuffer currently "rebases" the buffer pointers by subtracting the original buffer pointer from the pointer newly returned by realloc. While this seems to work fine on my linux setup(I couldn't force a reproducer), pointer subtraction between pointers that we allocated separately is an undefined operation.

      I have run into problems with this on platforms other than linux.

      I am attaching a patch that removes the undefined operation.

        Attachments

        1. 0_7_0_ptrdiff.patch
          1.0 kB
          Anatoly Fayngelerin

          Activity

            People

            • Assignee:
              jking3 James E. King III
              Reporter:
              fanatoly Anatoly Fayngelerin
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: