From aa112ef17f4fdfeecc05e5305af93a6d4b9fce70 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 4 Jan 2023 12:04:56 -0500 Subject: DRTVWR-575: Fix bug in macOS micro_sleep(). 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. --- indra/llcommon/lltimer.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltimer.cpp b/indra/llcommon/lltimer.cpp index 74ec62d347..58bedacf43 100644 --- a/indra/llcommon/lltimer.cpp +++ b/indra/llcommon/lltimer.cpp @@ -121,9 +121,14 @@ U32 micro_sleep(U64 us, U32 max_yields) U64 start = get_clock_count(); // This is kernel dependent. Currently, our kernel generates software clock // interrupts at 250 Hz (every 4,000 microseconds). - const U64 KERNEL_SLEEP_INTERVAL_US = 4000; - - auto num_sleep_intervals = (us - (KERNEL_SLEEP_INTERVAL_US >> 1)) / KERNEL_SLEEP_INTERVAL_US; + const S64 KERNEL_SLEEP_INTERVAL_US = 4000; + + // Use signed arithmetic to discover whether a sleep is even necessary. If + // either 'us' or KERNEL_SLEEP_INTERVAL_US is unsigned, the compiler + // promotes the difference to unsigned. If 'us' is less than half + // KERNEL_SLEEP_INTERVAL_US, the unsigned difference will be hugely + // positive, resulting in a crazy long wait. + auto num_sleep_intervals = (S64(us) - (KERNEL_SLEEP_INTERVAL_US >> 1)) / KERNEL_SLEEP_INTERVAL_US; if (num_sleep_intervals > 0) { U64 sleep_time = (num_sleep_intervals * KERNEL_SLEEP_INTERVAL_US) - (KERNEL_SLEEP_INTERVAL_US >> 1); -- cgit v1.2.3 From 99c040ea9976e90caec9dedd942badc1c43822e7 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 4 Jan 2023 17:18:31 -0500 Subject: DRTVWR-575: Fix possible bad indexing in LLSD::operator[](size_t). 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. --- indra/llcommon/llsd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llsd.cpp b/indra/llcommon/llsd.cpp index a645e624f8..590915e9d2 100644 --- a/indra/llcommon/llsd.cpp +++ b/indra/llcommon/llsd.cpp @@ -622,7 +622,7 @@ namespace if (index >= mData.size()) { - mData.resize(i + 1); + mData.resize(index + 1); } return mData[index]; -- cgit v1.2.3 From f3cd329b585ef55a66f2a824f010d1a54d67d8d2 Mon Sep 17 00:00:00 2001 From: akleshchev <117672381+akleshchev@users.noreply.github.com> Date: Tue, 10 Jan 2023 19:38:44 +0200 Subject: SL-18911 My Land Holdings floater crashes viewer on the Xcode/+Monterey branches (#47) Revert part of "DRTVWR-575: Address review comments on Xcode 14.1 type tweaks." Crash was reproduced when assigning areastr to llsd, but likely present in other cases of assigning ui strings to llsd (instead of going for lluistring's result directly copy constructor was engaged and either copy or original crashed due to invalid pointers, copy shouldn't have been created). --- indra/llcommon/llsd.h | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llsd.h b/indra/llcommon/llsd.h index c1406cf73f..92a1fc58a5 100644 --- a/indra/llcommon/llsd.h +++ b/indra/llcommon/llsd.h @@ -30,7 +30,6 @@ #include #include #include -#include #include "stdtypes.h" @@ -216,21 +215,15 @@ public: void assign(const Date&); void assign(const URI&); void assign(const Binary&); - - // support assignment from size_t et al. - template ::value && - ! std::is_same::value, - bool>::type = true> - void assign(VALUE v) { assign(Integer(narrow(v))); } - // support assignment from F32 et al. - template ::value, - bool>::type = true> - void assign(VALUE v) { assign(Real(narrow(v))); } - - template - LLSD& operator=(VALUE v) { assign(v); return *this; } + + LLSD& operator=(Boolean v) { assign(v); return *this; } + LLSD& operator=(Integer v) { assign(v); return *this; } + LLSD& operator=(Real v) { assign(v); return *this; } + LLSD& operator=(const String& v) { assign(v); return *this; } + LLSD& operator=(const UUID& v) { assign(v); return *this; } + LLSD& operator=(const Date& v) { assign(v); return *this; } + LLSD& operator=(const URI& v) { assign(v); return *this; } + LLSD& operator=(const Binary& v) { assign(v); return *this; } //@} /** @@ -292,6 +285,7 @@ public: //@{ LLSD(const char*); void assign(const char*); + LLSD& operator=(const char* v) { assign(v); return *this; } //@} /** @name Map Values */ -- cgit v1.2.3