From b7fd109f93e05f6719075efd43fc458ad25171ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 10 Apr 2018 10:14:46 +0200 Subject: [PATCH] [ion] Fix hexNumber(). Change-Id: Ic12e3f17ec5e6508613034c4b259eee2fd103be4 --- ion/src/device/bench/command/command.cpp | 9 +++++---- ion/src/device/bench/command/command.h | 2 +- ion/src/device/bench/command/print.cpp | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ion/src/device/bench/command/command.cpp b/ion/src/device/bench/command/command.cpp index b8a41bdfc..645b224d9 100644 --- a/ion/src/device/bench/command/command.cpp +++ b/ion/src/device/bench/command/command.cpp @@ -30,11 +30,12 @@ bool isHex(char c) { return hexChar(c) >= 0; } -uint32_t hexNumber(const char * s) { +uint32_t hexNumber(const char * s, int maxLength) { uint32_t result = 0; - int8_t digit = 0; - while ((digit = hexChar(*s++)) >= 0) { - result = (result << 4) | digit; + int index = 0; + while ((maxLength < 0 || index < maxLength) && s[index] != NULL) { + result = (result << 4) | hexChar(s[index]); + index++; } return result; } diff --git a/ion/src/device/bench/command/command.h b/ion/src/device/bench/command/command.h index 5a749ed1d..5e5b9b857 100644 --- a/ion/src/device/bench/command/command.h +++ b/ion/src/device/bench/command/command.h @@ -31,7 +31,7 @@ extern const char * const sOFF; void reply(const char * s); int8_t hexChar(char c); bool isHex(char c); -uint32_t hexNumber(const char * s); +uint32_t hexNumber(const char * s, int maxLength = -1); } } diff --git a/ion/src/device/bench/command/print.cpp b/ion/src/device/bench/command/print.cpp index ec51a410b..8b5eb3bfc 100644 --- a/ion/src/device/bench/command/print.cpp +++ b/ion/src/device/bench/command/print.cpp @@ -15,8 +15,8 @@ void Print(const char * input) { return; } - char x = hexNumber(input); - char y = hexNumber(input+3); + char x = hexNumber(input, 2); + char y = hexNumber(input+3, 2); KDContext * ctx = KDIonContext::sharedContext(); ctx->drawString(input+6, KDPoint(x, y));