summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2023-06-21 04:03:48 +0000
committerGitHub <noreply@github.com>2023-06-21 00:03:48 -0400
commit6f1a8f7e5b2dd2aad8913da4d1b60a9433779b6f (patch)
tree568eddb118e56a282310d1d14d142f227344da44
parent76e81df7150d9445699fcb66e678c319b4655d8f (diff)
bug: fix overflow/underflow with graph timespan zoom (#1219)
* bug: fix overflow/underflow with graph timespan zoom Basically, you could overflow/underflow the time span which would skip checks. * changelog
-rw-r--r--CHANGELOG.md3
-rw-r--r--src/app.rs36
2 files changed, 26 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 49901965..86841312 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Bug Fixes
-- [https://github.com/ClementTsang/bottom/pull/1216](https://github.com/ClementTsang/bottom/pull/1216): Fix arguments not being sorted alphabetically.
+- [#1216](https://github.com/ClementTsang/bottom/pull/1216): Fix arguments not being sorted alphabetically.
+- [#1219](https://github.com/ClementTsang/bottom/pull/1219): Fix overflow/underflow in graph timespan zoom.
## [0.9.2] - 2023-06-11
diff --git a/src/app.rs b/src/app.rs
index 50e87b22..5418f615 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -2173,8 +2173,10 @@ impl App {
.widget_states
.get_mut(&self.current_widget.widget_id)
{
- let new_time = cpu_widget_state.current_display_time
- + self.app_config_fields.time_interval;
+ let new_time = cpu_widget_state
+ .current_display_time
+ .saturating_add(self.app_config_fields.time_interval);
+
if new_time <= self.app_config_fields.retention_ms {
cpu_widget_state.current_display_time = new_time;
self.states.cpu_state.force_update = Some(self.current_widget.widget_id);
@@ -2199,8 +2201,10 @@ impl App {
.widget_states
.get_mut(&self.current_widget.widget_id)
{
- let new_time = mem_widget_state.current_display_time
- + self.app_config_fields.time_interval;
+ let new_time = mem_widget_state
+ .current_display_time
+ .saturating_add(self.app_config_fields.time_interval);
+
if new_time <= self.app_config_fields.retention_ms {
mem_widget_state.current_display_time = new_time;
self.states.mem_state.force_update = Some(self.current_widget.widget_id);
@@ -2225,8 +2229,10 @@ impl App {
.widget_states
.get_mut(&self.current_widget.widget_id)
{
- let new_time = net_widget_state.current_display_time
- + self.app_config_fields.time_interval;
+ let new_time = net_widget_state
+ .current_display_time
+ .saturating_add(self.app_config_fields.time_interval);
+
if new_time <= self.app_config_fields.retention_ms {
net_widget_state.current_display_time = new_time;
self.states.net_state.force_update = Some(self.current_widget.widget_id);
@@ -2257,8 +2263,10 @@ impl App {
.widget_states
.get_mut(&self.current_widget.widget_id)
{
- let new_time = cpu_widget_state.current_display_time
- - self.app_config_fields.time_interval;
+ let new_time = cpu_widget_state
+ .current_display_time
+ .saturating_sub(self.app_config_fields.time_interval);
+
if new_time >= constants::STALE_MIN_MILLISECONDS {
cpu_widget_state.current_display_time = new_time;
self.states.cpu_state.force_update = Some(self.current_widget.widget_id);
@@ -2283,8 +2291,10 @@ impl App {
.widget_states
.get_mut(&self.current_widget.widget_id)
{
- let new_time = mem_widget_state.current_display_time
- - self.app_config_fields.time_interval;
+ let new_time = mem_widget_state
+ .current_display_time
+ .saturating_sub(self.app_config_fields.time_interval);
+
if new_time >= constants::STALE_MIN_MILLISECONDS {
mem_widget_state.current_display_time = new_time;
self.states.mem_state.force_update = Some(self.current_widget.widget_id);
@@ -2309,8 +2319,10 @@ impl App {
.widget_states
.get_mut(&self.current_widget.widget_id)
{
- let new_time = net_widget_state.current_display_time
- - self.app_config_fields.time_interval;
+ let new_time = net_widget_state
+ .current_display_time
+ .saturating_sub(self.app_config_fields.time_interval);
+
if new_time >= constants::STALE_MIN_MILLISECONDS {
net_widget_state.current_display_time = new_time;
self.states.net_state.force_update = Some(self.current_widget.widget_id);