Fix bug in w32_memory_info
authorArthur Miller <arthur.miller@live.com>
Tue, 21 Jan 2025 18:10:14 +0000 (19:10 +0100)
committerEli Zaretskii <eliz@gnu.org>
Tue, 21 Jan 2025 19:22:58 +0000 (21:22 +0200)
* src/w32.c (w32_memory_info): Initialize struct size.

src/w32.c

index 6399d8835440e5cb197de13bcb7f9a41d422796f..0d876951cf67b6be7f5058a92272285e759c7313 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -7659,7 +7659,7 @@ w32_memory_info (unsigned long long *totalram, unsigned long long *freeram,
 {
   MEMORYSTATUS memst;
   MEMORY_STATUS_EX memstex;
-
+  memstex.dwLength = sizeof(memstex);
   /* Use GlobalMemoryStatusEx if available, as it can report more than
      2GB of memory.  */
   if (global_memory_status_ex (&memstex))
@@ -7670,7 +7670,9 @@ w32_memory_info (unsigned long long *totalram, unsigned long long *freeram,
       *freeswap  = memstex.ullAvailPageFile;
       return 0;
     }
-  else if (global_memory_status (&memst))
+
+  memst.dwLength = sizeof(memst);
+  if (global_memory_status (&memst))
     {
       *totalram = memst.dwTotalPhys;
       *freeram   = memst.dwAvailPhys;