From b636e338c4a2327d0f3abb3f123a0464a003aba9 Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Wed, 13 Feb 2019 09:16:55 +0800 Subject: [PATCH] Prefer to use std::array to avoid memory leaking in buffer --- lib/service/buffer.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/service/buffer.cpp b/lib/service/buffer.cpp index 14b421a..3c7064d 100644 --- a/lib/service/buffer.cpp +++ b/lib/service/buffer.cpp @@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include // std::fgets_unlocked, stdin +#include // fgets_unlocked, stdin #include "../index.hpp" /** @@ -47,14 +47,13 @@ namespace comfortable_swipe::service ); // prepare data containers - static const int MAX_LINE_LENGTH = 256; - static char data[MAX_LINE_LENGTH]; + std::array line; // start reading lines from input one by one - while (fgets_unlocked(data, MAX_LINE_LENGTH, stdin) != NULL) + while (fgets_unlocked(line.data(), line.size(), stdin) != NULL) { // attempt to parse swipe gestures - swipe_gesture_handler.parse_line(data); + swipe_gesture_handler.parse_line(line.data()); } } }