Skip to content

Commit 580f4a0

Browse files
committed
-nan(ind) is not a way to display zero, it's a result of dividing by zero and this is a crash for int check is only for virtual memory (its amount can be controlled by user) physical memory can't be zero (then how you even run this) not sure about system_cache also optimized math for memory percentages percent_f calculated first, then it converts to int percent
1 parent 3e8b35b commit 580f4a0

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/routine.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9168,8 +9168,8 @@ NTSTATUS _r_sys_getmemoryinfo (
91689168

91699169
out_buffer->physical_memory.used_bytes = out_buffer->physical_memory.total_bytes - out_buffer->physical_memory.free_bytes;
91709170

9171-
out_buffer->physical_memory.percent = (ULONG)PR_CALC_PERCENTOF (out_buffer->physical_memory.used_bytes, out_buffer->physical_memory.total_bytes);
91729171
out_buffer->physical_memory.percent_f = PR_CALC_PERCENTOF (out_buffer->physical_memory.used_bytes, out_buffer->physical_memory.total_bytes);
9172+
out_buffer->physical_memory.percent = (ULONG)out_buffer->physical_memory.percent_f;
91739173
}
91749174

91759175
// file cache information
@@ -9181,8 +9181,8 @@ NTSTATUS _r_sys_getmemoryinfo (
91819181
out_buffer->system_cache.free_bytes = (ULONG64)sfci.PeakSize - (ULONG64)sfci.CurrentSize;
91829182
out_buffer->system_cache.used_bytes = sfci.CurrentSize;
91839183

9184-
out_buffer->system_cache.percent = (ULONG)PR_CALC_PERCENTOF (out_buffer->system_cache.used_bytes, out_buffer->system_cache.total_bytes);
91859184
out_buffer->system_cache.percent_f = PR_CALC_PERCENTOF (out_buffer->system_cache.used_bytes, out_buffer->system_cache.total_bytes);
9185+
out_buffer->system_cache.percent = (ULONG)out_buffer->system_cache.percent_f;
91869186
}
91879187

91889188
// page file information
@@ -9214,8 +9214,9 @@ NTSTATUS _r_sys_getmemoryinfo (
92149214
pagefile = pagefile->NextEntryOffset ? PTR_ADD_OFFSET (pagefile, pagefile->NextEntryOffset) : NULL;
92159215
}
92169216

9217-
out_buffer->page_file.percent = (ULONG)PR_CALC_PERCENTOF (out_buffer->page_file.used_bytes, out_buffer->page_file.total_bytes);
9218-
out_buffer->page_file.percent_f = PR_CALC_PERCENTOF (out_buffer->page_file.used_bytes, out_buffer->page_file.total_bytes);
9217+
//memory are zeroed at start - no need to reassign zero
9218+
if (out_buffer->page_file.total_bytes) out_buffer->page_file.percent_f = PR_CALC_PERCENTOF (out_buffer->page_file.used_bytes, out_buffer->page_file.total_bytes);
9219+
out_buffer->page_file.percent = (ULONG)out_buffer->page_file.percent_f;
92199220
}
92209221

92219222
_r_mem_free (pagefiles);

0 commit comments

Comments
 (0)