char *base = malloc(sizeof(char) * 1); base[0] = '\0'; strncat(base, hash, hash_length - 1); 1 byte buffer is overwritten by strncat.