Browse Source

🩹 Fix strtof interpreting a hex value

Bug introduced in #21532
Scott Lahteine 1 year ago
parent
commit
af1c7e1a81
1 changed files with 12 additions and 14 deletions
  1. 12
    14
      Marlin/src/gcode/parser.h

+ 12
- 14
Marlin/src/gcode/parser.h View File

@@ -256,22 +256,20 @@ public:
256 256
 
257 257
   // Float removes 'E' to prevent scientific notation interpretation
258 258
   static float value_float() {
259
-    if (value_ptr) {
260
-      char *e = value_ptr;
261
-      for (;;) {
262
-        const char c = *e;
263
-        if (c == '\0' || c == ' ') break;
264
-        if (c == 'E' || c == 'e') {
265
-          *e = '\0';
266
-          const float ret = strtof(value_ptr, nullptr);
267
-          *e = c;
268
-          return ret;
269
-        }
270
-        ++e;
259
+    if (!value_ptr) return 0;
260
+    char *e = value_ptr;
261
+    for (;;) {
262
+      const char c = *e;
263
+      if (c == '\0' || c == ' ') break;
264
+      if (c == 'E' || c == 'e' || c == 'X' || c == 'x') {
265
+        *e = '\0';
266
+        const float ret = strtof(value_ptr, nullptr);
267
+        *e = c;
268
+        return ret;
271 269
       }
272
-      return strtof(value_ptr, nullptr);
270
+      ++e;
273 271
     }
274
-    return 0;
272
+    return strtof(value_ptr, nullptr);
275 273
   }
276 274
 
277 275
   // Code value as a long or ulong

Loading…
Cancel
Save