diff options
author | David Cole <david.cole@kitware.com> | 2009-11-18 16:22:38 (GMT) |
---|---|---|
committer | David Cole <david.cole@kitware.com> | 2009-11-18 16:22:38 (GMT) |
commit | ba216220485e16d4fb4fbb073462a57b16f87e54 (patch) | |
tree | 7c118b75534e55301415fcc4beba10eb7acc8951 /Source | |
parent | 5fbefd66dcb28c3b835130ca226d041e53a62f2c (diff) | |
download | CMake-ba216220485e16d4fb4fbb073462a57b16f87e54.zip CMake-ba216220485e16d4fb4fbb073462a57b16f87e54.tar.gz CMake-ba216220485e16d4fb4fbb073462a57b16f87e54.tar.bz2 |
Fix bogus calls to GetMemoryStatus and GetMemoryStatusEx: need to set the dwLength member of the struct prior to calling. Otherwise it's just a garbage value from the stack. Also, pay attention to return value of GetMemoryStatusEx: if it indicates failure then just return 0 without using any of the other data the call returns.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/kwsys/SystemInformation.cxx | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx index ecdedc7..894cf57 100644 --- a/Source/kwsys/SystemInformation.cxx +++ b/Source/kwsys/SystemInformation.cxx @@ -2279,11 +2279,16 @@ int SystemInformationImplementation::QueryMemory() #elif _WIN32 #if _MSC_VER < 1300 MEMORYSTATUS ms; + ms.dwLength = sizeof(ms); GlobalMemoryStatus(&ms); #define MEM_VAL(value) dw##value #else MEMORYSTATUSEX ms; - GlobalMemoryStatusEx(&ms); + ms.dwLength = sizeof(ms); + if (0 == GlobalMemoryStatusEx(&ms)) + { + return 0; + } #define MEM_VAL(value) ull##value #endif unsigned long tv = ms.MEM_VAL(TotalVirtual); |