lcm1602: fix potential reference of uninitialized memory

Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
Jon Trulson 2016-10-25 16:59:53 -06:00
parent 654c3be71e
commit bfe64789b6

View File

@ -55,6 +55,8 @@ lcm1602_context lcm1602_i2c_init(int bus, int address, bool is_expander,
if (!dev)
return NULL;
memset((void *)dev, 0, sizeof(struct _lcm1602_context));
// make sure MRAA is initialized
int mraa_rv;
if ((mraa_rv = mraa_init()) != MRAA_SUCCESS)
@ -64,8 +66,6 @@ lcm1602_context lcm1602_i2c_init(int bus, int address, bool is_expander,
return NULL;
}
memset((void *)dev, 0, sizeof(struct _lcm1602_context));
// initialize the MRAA context
if (!(dev->i2c = mraa_i2c_init(bus)))
@ -146,6 +146,8 @@ lcm1602_context lcm1602_gpio_init(uint8_t rs, uint8_t enable,
if (!dev)
return NULL;
memset((void *)dev, 0, sizeof(struct _lcm1602_context));
// make sure MRAA is initialized
int mraa_rv;
if ((mraa_rv = mraa_init()) != MRAA_SUCCESS)
@ -155,8 +157,6 @@ lcm1602_context lcm1602_gpio_init(uint8_t rs, uint8_t enable,
return NULL;
}
memset((void *)dev, 0, sizeof(struct _lcm1602_context));
// initialize the MRAA contexts
if (!(dev->gpioRS = mraa_gpio_init(rs)))