From 0adee8fae008660895c9f993021ca3c68a173312 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 18 Aug 2022 13:03:17 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Fix=20strtof=20interpreting=20a?= =?UTF-8?q?=20hex=20value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug introduced in #21532 --- Marlin/src/gcode/parser.h | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h index 3f5290e81c..c05d6f32c5 100644 --- a/Marlin/src/gcode/parser.h +++ b/Marlin/src/gcode/parser.h @@ -256,22 +256,20 @@ public: // 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