From e0ef93396e9fe9bf66b6d57fbd8f0f2f99bbf895 Mon Sep 17 00:00:00 2001 From: Reto Schneider Date: Wed, 7 Apr 2021 19:00:08 +0200 Subject: [PATCH] fixup! [GH-494] ci: Build and test on multiple architectures --- core/utils.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/core/utils.c b/core/utils.c index 3d8afea46..8878dea0f 100644 --- a/core/utils.c +++ b/core/utils.c @@ -140,7 +140,13 @@ int utils_textToFloat(const uint8_t * buffer, int sign; int i; - if (0 == length) return 0; + printf("%s (%d): Converting %s with length %d\n", __func__, __LINE__, + buffer, length); + + if (0 == length) { + printf("%s (%d): Returning error\n", __func__, __LINE__); + return 0; + } if (buffer[0] == '-') { @@ -154,19 +160,26 @@ int utils_textToFloat(const uint8_t * buffer, } /* Must have a decimal digit first after optional sign */ - if (i >= length || !isdigit(buffer[i])) return 0; + if (i >= length || !isdigit(buffer[i])) { + printf("%s (%d): Returning error\n", __func__, __LINE__); + return 0; + } result = 0; while (i < length && buffer[i] != '.' && buffer[i] != 'e' && buffer[i] != 'E') { if (isdigit(buffer[i])) { - if (result > (DBL_MAX / 10)) return 0; + if (result > (DBL_MAX / 10)) { + printf("%s (%d): Returning error\n", __func__, __LINE__); + return 0; + } result *= 10; result += (buffer[i] - '0'); } else { + printf("%s (%d): Returning error\n", __func__, __LINE__); return 0; } i++; @@ -187,6 +200,7 @@ int utils_textToFloat(const uint8_t * buffer, } else { + printf("%s (%d): Returning error\n", __func__, __LINE__); return 0; } i++; @@ -197,12 +211,18 @@ int utils_textToFloat(const uint8_t * buffer, int64_t exp; int res; - if (!allowExponential) return 0; + if (!allowExponential) { + printf("%s (%d): Returning error\n", __func__, __LINE__); + return 0; + } i++; if (i < length && buffer[i] == '+') i++; res = utils_textToInt(buffer + i, length - i, &exp); - if (res == 0) return 0; + if (res == 0) { + printf("%s (%d): Returning error\n", __func__, __LINE__); + return 0; + } if (exp > 0) { while (exp > 100) @@ -243,6 +263,7 @@ int utils_textToFloat(const uint8_t * buffer, if (result > DBL_MAX) result = DBL_MAX; /* Keep the result finite */ *dataP = result * sign; + printf("%s (%d): Value %f\n", __func__, __LINE__, *dataP); return 1; }