Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DirectSound.cpp: Fix MinGW compilation warnings #2810

Merged

Conversation

@davidebeatrici
Copy link
Member

commented Feb 4, 2017

DirectSound.cpp:548:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (static_cast<int>(dwReadyBytes) < sizeof(short) * iFrameSize) {
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
DirectSound.cpp:563:44: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    } while (static_cast<int>(dwReadyBytes) < sizeof(short) * iFrameSize);
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
DirectSound.cpp:571:120: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long long unsigned int' [-Wformat=]
      qWarning("DXAudioInput: Lock from %ld (%d bytes) failed: hr=0x%08lx",dwLastReadPos, sizeof(short) * iFrameSize, hr);
                                                                                                                        ^

@davidebeatrici davidebeatrici added the build label Feb 4, 2017

@@ -545,7 +545,7 @@ void DXAudioInput::run() {
else
dwReadyBytes = dwReadPosition - dwLastReadPos;

if (static_cast<int>(dwReadyBytes) < sizeof(short) * iFrameSize) {
if (static_cast<unsigned int>(dwReadyBytes) < sizeof(short) * iFrameSize) {

This comment has been minimized.

Copy link
@hacst

hacst Feb 4, 2017

Member

size_t would make more sense as that is what the right side is promoted to.

@@ -560,15 +560,15 @@ void DXAudioInput::run() {
didsleep = true;
firstsleep = false;
}
} while (static_cast<int>(dwReadyBytes) < sizeof(short) * iFrameSize);
} while (static_cast<unsigned int>(dwReadyBytes) < sizeof(short) * iFrameSize);

This comment has been minimized.

Copy link
@hacst

hacst Feb 4, 2017

Member

see above


// Desynchonized?
if (dwReadyBytes > (dwBufferSize / 2)) {
qWarning("DXAudioInput: Lost synchronization");
dwLastReadPos = dwReadPosition;
} else if (bRunning) {
if (FAILED(hr = pDSCaptureBuffer->Lock(dwLastReadPos, sizeof(short) * iFrameSize, &aptr1, &nbytes1, &aptr2, &nbytes2, 0))) {
qWarning("DXAudioInput: Lock from %ld (%d bytes) failed: hr=0x%08lx",dwLastReadPos, sizeof(short) * iFrameSize, hr);
qWarning("DXAudioInput: Lock from %ld (%llu bytes) failed: hr=0x%08lx",dwLastReadPos, sizeof(short) * iFrameSize, hr);

This comment has been minimized.

Copy link
@hacst

hacst Feb 4, 2017

Member

I don't think this is correct. On x86 size_t is 32bit. Try whether Qt accepts '''%zu''' there instead. That is the correct way to format a size_t afaik.

This comment has been minimized.

Copy link
@mkrautz

mkrautz Feb 5, 2017

Member

OTOH, this should be OK if you cast dwLastReadPos to unsigned long long... That an acceptable way to portably print a size_t in my book.

But %zu should work in modern MSVCs (and even not-so modern ones)...

https://github.com/mumble-voip/mumble-releng/blob/master/buildenv/1.3.x/win32-static/patches/test_vsnprintf.c#L103-L104 <- That's a test I created when porting libsndfile from MinGW to MSVC2013 (I believe).

So ust use %zu :)

@mkrautz
Copy link
Member

left a comment

Please use %zu

@davidebeatrici davidebeatrici force-pushed the davidebeatrici:DirectSound.cpp_fix-warnings branch from 93e1793 to dd91247 Feb 5, 2017


// Desynchonized?
if (dwReadyBytes > (dwBufferSize / 2)) {
qWarning("DXAudioInput: Lost synchronization");
dwLastReadPos = dwReadPosition;
} else if (bRunning) {
if (FAILED(hr = pDSCaptureBuffer->Lock(dwLastReadPos, sizeof(short) * iFrameSize, &aptr1, &nbytes1, &aptr2, &nbytes2, 0))) {
qWarning("DXAudioInput: Lock from %ld (%d bytes) failed: hr=0x%08lx",dwLastReadPos, sizeof(short) * iFrameSize, hr);
qWarning("DXAudioInput: Lock from %ld (%zu bytes) failed: hr=0x%08lx",dwLastReadPos, sizeof(short) * iFrameSize, hr);

This comment has been minimized.

Copy link
@mkrautz

mkrautz Feb 5, 2017

Member

Maybe change %ld to %lu while we're here (%d is signed).
And change dwLastReadPos to static_cast(dwLastReadPos)?

@davidebeatrici davidebeatrici force-pushed the davidebeatrici:DirectSound.cpp_fix-warnings branch from dd91247 to 398c5a9 Feb 5, 2017


// Desynchonized?
if (dwReadyBytes > (dwBufferSize / 2)) {
qWarning("DXAudioInput: Lost synchronization");
dwLastReadPos = dwReadPosition;
} else if (bRunning) {
if (FAILED(hr = pDSCaptureBuffer->Lock(dwLastReadPos, sizeof(short) * iFrameSize, &aptr1, &nbytes1, &aptr2, &nbytes2, 0))) {
qWarning("DXAudioInput: Lock from %ld (%d bytes) failed: hr=0x%08lx",dwLastReadPos, sizeof(short) * iFrameSize, hr);
qWarning("DXAudioInput: Lock from %lu (%zu bytes) failed: hr=0x%08lx", static_cast(dwLastReadPos), sizeof(short) * iFrameSize, hr);

This comment has been minimized.

Copy link
@mkrautz

mkrautz Feb 5, 2017

Member

This doesn't build...

Should be static_cast<unsigned long>(...)... Apologies if I wrote only static_cast(...) before. The markdown must have eaten my < and >s.

DirectSound.cpp: Fix MinGW compilation warnings
DirectSound.cpp:548:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (static_cast<int>(dwReadyBytes) < sizeof(short) * iFrameSize) {
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
DirectSound.cpp:563:44: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    } while (static_cast<int>(dwReadyBytes) < sizeof(short) * iFrameSize);
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
DirectSound.cpp:571:120: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long long unsigned int' [-Wformat=]
      qWarning("DXAudioInput: Lock from %ld (%d bytes) failed: hr=0x%08lx",dwLastReadPos, sizeof(short) * iFrameSize, hr);
                                                                                                                        ^

@davidebeatrici davidebeatrici force-pushed the davidebeatrici:DirectSound.cpp_fix-warnings branch from 398c5a9 to 6afeca6 Feb 5, 2017

@mkrautz
mkrautz approved these changes Feb 5, 2017

@mkrautz mkrautz merged commit 4ca6f2c into mumble-voip:master Feb 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.