@@ -304,14 +304,17 @@ static void asar_patch_begin(char * romdata_, int buflen, int * romlen_)
304304{
305305 if (buflen != maxromsize)
306306 {
307- romdata_r = (unsigned char *)malloc (maxromsize);
308- memcpy (const_cast <unsigned char *>(romdata_r)/* we just allocated this, it's safe to violate its const*/ , romdata_, (size_t )*romlen_);
307+ unsigned char * romdata_r_buffer = (unsigned char *)malloc (maxromsize);
308+ memcpy (romdata_r_buffer, romdata_, (size_t )*romlen_);
309+ romdata_r = romdata_r_buffer;
309310 }
310311 else romdata_r = (unsigned char *)romdata_;
311- romdata = (unsigned char *)malloc (maxromsize);
312- // RPG Hacker: Without this memset, freespace commands can (and probably will) fail.
313- memset ((void *)romdata, 0 , maxromsize);
314- memcpy (const_cast <unsigned char *>(romdata), romdata_, (size_t )*romlen_);
312+ unsigned char * romdata_buffer = (unsigned char *)malloc (maxromsize);
313+ // this memset shouldn't be necessary currently (expanding the rom should
314+ // fill the new parts with freespacebyte), but doesn't hurt to be safe here
315+ memset (romdata_buffer, 0 , maxromsize);
316+ memcpy (romdata_buffer, romdata_, (size_t )*romlen_);
317+ romdata = romdata_buffer;
315318 resetdllstuff ();
316319 romlen = *romlen_;
317320 romlen_r = *romlen_;
0 commit comments