Prevent SEGFAULT on bad inputs