Prevent segfault when input file could not be opened

Hat tip @peterjc, cf #212.