Skip to content
Snippets Groups Projects
  1. Jan 10, 2023
  2. Jan 04, 2023
    • Nat Goodspeed's avatar
      DRTVWR-575: Fix possible bad indexing in LLSD::operator[](size_t). · 99c040ea
      Nat Goodspeed authored
      One could argue that passing a negative index to an LLSD array should do
      something other than shrug and reference element [0], but as that's legacy
      behavior, it seems all too likely that the viewer sometimes relies on it.
      
      This specific problem arises if the index passed to operator[]() is negative
      -- either with the previous Integer parameter or with size_t (which of course
      reinterprets the negative index as hugely positive). The non-const
      ImplArray::ref() overload checks parameter 'i' and, if it appears negative,
      sets internal 'index' to 0.
      
      But in the next stanza, if (index >= existing size()), it calls resize() to
      scale the internal array up to one more than the requested index. The trouble
      is that it passed resize(i + 1), not the adjusted resize(index + 1).
      
      With a requested index of exactly -1, that would pass resize(0), which would
      result in the ensuing array[0] reference being invalid.
      
      With a requested index less than -1, that would pass resize(hugely positive)
      -- since, whether operator[]() accepts signed LLSD::Integer or size_t,
      resize() accepts std::vector::size_type. Given that the footprint of an LLSD
      array element is at least a pointer, the number of bytes required for
      resize(hugely positive) is likely to exceed available heap storage.
      
      Passing the adjusted resize(index + 1) should defend against that case.
      99c040ea
    • Nat Goodspeed's avatar
      DRTVWR-575: Use llsdutil.h functions for LLFloaterLandHoldings LLSD · 4093d5b1
      Nat Goodspeed authored
      LLFloaterLandHoldings::postBuild() was constructing an LLSD structure by
      assigning each map entry and array element one at a time. Chorazinallen
      identified a crash bug possibly caused by destroying that LLSD structure.
      Diagnostically try building it using nested llsd::map() and llsd::array()
      calls instead to see if that improves matters.
      4093d5b1
    • Nat Goodspeed's avatar
      DRTVWR-575: Fix bug in macOS micro_sleep(). · aa112ef1
      Nat Goodspeed authored
      The compiler was deducing an unsigned type for the difference (U64 desired
      microseconds - half KERNEL_SLEEP_INTERVAL_US). When the desired sleep was less
      than that constant, the difference went hugely positive, resulting in a very
      long snooze.
      
      Amusingly, forcing that U64 result into an S32 num_sleep_intervals worked only
      *because* of integer truncation: the high-order bits were discarded, resulting
      in a negative result as intended.
      
      Ensuring that both integer operands are signed at the outset, though, produces
      a more formally correct result.
      aa112ef1
  3. Jan 03, 2023
    • Nat Goodspeed's avatar
      DRTVWR-575: Replace some LLSDArray() usage with llsd::array(). · bb718155
      Nat Goodspeed authored
      It seems newer compilers have a different interpretation of exactly when to
      engage LLSDArray's copy constructor. In particular, this assignment:
      
      some_LLSD_map[key] = LLSDArray(...)(...)...;
      
      used to convert the LLSDArray object directly to LLSD; now it first calls the
      custom copy constructor, which embeds the intended array within an outer array
      before assigning it into the containing map.
      
      The newer llsd::array() function avoids that problem because what it returns
      is already an LLSD object.
      
      Taking inventory of LLSDArray assignments of that form turned up a number of
      workarounds like LLSD(LLSDArray(...)). Replacing those with llsd::array() is
      both simpler and more readable.
      
      Tip of the hat to Chorazinallen for surfacing this issue!
      bb718155
  4. Dec 06, 2022
  5. Nov 13, 2022
  6. Nov 12, 2022
    • Nat Goodspeed's avatar
      DRTVWR-575: Address review comments on Xcode 14.1 type tweaks. · 4349cb61
      Nat Goodspeed authored
      Introduce LLSD template constructors and assignment operators to disambiguate
      construction or assignment from any integer type to Integer, likewise any
      floating point type to Real. Use new narrow() function to validate
      conversions.
      
      For LLSD method parameters converted from LLSD::Integer to size_t, where the
      method previously checked for a negative argument, make it now check for
      size_t converted from negative: in other words, more than S32_MAX. The risk of
      having a parameter forced from negative to unsigned exceeds the risk of a
      valid length or index over that max.
      
      In lltracerecording.cpp's PeriodicRecording, now that mCurPeriod and
      mNumRecordedPeriods are size_t instead of S32, defend against subtracting 1
      from 0.
      
      Use narrow() to validate newly-introduced narrowing conversions.
      
      Make llclamp() return the type of the raw input value, even if the types of
      the boundary values differ.
      
      std::ostream::tellp() no longer returns a value we can directly report as a
      number. Cast to U64.
      4349cb61
  7. Nov 11, 2022
  8. Nov 04, 2022
    • Nat Goodspeed's avatar
      DRTVWR-575: Introduce llssize (signed size_t) and narrow() function. · cd997f21
      Nat Goodspeed authored
      llssize is for a function parameter that should accept a size or index
      (derived from size_t, which is 64 bits in a 64-bit viewer) but might need to
      go negative for flag values. We've historically used S32 for that purpose, but
      Xcode 14.1 complains about trying to pass size_t to S32.
      
      narrow() is a template function that casts a wider type (e.g. size_t or
      llssize) to a narrower type (e.g. S32 or U32), with validation in
      RelWithDebInfo builds. It verifies (using assert()) that the value being
      truncated can in fact fit into the target type.
      cd997f21
  9. Nov 03, 2022
  10. Nov 01, 2022
  11. Oct 31, 2022
  12. Oct 26, 2022
  13. Oct 24, 2022
  14. Oct 20, 2022
  15. Oct 17, 2022
  16. Sep 28, 2022
  17. Sep 22, 2022
  18. Sep 21, 2022
  19. Sep 20, 2022
  20. Sep 16, 2022
  21. Sep 15, 2022
Loading