From 7d2ef0ac3d583a2fe4eb2c0f0033395618c532af Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Thu, 15 May 2014 21:02:31 -0400 Subject: [PATCH] prevent segfault caused by bitidx++ This patch modifies Adafruit_DHT_Driver/Adafruit_DHT.c so that the code that increments `bitidx` without bound is protected by #ifdef DEBUG. This prevents this code from generating a segfault if readDHT is called several times (which will ultimately cause bitidx to increment beyond the end of the bits array). Resolves github issue #78. --- Adafruit_DHT_Driver/Adafruit_DHT.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Adafruit_DHT_Driver/Adafruit_DHT.c b/Adafruit_DHT_Driver/Adafruit_DHT.c index 9d1746be..a35cf10d 100644 --- a/Adafruit_DHT_Driver/Adafruit_DHT.c +++ b/Adafruit_DHT_Driver/Adafruit_DHT.c @@ -105,7 +105,9 @@ int readDHT(int type, int pin) { } laststate = bcm2835_gpio_lev(pin); if (counter == 1000) break; +#ifdef DEBUG bits[bitidx++] = counter; +#endif if ((i>3) && (i%2 == 0)) { // shove each bit into the storage bytes