buffer overflow, replaced calloc, removed redundant check