Skip to content

Commit

Permalink
fixup! [eclipse-wakaamaGH-494] ci: Build and test on multiple archite…
Browse files Browse the repository at this point in the history
…ctures
  • Loading branch information
rettichschnidi committed Apr 7, 2021
1 parent a0f8f16 commit e0ef933
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions core/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] == '-')
{
Expand All @@ -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++;
Expand All @@ -187,6 +200,7 @@ int utils_textToFloat(const uint8_t * buffer,
}
else
{
printf("%s (%d): Returning error\n", __func__, __LINE__);
return 0;
}
i++;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit e0ef933

Please sign in to comment.