Fix overrun on improperly terminated configs

When the last line of a config chunk wasn't terminated with a \n,
remaining was decrimented too far, causing an overflow and
subsequent segv.

Fix calculation of remaining size, added test for improperly
terminated config files.
Merge pull request #414 from rpedde/no-trailing-newline

Fix overrun on improperly terminated configs