Protection against buffer overruns. Fixes to fscanf.

Needed to allocate memory for the name, the man page implied to me I
didn't need to, but I guess I didn't read it carefully enough.

Added constraints on fscanf reading from files to not overrun the
buffers they are being allocated to.