From 0e0803a5e6d63dd9dc348bd7b088c25319193fae Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 14 Apr 2019 10:32:11 +0200 Subject: [PATCH] Preventing buffer overflow --- Calendar/LoopTimer.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Calendar/LoopTimer.py b/Calendar/LoopTimer.py index bfbc74b..7342db7 100644 --- a/Calendar/LoopTimer.py +++ b/Calendar/LoopTimer.py @@ -1,6 +1,7 @@ from datetime import datetime, timedelta min_sleep_minutes = 0 +max_history_entries = 25 class LoopTimer (object): """Manages loop times and sleeps until @@ -19,6 +20,10 @@ class LoopTimer (object): def __add_beginning__ (self, time): self.loop_history.append((time,)) + if len(self.loop_history) > max_history_entries: + dif = len(self.loop_history) - max_history_entries + self.loop_history = self.loop_history[dif:] + def __add_ending__ (self, time): current = self.get_current() self.loop_history[-1] = (current[0], time)