robinluckey/ohcount — pull request #13 by raphink (2012-06-01 22:09:18+00:00)
Title: Prevent segfault on empty files

When running ohcount on empty files, it chokes and segfaults when it uses the `mystrnlen` function used by disambiguation functions.

For example, I have a `site.pp` file which only contains `\n`:

rpinson@wrk4:~/dev/ohcount$ bin/ohcount site.pp
Examining 1 file(s)
Segmentation fault (core dumped)

This PR fixes this by returning 0 when `char *begin` is `NULL`:

rpinson@wrk4:~/dev/ohcount$ bin/ohcount site.pp
Examining 1 file(s)

Ohloh Line Count Summary

Language Files Code Comment Comment % Blank Total
---------------- ----- --------- --------- --------- --------- ---------
---------------- ----- --------- --------- --------- --------- ---------
Total 0 0 0 0.0% 0 0

For some reason, this bug only affects the `_pp` disambiguation, even though `_pl` also uses `mystrnlen` in a very similar way. It might be that there is actually a bug in the `_pp` disambiguation function that I'm not seeing, and thus a better way to fix this...