From 3e8b35b2c08fe9b46607122962451be055eb5fbc Mon Sep 17 00:00:00 2001 From: XakerTwo <13261533+XakerTwo@users.noreply.github.com> Date: Tue, 25 Feb 2025 22:43:40 +0300 Subject: [PATCH 1/2] added inline function for full reset list view --- src/routine.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/routine.h b/src/routine.h index 846c905..4bb22b0 100644 --- a/src/routine.h +++ b/src/routine.h @@ -5586,6 +5586,16 @@ FORCEINLINE BOOLEAN _r_listview_deleteallitems ( return (_r_wnd_sendmessage (hwnd, ctrl_id, LVM_DELETEALLITEMS, 0, 0) == TRUE); } +FORCEINLINE VOID _r_listview_reset ( + _In_ HWND hwnd, + _In_opt_ INT ctrl_id +) +{ + _r_listview_deleteallitems(hwnd, ctrl_id); + _r_listview_deleteallgroups(hwnd, ctrl_id); + _r_listview_deleteallcolumns(hwnd, ctrl_id); +} + FORCEINLINE BOOLEAN _r_listview_deleteitem ( _In_ HWND hwnd, _In_opt_ INT ctrl_id, From 580f4a0b2cc7e8fd60db726b21de221cd6b29d72 Mon Sep 17 00:00:00 2001 From: XakerTwo <13261533+XakerTwo@users.noreply.github.com> Date: Wed, 26 Feb 2025 00:28:29 +0300 Subject: [PATCH 2/2] fix dividing by zero (henrypp/memreduct#262 henrypp/memreduct#263) -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 --- src/routine.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/routine.c b/src/routine.c index a43a2ae..36e3c2f 100644 --- a/src/routine.c +++ b/src/routine.c @@ -9168,8 +9168,8 @@ NTSTATUS _r_sys_getmemoryinfo ( out_buffer->physical_memory.used_bytes = out_buffer->physical_memory.total_bytes - out_buffer->physical_memory.free_bytes; - out_buffer->physical_memory.percent = (ULONG)PR_CALC_PERCENTOF (out_buffer->physical_memory.used_bytes, out_buffer->physical_memory.total_bytes); out_buffer->physical_memory.percent_f = PR_CALC_PERCENTOF (out_buffer->physical_memory.used_bytes, out_buffer->physical_memory.total_bytes); + out_buffer->physical_memory.percent = (ULONG)out_buffer->physical_memory.percent_f; } // file cache information @@ -9181,8 +9181,8 @@ NTSTATUS _r_sys_getmemoryinfo ( out_buffer->system_cache.free_bytes = (ULONG64)sfci.PeakSize - (ULONG64)sfci.CurrentSize; out_buffer->system_cache.used_bytes = sfci.CurrentSize; - out_buffer->system_cache.percent = (ULONG)PR_CALC_PERCENTOF (out_buffer->system_cache.used_bytes, out_buffer->system_cache.total_bytes); out_buffer->system_cache.percent_f = PR_CALC_PERCENTOF (out_buffer->system_cache.used_bytes, out_buffer->system_cache.total_bytes); + out_buffer->system_cache.percent = (ULONG)out_buffer->system_cache.percent_f; } // page file information @@ -9214,8 +9214,9 @@ NTSTATUS _r_sys_getmemoryinfo ( pagefile = pagefile->NextEntryOffset ? PTR_ADD_OFFSET (pagefile, pagefile->NextEntryOffset) : NULL; } - out_buffer->page_file.percent = (ULONG)PR_CALC_PERCENTOF (out_buffer->page_file.used_bytes, 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); + //memory are zeroed at start - no need to reassign zero + 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); + out_buffer->page_file.percent = (ULONG)out_buffer->page_file.percent_f; } _r_mem_free (pagefiles);