get rid of some instances of type punning (dangerous in the face of aliasing optimizations)
This was SVN commit r6140.
This commit is contained in:
parent
f2037e3dca
commit
e62deac770
@ -1240,6 +1240,11 @@ static LibError VSrc_reload(VSrc* vs, const VfsPath& pathname, Handle hvs)
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
static bool IsValidBoolean(ALboolean b)
|
||||
{
|
||||
return (b == AL_FALSE || b == AL_TRUE);
|
||||
}
|
||||
|
||||
static LibError VSrc_validate(const VSrc* vs)
|
||||
{
|
||||
// al_src can legitimately be 0 (if vs is low-pri)
|
||||
@ -1250,7 +1255,7 @@ static LibError VSrc_validate(const VSrc* vs)
|
||||
WARN_RETURN(ERR::_2);
|
||||
if(!(0.0f < vs->pitch && vs->pitch <= 2.0f))
|
||||
WARN_RETURN(ERR::_3);
|
||||
if(*(u8*)&vs->loop > 1 || *(u8*)&vs->relative > 1)
|
||||
if(!IsValidBoolean(vs->loop) || !IsValidBoolean(vs->relative))
|
||||
WARN_RETURN(ERR::_4);
|
||||
// <static_pri> and <cur_pri> have no invariant we could check.
|
||||
return INFO::OK;
|
||||
|
@ -110,7 +110,7 @@ static void* UnsafeLocateAndRetrieveRsdp(PCV_u8 buf, size_t numBytes, void* arg)
|
||||
if(ComputeChecksum(p, sizeof(RSDP)) != 0)
|
||||
continue;
|
||||
|
||||
*(RSDP*)arg = *prsdp;
|
||||
memcpy(arg, prsdp, sizeof(RSDP));
|
||||
return SUCCEEDED;
|
||||
}
|
||||
|
||||
@ -154,7 +154,7 @@ static inline void* UnsafeAllocateCopyOfTable(PCV_u8 mem, size_t numBytes, void*
|
||||
// (caller will map a larger window and call us again)
|
||||
if(numBytes < tableSize)
|
||||
{
|
||||
*(size_t*)arg = tableSize;
|
||||
memcpy(arg, &tableSize, sizeof(size_t));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,8 @@ WINIT_REGISTER_CRITICAL_INIT(wposix_Init); // wposix -> error handling
|
||||
// used by _SC_PAGESIZE and _SC_*_PAGES
|
||||
static DWORD pageSize;
|
||||
static DWORD numProcessors;
|
||||
static BOOL (WINAPI *pGlobalMemoryStatusEx)(MEMORYSTATUSEX*);
|
||||
typedef BOOL (WINAPI *PGlobalMemoryStatusEx)(MEMORYSTATUSEX*);
|
||||
static PGlobalMemoryStatusEx pGlobalMemoryStatusEx;
|
||||
|
||||
// NB: called from critical init
|
||||
static void InitSysconf()
|
||||
@ -35,7 +36,7 @@ static void InitSysconf()
|
||||
// import GlobalMemoryStatusEx - it's not defined by the VC6 PSDK.
|
||||
// used by _SC_*_PAGES if available (provides better results).
|
||||
const HMODULE hKernel32Dll = GetModuleHandle("kernel32.dll");
|
||||
*(void**)&pGlobalMemoryStatusEx = GetProcAddress(hKernel32Dll, "GlobalMemoryStatusEx");
|
||||
pGlobalMemoryStatusEx = (PGlobalMemoryStatusEx)GetProcAddress(hKernel32Dll, "GlobalMemoryStatusEx");
|
||||
}
|
||||
|
||||
long sysconf(int name)
|
||||
|
@ -45,9 +45,12 @@ const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; // ::_1
|
||||
// enter a clever but safe hack: we call a harmless winsock function that
|
||||
// triggers the delay load or does nothing if init has already happened.
|
||||
|
||||
static int (WINAPI *pgetnameinfo)(const struct sockaddr*, socklen_t, char*, socklen_t, char*, socklen_t, unsigned int);
|
||||
static int (WINAPI *pgetaddrinfo)(const char*, const char*, const struct addrinfo*, struct addrinfo**);
|
||||
static void (WINAPI *pfreeaddrinfo)(struct addrinfo*);
|
||||
typedef int (WINAPI *Pgetnameinfo)(const struct sockaddr*, socklen_t, char*, socklen_t, char*, socklen_t, unsigned int);
|
||||
typedef int (WINAPI *Pgetaddrinfo)(const char*, const char*, const struct addrinfo*, struct addrinfo**);
|
||||
typedef void (WINAPI *Pfreeaddrinfo)(struct addrinfo*);
|
||||
static Pgetnameinfo pgetnameinfo;
|
||||
static Pgetaddrinfo pgetaddrinfo;
|
||||
static Pfreeaddrinfo pfreeaddrinfo;
|
||||
|
||||
int getnameinfo(const struct sockaddr* sa, socklen_t salen, char* host, socklen_t hostlen, char* serv, socklen_t servlen, unsigned int flags)
|
||||
{
|
||||
@ -87,9 +90,9 @@ static void ImportOptionalFunctions()
|
||||
// (by the time we get here, ws2_32.dll will have been loaded, so
|
||||
// this isn't the only reference and can be freed immediately)
|
||||
HMODULE hWs2_32Dll = LoadLibrary("ws2_32.dll");
|
||||
*(void**)&pgetnameinfo = GetProcAddress(hWs2_32Dll, "getnameinfo");
|
||||
*(void**)&pgetaddrinfo = GetProcAddress(hWs2_32Dll, "getaddrinfo");
|
||||
*(void**)&pfreeaddrinfo = GetProcAddress(hWs2_32Dll, "freeaddrinfo");
|
||||
pgetnameinfo = (Pgetnameinfo)GetProcAddress(hWs2_32Dll, "getnameinfo");
|
||||
pgetaddrinfo = (Pgetaddrinfo)GetProcAddress(hWs2_32Dll, "getaddrinfo");
|
||||
pfreeaddrinfo = (Pfreeaddrinfo)GetProcAddress(hWs2_32Dll, "freeaddrinfo");
|
||||
FreeLibrary(hWs2_32Dll);
|
||||
}
|
||||
|
||||
|
@ -95,9 +95,9 @@ static const char* GetDirectSoundDriverPath()
|
||||
{
|
||||
#define DS_OK 0
|
||||
typedef BOOL (CALLBACK* LPDSENUMCALLBACKA)(void*, const char*, const char*, void*);
|
||||
HRESULT (WINAPI *pDirectSoundEnumerateA)(LPDSENUMCALLBACKA, void*);
|
||||
typedef HRESULT (WINAPI *PDirectSoundEnumerateA)(LPDSENUMCALLBACKA, void*);
|
||||
HMODULE hDsoundDll = LoadLibrary("dsound.dll");
|
||||
*(void**)&pDirectSoundEnumerateA = GetProcAddress(hDsoundDll, "DirectSoundEnumerateA");
|
||||
PDirectSoundEnumerateA pDirectSoundEnumerateA = (PDirectSoundEnumerateA)GetProcAddress(hDsoundDll, "DirectSoundEnumerateA");
|
||||
if(pDirectSoundEnumerateA)
|
||||
{
|
||||
HRESULT ret = pDirectSoundEnumerateA(DirectSoundCallback, (void*)0);
|
||||
|
@ -274,8 +274,8 @@ static void EnableLowFragmentationHeap()
|
||||
{
|
||||
#if WINVER >= 0x0501
|
||||
const HMODULE hKernel32Dll = GetModuleHandle("kernel32.dll");
|
||||
BOOL (WINAPI* pHeapSetInformation)(HANDLE, HEAP_INFORMATION_CLASS, void*, size_t);
|
||||
*(void**)&pHeapSetInformation = GetProcAddress(hKernel32Dll, "HeapSetInformation");
|
||||
typedef BOOL (WINAPI* PHeapSetInformation)(HANDLE, HEAP_INFORMATION_CLASS, void*, size_t);
|
||||
PHeapSetInformation pHeapSetInformation = (PHeapSetInformation)GetProcAddress(hKernel32Dll, "HeapSetInformation");
|
||||
if(!pHeapSetInformation)
|
||||
return;
|
||||
|
||||
@ -354,18 +354,21 @@ size_t wutil_WindowsVersion()
|
||||
// that's bad, because the actual drivers are not in the subdirectory. to
|
||||
// work around this, provide for temporarily disabling redirection.
|
||||
|
||||
static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
|
||||
static BOOL (WINAPI *pWow64DisableWow64FsRedirection)(PVOID*) = 0;
|
||||
static BOOL (WINAPI *pWow64RevertWow64FsRedirection)(PVOID) = 0;
|
||||
typedef BOOL (WINAPI *PIsWow64Process)(HANDLE, PBOOL);
|
||||
typedef BOOL (WINAPI *PWow64DisableWow64FsRedirection)(PVOID*);
|
||||
typedef BOOL (WINAPI *PWow64RevertWow64FsRedirection)(PVOID);
|
||||
static PIsWow64Process pIsWow64Process;
|
||||
static PWow64DisableWow64FsRedirection pWow64DisableWow64FsRedirection;
|
||||
static PWow64RevertWow64FsRedirection pWow64RevertWow64FsRedirection;
|
||||
|
||||
static bool isWow64;
|
||||
|
||||
static void ImportWow64Functions()
|
||||
{
|
||||
const HMODULE hKernel32Dll = GetModuleHandle("kernel32.dll");
|
||||
*(void**)&pIsWow64Process = GetProcAddress(hKernel32Dll, "IsWow64Process");
|
||||
*(void**)&pWow64DisableWow64FsRedirection = GetProcAddress(hKernel32Dll, "Wow64DisableWow64FsRedirection");
|
||||
*(void**)&pWow64RevertWow64FsRedirection = GetProcAddress(hKernel32Dll, "Wow64RevertWow64FsRedirection");
|
||||
pIsWow64Process = (PIsWow64Process)GetProcAddress(hKernel32Dll, "IsWow64Process");
|
||||
pWow64DisableWow64FsRedirection = (PWow64DisableWow64FsRedirection)GetProcAddress(hKernel32Dll, "Wow64DisableWow64FsRedirection");
|
||||
pWow64RevertWow64FsRedirection = (PWow64RevertWow64FsRedirection)GetProcAddress(hKernel32Dll, "Wow64RevertWow64FsRedirection");
|
||||
}
|
||||
|
||||
static void DetectWow64()
|
||||
|
@ -8,7 +8,8 @@ public:
|
||||
void test_conversion()
|
||||
{
|
||||
const u32 x = 0x01234567u;
|
||||
const u8 LS_byte = *(u8*)&x;
|
||||
u8 LS_byte;
|
||||
memcpy(&LS_byte, &x, 1);
|
||||
// little endian
|
||||
if(LS_byte == 0x67)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user