From 8f61e6b99830c2f93b67e8c17cf4c20f40ee0dbd Mon Sep 17 00:00:00 2001 From: "Sebastian H. Gabrielli" Date: Sun, 28 Apr 2024 20:10:01 +0200 Subject: [PATCH] Validate that we do not overflow the receive buffer Closes #20 --- prosjekt.X/i2c.c | 5 +++++ prosjekt.X/nbproject/configurations.xml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/prosjekt.X/i2c.c b/prosjekt.X/i2c.c index 43f65ab..aff2ac4 100644 --- a/prosjekt.X/i2c.c +++ b/prosjekt.X/i2c.c @@ -53,6 +53,11 @@ void i2c_reset_recv() { void i2c_write_handler(uint8_t data) { last_action_write = true; + + // Validate that we are not overflowing the buffer + if (i2c_recv_len >= I2C_RECV_BUF_SIZE) { return; } + + // Write the data to the receive buffer i2c_recv[i2c_recv_len] = data; i2c_recv_len++; } diff --git a/prosjekt.X/nbproject/configurations.xml b/prosjekt.X/nbproject/configurations.xml index 22bd261..af7016b 100644 --- a/prosjekt.X/nbproject/configurations.xml +++ b/prosjekt.X/nbproject/configurations.xml @@ -42,7 +42,7 @@ nEdbgTool XC8 - 2.45 + 2.46 2