From: Nathael Pajani Date: Wed, 23 Sep 2015 12:45:54 +0000 (+0200) Subject: Fix hidden segfault, this should never have been working. It should have trigggered... X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=e82e06d861aca14357f48f2c95f3b674f7b3d3b6;p=soft%2Flpc122x%2Fcore Fix hidden segfault, this should never have been working. It should have trigggered a BusFault exception instead. --- 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;