avoid segfault when invalid buffer passed