From ad7eba0b012f90aa323230b9c7c778270467c1ff Mon Sep 17 00:00:00 2001 From: Rigel Di Scala Date: Sun, 21 Jan 2024 19:36:38 +0100 Subject: [PATCH] Don't get or set cells in rows that are less than zero --- src/main.c | 2 +- src/tinycols/color.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 7798364..8db9b9e 100644 --- a/src/main.c +++ b/src/main.c @@ -7,7 +7,7 @@ #include "../include/queue.h" #include "../include/gfx.h" -#define TINYCOLS_VERSION "0.8.0" +#define TINYCOLS_VERSION "0.8.1" #define TICK_TIME 10000 #define MAX_TIMER 180 diff --git a/src/tinycols/color.c b/src/tinycols/color.c index e218a70..b0ea602 100644 --- a/src/tinycols/color.c +++ b/src/tinycols/color.c @@ -2,10 +2,16 @@ inline enum color get_cell_color(const struct grid *gr, int row, int col) { - return gr->cells[(row * gr->cols) + col]; + if ((row >= 0) && (row <= gr->rows) && (col <= gr->cols)) { + return gr->cells[(row * gr->cols) + col]; + } else { + return TRANSPARENT; + } } inline void set_cell_color(struct grid *gr, int row, int col, enum color clr) { - gr->cells[(row * gr->cols) + col] = clr; + if ((row >= 0) && (row <= gr->rows) && (col <= gr->cols)) { + gr->cells[(row * gr->cols) + col] = clr; + } }