Skip to content

Commit

Permalink
🩹 Fix strtof interpreting a hex value
Browse files Browse the repository at this point in the history
Bug introduced in MarlinFirmware#21532
  • Loading branch information
thinkyhead committed Aug 18, 2022
1 parent 1766ee1 commit af1c7e1
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions Marlin/src/gcode/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,20 @@ class GCodeParser {

// Float removes 'E' to prevent scientific notation interpretation
static float value_float() {
if (value_ptr) {
char *e = value_ptr;
for (;;) {
const char c = *e;
if (c == '\0' || c == ' ') break;
if (c == 'E' || c == 'e') {
*e = '\0';
const float ret = strtof(value_ptr, nullptr);
*e = c;
return ret;
}
++e;
if (!value_ptr) return 0;
char *e = value_ptr;
for (;;) {
const char c = *e;
if (c == '\0' || c == ' ') break;
if (c == 'E' || c == 'e' || c == 'X' || c == 'x') {
*e = '\0';
const float ret = strtof(value_ptr, nullptr);
*e = c;
return ret;
}
return strtof(value_ptr, nullptr);
++e;
}
return 0;
return strtof(value_ptr, nullptr);
}

// Code value as a long or ulong
Expand Down

0 comments on commit af1c7e1

Please sign in to comment.