[PATCH] kernel32: Fix overflow on 32-bits systems
Maarten Lankhorst
m.b.lankhorst at gmail.com
Sat Sep 10 04:22:59 CDT 2011
unsigned long is used, which is fine for up to (but not including)
4TB of memory/swap, but the multiplication was wrong, causing it to
overflow at 4GB. Fix this by adding a cast.
Signed-off-by: Maarten Lankhorst <m.b.lankhorst at gmail.com>
---
Seems BSD, Sun and Apple are still wrong for 32-bits?
diff --git a/dlls/kernel32/heap.c b/dlls/kernel32/heap.c
index 598bfe4..db21b7a 100644
--- a/dlls/kernel32/heap.c
+++ b/dlls/kernel32/heap.c
@@ -1204,17 +1204,17 @@ BOOL WINAPI GlobalMemoryStatusEx( LPMEMORYSTATUSEX lpmemex )
/* new style /proc/meminfo ... */
if (sscanf(buffer, "MemTotal: %lu", &total))
- lpmemex->ullTotalPhys = total*1024;
+ lpmemex->ullTotalPhys = (ULONG64)total*1024;
if (sscanf(buffer, "MemFree: %lu", &free))
- lpmemex->ullAvailPhys = free*1024;
+ lpmemex->ullAvailPhys = (ULONG64)free*1024;
if (sscanf(buffer, "SwapTotal: %lu", &total))
- lpmemex->ullTotalPageFile = total*1024;
+ lpmemex->ullTotalPageFile = (ULONG64)total*1024;
if (sscanf(buffer, "SwapFree: %lu", &free))
- lpmemex->ullAvailPageFile = free*1024;
+ lpmemex->ullAvailPageFile = (ULONG64)free*1024;
if (sscanf(buffer, "Buffers: %lu", &buffers))
- lpmemex->ullAvailPhys += buffers*1024;
+ lpmemex->ullAvailPhys += (ULONG64)buffers*1024;
if (sscanf(buffer, "Cached: %lu", &cached))
- lpmemex->ullAvailPhys += cached*1024;
+ lpmemex->ullAvailPhys += (ULONG64)cached*1024;
}
fclose( f );
}
More information about the wine-patches
mailing list