Skip to content

Commit

Permalink
Enable more warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Apr 13, 2023
1 parent e1e750e commit dfc92dd
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 32 deletions.
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ project(dsoal LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(CheckCXXCompilerFlag)

set(DSOAL_CPPDEFS )
set(DSOAL_CFLAGS )
set(DSOAL_LINK_FLAGS )

if(MSVC)
Expand All @@ -16,9 +19,29 @@ if(MSVC)
endif()

set(DSOAL_CPPDEFS ${DSOAL_CPPDEFS} _CRT_SECURE_NO_WARNINGS)

check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
if(HAVE_PERMISSIVE_SWITCH)
set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
endif()
set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4127 /wd4268 /wd4324 /wd5030 /wd5051)
else()
set(DEF_FILE mingw.def)

set(DSOAL_CFLAGS ${DSOAL_CFLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion
-Wcast-align -Wpedantic
$<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)

check_cxx_compiler_flag(-Wno-c++20-attribute-extensions HAVE_WNO_CXX20_ATTR_EXT)
if(HAVE_WNO_CXX20_ATTR_EXT)
set(DSOAL_CFLAGS ${DSOAL_CFLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-c++20-attribute-extensions>)
else()
check_cxx_compiler_flag(-Wno-c++20-extensions HAVE_WNO_CXX20_EXT)
if(HAVE_WNO_CXX20_EXT)
set(DSOAL_CFLAGS ${DSOAL_CFLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-c++20-extensions>)
endif()
endif()

set(DSOAL_LINK_FLAGS ${DSOAL_LINK_FLAGS} -static-libgcc -static-libstdc++)
set(DSOAL_LINK_FLAGS ${DSOAL_LINK_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
endif(MSVC)
Expand All @@ -43,3 +66,4 @@ add_library(dsound SHARED
set_target_properties(dsound PROPERTIES PREFIX "")
target_link_libraries(dsound PRIVATE ${DSOAL_LINK_FLAGS})
target_compile_definitions(dsound PRIVATE DSOAL_LIBRARY ${DSOAL_CPPDEFS})
target_compile_options(dsound PRIVATE ${DSOAL_CFLAGS})
64 changes: 39 additions & 25 deletions src/dsoal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
#include "logging.h"


namespace {

using voidp = void*;
using cvoidp = const void*;

} // namespace

extern "C" {

#ifdef _MSC_VER
Expand All @@ -32,7 +39,7 @@ const IID IID_IMMDeviceEnumerator = {

DSOAL_EXPORT BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD reason, void *reserved)
{
DEBUG("DllMain (%p, %lu, %p)\n", hInstDLL, reason, reserved);
DEBUG("DllMain (%p, %lu, %p)\n", voidp{hInstDLL}, reason, reserved);

switch(reason)
{
Expand Down Expand Up @@ -62,7 +69,8 @@ DSOAL_EXPORT BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD reason, void *reserve
}

/* Increase refcount on dsound by 1 */
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
reinterpret_cast<LPCWSTR>(hInstDLL), &hInstDLL);
break;

case DLL_PROCESS_DETACH:
Expand All @@ -76,27 +84,27 @@ DSOAL_EXPORT BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD reason, void *reserve

HRESULT WINAPI DSOAL_DirectSoundCreate(const GUID *deviceId, IDirectSound **ds, IUnknown *outer)
{
TRACE("DirectSoundCreate (%p, %p, %p)\n", deviceId, ds, outer);
TRACE("DirectSoundCreate (%p, %p, %p)\n", cvoidp{deviceId}, voidp{ds}, voidp{outer});
return E_NOTIMPL;
}

HRESULT WINAPI DSOAL_DirectSoundCreate8(const GUID *deviceId, IDirectSound8 **ds, IUnknown *outer)
{
TRACE("DirectSoundCreate8 (%p, %p, %p)\n", deviceId, ds, outer);
TRACE("DirectSoundCreate8 (%p, %p, %p)\n", cvoidp{deviceId}, voidp{ds}, voidp{outer});
return E_NOTIMPL;
}

HRESULT WINAPI DSOAL_DirectSoundCaptureCreate(const GUID *deviceId, IDirectSoundCapture **ds,
IUnknown *outer)
{
TRACE("DirectSoundCaptureCreate (%p, %p, %p)\n", deviceId, ds, outer);
TRACE("DirectSoundCaptureCreate (%p, %p, %p)\n", cvoidp{deviceId}, voidp{ds}, voidp{outer});
return E_NOTIMPL;
}

HRESULT WINAPI DSOAL_DirectSoundCaptureCreate8(const GUID *deviceId, IDirectSoundCapture8 **ds,
IUnknown *outer)
{
TRACE("DirectSoundCaptureCreate8 (%p, %p, %p)\n", deviceId, ds, outer);
TRACE("DirectSoundCaptureCreate8 (%p, %p, %p)\n", cvoidp{deviceId}, voidp{ds}, voidp{outer});
return E_NOTIMPL;
}

Expand All @@ -106,7 +114,10 @@ HRESULT WINAPI DSOAL_DirectSoundFullDuplexCreate(const GUID *captureDevice,
IDirectSoundFullDuplex **fullDuplex, IDirectSoundCaptureBuffer8 **captureBuffer8,
IDirectSoundBuffer8 **renderBuffer8, IUnknown *outer)
{
TRACE("DirectSoundFullDuplexCreate\n");
TRACE("DirectSoundFullDuplexCreate (%p, %p, %p, %p, %p, %lu, %p, %p, %p, %p)\n",
cvoidp{captureDevice}, cvoidp{renderDevice}, cvoidp{captureBufferDesc},
cvoidp{renderBufferDesc}, voidp{hWnd}, coopLevel, voidp{fullDuplex},
voidp{captureBuffer8}, voidp{renderBuffer8}, voidp{outer});
return E_NOTIMPL;
}

Expand All @@ -132,8 +143,11 @@ class PropVariant {

public:
PropVariant() { PropVariantInit(&mProp); }
PropVariant(const PropVariant&) = delete;
~PropVariant() { clear(); }

PropVariant& operator=(const PropVariant&) = delete;

void clear() { PropVariantClear(&mProp); }

PROPVARIANT* get() noexcept { return &mProp; }
Expand Down Expand Up @@ -207,21 +221,21 @@ HRESULT enumerate_mmdev(const EDataFlow flow, std::deque<GUID> &devlist, T cb)
TRACE("enumerate_mmdev Calling back with NULL (%ls)\n", primary_desc);
bool keep_going{cb(nullptr, primary_desc, L"")};

auto send_device = [flow,&devlist,&cb,&keep_going](IMMDevice *device)
auto send_device = [&devlist,&cb,&keep_going](IMMDevice *device)
{
ComPtr<IPropertyStore> ps;
HRESULT hr{device->OpenPropertyStore(STGM_READ, ds::out_ptr(ps))};
if(FAILED(hr))
HRESULT hr2{device->OpenPropertyStore(STGM_READ, ds::out_ptr(ps))};
if(FAILED(hr2))
{
WARN("send_device IMMDevice::OpenPropertyStore failed: %08lx\n", hr);
WARN("send_device IMMDevice::OpenPropertyStore failed: %08lx\n", hr2);
return;
}

PropVariant pv;
hr = ps->GetValue(PKEY_AudioEndpoint_GUID, pv.get());
if(FAILED(hr) || pv->vt != VT_LPWSTR)
hr2 = ps->GetValue(PKEY_AudioEndpoint_GUID, pv.get());
if(FAILED(hr2) || pv->vt != VT_LPWSTR)
{
WARN("send_device IPropertyStore::GetValue(GUID) failed: %08lx\n", hr);
WARN("send_device IPropertyStore::GetValue(GUID) failed: %08lx\n", hr2);
return;
}

Expand All @@ -234,11 +248,11 @@ HRESULT enumerate_mmdev(const EDataFlow flow, std::deque<GUID> &devlist, T cb)
if(!keep_going) return;

pv.clear();
hr = ps->GetValue(reinterpret_cast<const PROPERTYKEY&>(DEVPKEY_Device_FriendlyName),
hr2 = ps->GetValue(reinterpret_cast<const PROPERTYKEY&>(DEVPKEY_Device_FriendlyName),
pv.get());
if(FAILED(hr))
if(FAILED(hr2))
{
WARN("send_device IPropertyStore::GetValue(FriendlyName) failed: %08lx\n", hr);
WARN("send_device IPropertyStore::GetValue(FriendlyName) failed: %08lx\n", hr2);
return;
}

Expand Down Expand Up @@ -273,15 +287,15 @@ extern "C" {

HRESULT WINAPI DSOAL_DirectSoundEnumerateA(LPDSENUMCALLBACKA callback, void *userPtr)
{
TRACE("DirectSoundEnumerateA (%p, %p)\n", callback, userPtr);
TRACE("DirectSoundEnumerateA (%p, %p)\n", reinterpret_cast<void*>(callback), userPtr);

auto do_enum = [callback,userPtr](GUID *guid, const WCHAR *drvname, const WCHAR *devname)
{
const auto dlen = WideCharToMultiByte(CP_ACP, 0, drvname, -1, nullptr, 0, nullptr, nullptr);
const auto mlen = WideCharToMultiByte(CP_ACP, 0, devname, -1, nullptr, 0, nullptr, nullptr);
if(dlen < 0 || mlen < 0) return false;

auto descA = std::make_unique<char[]>(dlen+mlen+2);
auto descA = std::make_unique<char[]>(static_cast<size_t>(dlen+mlen)+2);
if(!descA) return false;
char *modA = descA.get() + dlen+1;

Expand All @@ -296,7 +310,7 @@ HRESULT WINAPI DSOAL_DirectSoundEnumerateA(LPDSENUMCALLBACKA callback, void *use
}
HRESULT WINAPI DSOAL_DirectSoundEnumerateW(LPDSENUMCALLBACKW callback, void *userPtr)
{
TRACE("DirectSoundEnumerateW (%p, %p)\n", callback, userPtr);
TRACE("DirectSoundEnumerateW (%p, %p)\n", reinterpret_cast<void*>(callback), userPtr);

auto do_enum = [callback,userPtr](GUID *guid, const WCHAR *drvname, const WCHAR *devname)
{ return callback(guid, drvname, devname, userPtr) != FALSE; };
Expand All @@ -307,15 +321,15 @@ HRESULT WINAPI DSOAL_DirectSoundEnumerateW(LPDSENUMCALLBACKW callback, void *use

HRESULT WINAPI DSOAL_DirectSoundCaptureEnumerateA(LPDSENUMCALLBACKA callback, void *userPtr)
{
TRACE("DirectSoundCaptureEnumerateA (%p, %p)\n", callback, userPtr);
TRACE("DirectSoundCaptureEnumerateA (%p, %p)\n", reinterpret_cast<void*>(callback), userPtr);

auto do_enum = [callback,userPtr](GUID *guid, const WCHAR *drvname, const WCHAR *devname)
{
const auto dlen = WideCharToMultiByte(CP_ACP, 0, drvname, -1, nullptr, 0, nullptr, nullptr);
const auto mlen = WideCharToMultiByte(CP_ACP, 0, devname, -1, nullptr, 0, nullptr, nullptr);
if(dlen < 0 || mlen < 0) return false;

auto descA = std::make_unique<char[]>(dlen+mlen+2);
auto descA = std::make_unique<char[]>(static_cast<size_t>(dlen+mlen)+2);
if(!descA) return false;
char *modA = descA.get() + dlen+1;

Expand All @@ -330,7 +344,7 @@ HRESULT WINAPI DSOAL_DirectSoundCaptureEnumerateA(LPDSENUMCALLBACKA callback, vo
}
HRESULT WINAPI DSOAL_DirectSoundCaptureEnumerateW(LPDSENUMCALLBACKW callback, void *userPtr)
{
TRACE("DirectSoundCaptureEnumerateW (%p, %p)\n", callback, userPtr);
TRACE("DirectSoundCaptureEnumerateW (%p, %p)\n", reinterpret_cast<void*>(callback), userPtr);

auto do_enum = [callback,userPtr](GUID *guid, const WCHAR *drvname, const WCHAR *devname)
{ return callback(guid, drvname, devname, userPtr) != FALSE; };
Expand All @@ -348,13 +362,13 @@ HRESULT WINAPI DSOAL_DllCanUnloadNow()

HRESULT WINAPI DSOAL_DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
{
TRACE("DllGetClassObject (%p, %p, %p)\n", &rclsid, &riid, ppv);
TRACE("DllGetClassObject (%p, %p, %p)\n", cvoidp{&rclsid}, cvoidp{&riid}, voidp{ppv});
return E_NOTIMPL;
}

HRESULT WINAPI DSOAL_GetDeviceID(const GUID *guidSrc, GUID *guidDst)
{
TRACE("GetDeviceID (%p, %p)\n", guidSrc, guidDst);
TRACE("GetDeviceID (%p, %p)\n", cvoidp{guidSrc}, voidp{guidDst});

if(!guidSrc || !guidDst)
return DSERR_INVALIDPARAM;
Expand Down
13 changes: 7 additions & 6 deletions src/logging.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "logging.h"

#include <algorithm>
#include <array>
#include <cstdarg>
#include <cstdio>
Expand Down Expand Up @@ -40,20 +41,20 @@ void dsoal_print(LogLevel level, FILE *logfile, const char *fmt, ...)
const auto threadId = GetCurrentThreadId();
int prefixlen{std::snprintf(str, stcmsg.size(), "%04lx:%s:dsound:", threadId, prefix)};
if(prefixlen < 0) prefixlen = 0;
const auto uprefixlen = static_cast<unsigned int>(prefixlen);

std::va_list args, args2;
va_start(args, fmt);
va_copy(args2, args);
const int msglen{std::vsnprintf(str+prefixlen, stcmsg.size()-prefixlen, fmt, args)};
if(msglen >= 0 && static_cast<size_t>(msglen+prefixlen) >= stcmsg.size()) UNLIKELY
const int msglen{std::vsnprintf(str+uprefixlen, stcmsg.size()-uprefixlen, fmt, args)};
if(msglen >= 0 && static_cast<size_t>(msglen)+uprefixlen >= stcmsg.size()) UNLIKELY
{
dynmsg.resize(static_cast<size_t>(msglen+prefixlen) + 1u);
dynmsg.resize(static_cast<size_t>(msglen)+uprefixlen + 1u);
str = dynmsg.data();

prefixlen = std::snprintf(str, dynmsg.size(), "%04lx:%s:dsound:", threadId, prefix);
if(prefixlen < 0) prefixlen = 0;
std::copy_n(stcmsg.data(), uprefixlen, str);

std::vsnprintf(str+prefixlen, dynmsg.size()-prefixlen, fmt, args2);
std::vsnprintf(str+uprefixlen, dynmsg.size()-uprefixlen, fmt, args2);
}
va_end(args2);
va_end(args);
Expand Down
2 changes: 1 addition & 1 deletion src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern LogLevel gLogLevel;
extern FILE *gLogFile;

#if HAS_ATTRIBUTE(gnu::format)
#ifdef __USE_MINGW_ANSI_STDIO
#if defined(__USE_MINGW_ANSI_STDIO) && !defined(__clang__)
[[gnu::format(gnu_printf,3,4)]]
#else
[[gnu::format(printf,3,4)]]
Expand Down

0 comments on commit dfc92dd

Please sign in to comment.