From 0ee67a521be5d4f369a4310f06a912ba5bf14a64 Mon Sep 17 00:00:00 2001 From: ProDrone Date: Thu, 14 May 2015 00:11:31 +0200 Subject: [PATCH] Optimized comment stripper code --- src/main/io/serial_cli.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index 256bb6ac7..668edc9af 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -1712,19 +1712,20 @@ void cliProcess(void) // Strip comment starting with # from line char *p = cliBuffer; - p = strchr(++p, '#'); + p = strchr(p, '#'); if (NULL != p) { bufferIndex = (uint32_t)(p - cliBuffer); } - // Strip trailing whitespace - while (bufferIndex > 0 && cliBuffer[bufferIndex - 1] == ' ') { - bufferIndex--; - } + // Process non-empty lines + if (bufferIndex > 0) { + // Strip trailing whitespace + while (bufferIndex > 0 && cliBuffer[bufferIndex - 1] == ' ') { + bufferIndex--; + } - cliBuffer[bufferIndex] = 0; // null terminate + cliBuffer[bufferIndex] = 0; // null terminate - if (cliBuffer[0] != '#') { target.name = cliBuffer; target.param = NULL;