@@ -991,23 +991,6 @@ SString SharedUtil::GetSystemErrorMessage(uint uiError, bool bRemoveNewlines, bo
991991 return strResult;
992992}
993993
994- #ifdef ExpandEnvironmentStringsForUser
995- //
996- // eg "%HOMEDRIVE%" -> "C:"
997- //
998- SString SharedUtil::ExpandEnvString (const SString& strInput)
999- {
1000- HANDLE hProcessToken;
1001- if (!OpenProcessToken (GetCurrentProcess (), TOKEN_IMPERSONATE | TOKEN_QUERY | TOKEN_DUPLICATE, &hProcessToken))
1002- return strInput;
1003-
1004- const static int iBufferSize = 32000 ;
1005- char envBuf[iBufferSize + 2 ];
1006- ExpandEnvironmentStringsForUser (hProcessToken, strInput, envBuf, iBufferSize);
1007- return envBuf;
1008- }
1009- #endif
1010-
1011994// /////////////////////////////////////////////////////////////
1012995//
1013996// MyShellExecute
@@ -1258,6 +1241,7 @@ static LONG SafeNtQueryInformationThread(HANDLE ThreadHandle, INT ThreadInformat
12581241 struct FunctionLookup
12591242 {
12601243 FunctionPointer function;
1244+ HMODULE module ;
12611245 bool once;
12621246 };
12631247
@@ -1267,11 +1251,11 @@ static LONG SafeNtQueryInformationThread(HANDLE ThreadHandle, INT ThreadInformat
12671251 {
12681252 lookup.once = true ;
12691253
1270- HMODULE ntdll = LoadLibraryA (" ntdll.dll" );
1254+ lookup. module = LoadLibraryA (" ntdll.dll" );
12711255
1272- if (ntdll )
1273- lookup.function = static_cast <FunctionPointer>(static_cast <void *>(GetProcAddress (ntdll , " NtQueryInformationThread" )));
1274- else
1256+ if (lookup. module )
1257+ lookup.function = static_cast <FunctionPointer>(static_cast <void *>(GetProcAddress (lookup. module , " NtQueryInformationThread" )));
1258+ else
12751259 return 0xC0000135L ; // STATUS_DLL_NOT_FOUND
12761260 }
12771261
@@ -1876,17 +1860,27 @@ namespace SharedUtil
18761860 // Dynamically load GetCurrentProcessorNumber, as it does not exist on XP
18771861 using GetCurrentProcessorNumber_t = DWORD (WINAPI*)();
18781862
1879- static auto FnGetCurrentProcessorNumber = ([]() -> GetCurrentProcessorNumber_t {
1880- HMODULE kernel32 = LoadLibraryA (" kernel32" );
1863+ struct ProcessorNumberLookup
1864+ {
1865+ GetCurrentProcessorNumber_t function;
1866+ HMODULE module ;
1867+ bool once;
1868+ };
1869+
1870+ static ProcessorNumberLookup lookup = {};
1871+
18811872
1882- if (kernel32)
1883- return static_cast <GetCurrentProcessorNumber_t>(static_cast <void *>(GetProcAddress (kernel32, " GetCurrentProcessorNumber" )));
1873+ if (!lookup.once )
1874+ {
1875+ lookup.once = true ;
1876+ lookup.module = LoadLibraryA (" kernel32" );
18841877
1885- return nullptr ;
1886- })();
1878+ if (lookup.module )
1879+ lookup.function = static_cast <GetCurrentProcessorNumber_t>(static_cast <void *>(GetProcAddress (lookup.module , " GetCurrentProcessorNumber" )));
1880+ }
18871881
1888- if (FnGetCurrentProcessorNumber )
1889- return FnGetCurrentProcessorNumber ();
1882+ if (lookup. function )
1883+ return lookup. function ();
18901884
18911885 return _GetCurrentProcessorNumberXP ();
18921886#elif defined(__APPLE__) && defined(__aarch64__)
@@ -2091,7 +2085,7 @@ namespace SharedUtil
20912085 if (iter == m_StartLastMap.end ())
20922086 return ;
20932087
2094- // If last of found range is after query last, then range is not obscured
2088+ // If last of found range is after or at query last, then range is not obscured
20952089 if (iter->second > uiLast)
20962090 return ;
20972091
@@ -2105,6 +2099,15 @@ namespace SharedUtil
21052099 IterType iter = m_StartLastMap.lower_bound (uiPoint);
21062100 // iter is on or after point - So it can't overlap the point
21072101
2102+ if (iter != m_StartLastMap.end ())
2103+ {
2104+ // If last of found range is after or at query point, then range is overlapping
2105+ if (iter->first <= uiPoint && iter->second >= uiPoint)
2106+ {
2107+ result = iter;
2108+ return true ;
2109+ }
2110+ }
21082111 if (iter != m_StartLastMap.begin ())
21092112 {
21102113 iter--;
0 commit comments