Sizeof char is always 1. Rename patch_str to patch. Realloc patch instead of buffer overflowing.