From a65049b6f24bf60b983b009f76a7afdf62d85d08 Mon Sep 17 00:00:00 2001 From: Bianka Forkel <noreply@fortiss.org> Date: Sat, 15 Jul 2017 17:07:50 +0000 Subject: [PATCH] Wrong pointer in LaserRangeFinder refs 7956 --- .../trunk/lib/src/LaserRangeFinder.c | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c index ec34b3b0..1a5fbf36 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c +++ b/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c @@ -32,32 +32,37 @@ GEN_TYPE_int lrf_read() { if (uart_filestream == -1) return -1; - // free buffer + //empty buffer uart_flush(); + //initialize arrays + int i; char bytes[6]; + for (i = 0; i < 6; i++) { + bytes[i] = 0; + } int n_read = 0; - char value[3]; - int n = 0; - - int i; + char value[4]; + for (i = 0; i < 4; i++) { + value[i] = 0; + } + int n = 0; int d; - // looks like a blocking call and actually is but is always very fast - // since it only has to read the queue + //receive values while (1) { - n_read = uart_receive(&bytes, 6, 0); + n_read = uart_receive(bytes, 6, 0); + + if(n_read <= 0) + return -1; for (i = 0; i < n_read; i++) { if (bytes[i] != 0xd && bytes[i] != 0xa) { value[n++] = bytes[i]; } else if (atoi(value) != 0) { d = atoi(value); - for (i = n; i < 3; i++) { - value[i] = 0; - } return d; } } -- GitLab