From d041cbbb7aebdea65ec72d8781487d00bd0d6ec2 Mon Sep 17 00:00:00 2001 From: James Urquhart Date: Fri, 7 Nov 2014 23:47:05 +0000 Subject: [PATCH 1/3] Fix bug where console stack was incorrectly used to print audio devices --- Engine/source/sfx/sfxSystem.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Engine/source/sfx/sfxSystem.cpp b/Engine/source/sfx/sfxSystem.cpp index 5c425038a..a18d28616 100644 --- a/Engine/source/sfx/sfxSystem.cpp +++ b/Engine/source/sfx/sfxSystem.cpp @@ -1254,7 +1254,9 @@ DefineEngineFunction( sfxGetAvailableDevices, const char*, (),, "@ingroup SFX" ) { char* deviceList = Con::getReturnBuffer( 2048 ); - deviceList[0] = 0; + S32 len = 2048; + char *ptr = deviceList; + *ptr = 0; SFXProvider* provider = SFXProvider::getFirstProvider(); while ( provider ) @@ -1264,14 +1266,15 @@ DefineEngineFunction( sfxGetAvailableDevices, const char*, (),, for ( S32 d=0; d < deviceInfo.size(); d++ ) { const SFXDeviceInfo* info = deviceInfo[d]; - dStrcat( deviceList, provider->getName() ); - dStrcat( deviceList, "\t" ); - dStrcat( deviceList, info->name ); - dStrcat( deviceList, "\t" ); - dStrcat( deviceList, info->hasHardware ? "1" : "0" ); - dStrcat( deviceList, "\t" ); - dStrcat( deviceList, Con::getIntArg( info->maxBuffers ) ); - dStrcat( deviceList, "\n" ); + const char *providerName = provider->getName().c_str(); + const char *infoName = info->name.c_str(); + dSprintf(ptr, len, "%s\t%s\t%s\t%i\n", providerName, infoName, info->hasHardware ? "1" : "0", info->maxBuffers); + + ptr += dStrlen(deviceList); + len = 2048 - (ptr - deviceList); + + if (len <= 0) + return deviceList; //TODO: caps } From 0e87023e46a01831b4aec857046e5dbfe888dbf1 Mon Sep 17 00:00:00 2001 From: James Urquhart Date: Sat, 8 Nov 2014 00:01:01 +0000 Subject: [PATCH 2/3] Fix problem with formatting --- Engine/source/sfx/sfxSystem.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Engine/source/sfx/sfxSystem.cpp b/Engine/source/sfx/sfxSystem.cpp index a18d28616..9fcc526be 100644 --- a/Engine/source/sfx/sfxSystem.cpp +++ b/Engine/source/sfx/sfxSystem.cpp @@ -1266,17 +1266,15 @@ DefineEngineFunction( sfxGetAvailableDevices, const char*, (),, for ( S32 d=0; d < deviceInfo.size(); d++ ) { const SFXDeviceInfo* info = deviceInfo[d]; - const char *providerName = provider->getName().c_str(); - const char *infoName = info->name.c_str(); - dSprintf(ptr, len, "%s\t%s\t%s\t%i\n", providerName, infoName, info->hasHardware ? "1" : "0", info->maxBuffers); + const char *providerName = provider->getName().c_str(); + const char *infoName = info->name.c_str(); + dSprintf(ptr, len, "%s\t%s\t%s\t%i\n", providerName, infoName, info->hasHardware ? "1" : "0", info->maxBuffers); - ptr += dStrlen(deviceList); - len = 2048 - (ptr - deviceList); + ptr += dStrlen(deviceList); + len = 2048 - (ptr - deviceList); - if (len <= 0) + if (len <= 0) return deviceList; - - //TODO: caps } provider = provider->getNextProvider(); From 20acbfed04ae64ad2f08d22e2a243a9404d744ee Mon Sep 17 00:00:00 2001 From: James Urquhart Date: Sat, 8 Nov 2014 00:14:56 +0000 Subject: [PATCH 3/3] Fix late night coding issue --- Engine/source/sfx/sfxSystem.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Engine/source/sfx/sfxSystem.cpp b/Engine/source/sfx/sfxSystem.cpp index 9fcc526be..2fee72237 100644 --- a/Engine/source/sfx/sfxSystem.cpp +++ b/Engine/source/sfx/sfxSystem.cpp @@ -1253,8 +1253,9 @@ DefineEngineFunction( sfxGetAvailableDevices, const char*, (),, "@ref SFX_devices\n" "@ingroup SFX" ) { - char* deviceList = Con::getReturnBuffer( 2048 ); - S32 len = 2048; + const S32 bufferSize = 2048; + char* deviceList = Con::getReturnBuffer( bufferSize ); + S32 len = bufferSize; char *ptr = deviceList; *ptr = 0; @@ -1270,8 +1271,8 @@ DefineEngineFunction( sfxGetAvailableDevices, const char*, (),, const char *infoName = info->name.c_str(); dSprintf(ptr, len, "%s\t%s\t%s\t%i\n", providerName, infoName, info->hasHardware ? "1" : "0", info->maxBuffers); - ptr += dStrlen(deviceList); - len = 2048 - (ptr - deviceList); + ptr += dStrlen(ptr); + len = bufferSize - (ptr - deviceList); if (len <= 0) return deviceList;