From e82e06d861aca14357f48f2c95f3b674f7b3d3b6 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Wed, 23 Sep 2015 14:45:54 +0200 Subject: [PATCH] Fix hidden segfault, this should never have been working. It should have trigggered a BusFault exception instead. --- drivers/i2c.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/i2c.c b/drivers/i2c.c index 3be66a4..786171f 100644 --- a/drivers/i2c.c +++ b/drivers/i2c.c @@ -234,7 +234,10 @@ void I2C_0_Handler(void) break; case 0x50: /* Data byte has been received and ACK sent */ - i2c->in_buff[i2c->read_index++] = i2c->regs->data; + if (i2c->in_buff != NULL) { + i2c->in_buff[i2c->read_index] = i2c->regs->data; + } + i2c->read_index++; if ((i2c->read_index + 1) < i2c->read_length) { /* assert ACK after data is received, requesting next Data from slave */ i2c->regs->ctrl_set = I2C_ASSERT_ACK; @@ -247,7 +250,10 @@ void I2C_0_Handler(void) case 0x58: /* Data byte has been received and NACK "sent" */ /* This tells the slave it was the last byte. We should be done. */ - i2c->in_buff[i2c->read_index++] = i2c->regs->data; + if (i2c->in_buff != NULL) { + i2c->in_buff[i2c->read_index] = i2c->regs->data; + } + i2c->read_index++; /* FIXME : We have two other options : Repeated START or STOP + START, * but what for ? periodic reads ? */ i2c->regs->ctrl_set = I2C_STOP_FLAG; -- 2.43.0