Bugs in code tend to come together, even worse, they cascade, one leading into another. In this case, there were two problems. First of all,
if (0 == NULL) {
/*This will run*/
}
This is awful. A value of zero is equivalent to NULL?! Whatever. Don't use NULL, ever. Especially if you're checking if a variable is empty.The second problem is:
atof(""); /* return: 0.0 */
atof("Hello World"); /* return: 0.0 */
atof returns 0.0f if it fails to convert the given character string into a number. Who thought that was a good idea?!Therefore, the code has a new hack: AFTER a line is parsed and "converted" to a number, a check is run to see if the variable that was used to set the coordinates is empty. If it is, then std::nan() is used to overwrite that section of the parsed line struct and later on, when it is important to know whether the variable was empty or not, std::isnan() is used to check. What a mess.
I updated the Github repository with the latest changes, all seems to be well now. I'm working on compiled binaries to put on this page, because that 1Gb of free space on Hackaday.io is tempting me!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.