From 719a9d32b5b9ddbee2d339d8e4c6fe93ee2e1ac3 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Fri, 7 Jan 2011 18:53:13 +0100 Subject: [PATCH] gcode_parse.c: Limit the digits right of the decimal. Previously, variables in decfloat_to_int() could overflow due to excess precision, like Z2.0000000. --- gcode_parse.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gcode_parse.c b/gcode_parse.c index 4385a7f..2b4f481 100644 --- a/gcode_parse.c +++ b/gcode_parse.c @@ -292,8 +292,10 @@ void gcode_parse_char(uint8_t c) { #endif default: - // can't do ranges in switch..case, so process actual digits here - if (c >= '0' && c <= '9') { + // can't do ranges in switch..case, so process actual digits here. Limit the digits right of the decimal to avoid variable overflow in decfloat_to_int() due to excess precision + if (c >= '0' && c <= '9' && + ((next_target.option_inches == 0 && read_digit.exponent < 4) || + (next_target.option_inches && read_digit.exponent < 5))) { // this is simply mantissa = (mantissa * 10) + atoi(c) in different clothes read_digit.mantissa = (read_digit.mantissa << 3) + (read_digit.mantissa << 1) + (c - '0'); if (read_digit.exponent)