MarginallyClever / GcodeCNCDemo

a simple example of making a CNC machine from an Adafruit Motor Shield
213 stars 133 forks source link

infinite loop in parsenumber() #11

Closed i-make-robots closed 7 years ago

i-make-robots commented 8 years ago

float parsenumber(char code,float val) { char _ptr=buffer; while(ptr && *ptr && ptr<buffer+sofar) { if(_ptr==code) { return atof(ptr+1); } ptr=strchr(ptr,' ')+1; } return val; }

if strchr() does not find ' ' it returns null (0) and ptr becomes 1. while(ptr) would not stop the loop.

while(ptr... should be while(ptr>1...

i-make-robots commented 8 years ago

possible fix in 42c0b5d65d51f3352612709255cd09155de4eb32

misan commented 8 years ago

just ptr++; worked for me.

You never know if spaces will be in between or not (as they are not mandatory).

i-make-robots commented 8 years ago

See makelangelo-firmware for updated version.

On Sep 29, 2016, at 3:19 AM, Miguel Sanchez notifications@github.com wrote:

just ptr++; worked for me.

Trouble is strchr returns null if space is not found.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

i-make-robots commented 8 years ago

updated all versions to match makelangelo-firmware, but now github desktop is broken in windows 10.