yakra / tmtools

Tools to aid in development of the TravelMapping project
0 stars 0 forks source link

CSV mode: std::out_of_range #38

Closed yakra closed 6 years ago

yakra commented 6 years ago

http://www.cplusplus.com/reference/string/string/operator[]/ http://www.cplusplus.com/reference/string/string/at/ http://www.cplusplus.com/reference/stdexcept/out_of_range/

canvas & gisplunge • Test a broken CSV with incomplete information • [] > string length causes undefined behavior; use string::at • Test broken CSV again • try, catch

Test with: • NY I-90 • break usact's systems.csv line

yakra commented 6 years ago

try blocks: How would indentation etc. compare with current committed version? How would the DIFFs look?

yakra commented 6 years ago

No need to return 0 or terminate program, etc. Just skip adding element to vector/deque and continue

yakra commented 6 years ago

• [] > string length causes undefined behavior; use string::at

This makes no difference. string::at would throw an exception even at the end of a good line when attempting to evaluate whether CSVline[i] != ';'. The solution is to check whether i < CSVline.size(), which renders the distinction between [] and .at() moot.

Test with: • NY I-90 ... Just skip adding element to vector/deque and continue

This is exactly what happens when reading a Chopped Routes CSV. After premature end of a CSV line, nothing gets pushed to the strings it's split into. Thus it tries to look for a file named .wpt, (most likely) doesn't find it, and life goes on. If it does find such a file, I'm not going to code for such a rare case. Don't leave those lying around. No changes are needed here, other than adding in a bit of i < CSVline.size() to the IF statements. On second thought, this is easy. Done. Tests if (Root.empty()).

• break usact's systems.csv line

Incomplete CSVline -> garbage data after end -> wacky hijinks. In this case, usact ended up being rendered in lightsalmon. i < CSVline.size() definitely needed here too. ...An empty Tier field can cause unsigned short Tier = stoi(TierS); to throw std::invalid_argument. This is where try and catch come in.

yakra commented 6 years ago

canvas: https://github.com/yakra/tmtools/commit/eaac4d69560cd981adf42010cffcc047455583cd gisplunge: https://github.com/yakra/tmtools/commit/ba711e775e9da1672c03627b81ed583c4b26879c