Previous 15994 Revisions Next

r14649 Monday 27th February, 2012 at 18:51:33 UTC by Firewave
fixed stack overflow in chdman when compiled with Visual Studio by moving objects based on chd_file_compressor to the heap
[src/tools]chdman.c

src/tools/chdman.c
r14648r14649
15521552   printf("Logical size: %s\n", big_int_string(tempstr, input_end - input_start));
15531553
15541554   // catch errors so we can close & delete the output file
1555   chd_rawfile_compressor* chd = NULL;
15551556   try
15561557   {
15571558      // create the new CHD
1558      chd_rawfile_compressor chd(input_file, input_start, input_end);
1559      chd = new chd_rawfile_compressor(input_file, input_start, input_end);
15591560      chd_error err;
15601561      if (output_parent.opened())
1561         err = chd.create(*output_chd_str, input_end - input_start, hunk_size, compression, output_parent);
1562         err = chd->create(*output_chd_str, input_end - input_start, hunk_size, compression, output_parent);
15621563      else
1563         err = chd.create(*output_chd_str, input_end - input_start, hunk_size, unit_size, compression);
1564         err = chd->create(*output_chd_str, input_end - input_start, hunk_size, unit_size, compression);
15641565      if (err != CHDERR_NONE)
15651566         report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err));
15661567
15671568      // if we have a parent, copy forward all the metadata
15681569      if (output_parent.opened())
1569         chd.clone_all_metadata(output_parent);
1570         chd->clone_all_metadata(output_parent);
15701571
15711572      // compress it generically
1572      compress_common(chd);
1573      compress_common(*chd);
1574      delete chd;
15731575   }
15741576   catch (...)
15751577   {
r14648r14649
15771579      astring *output_chd_str = params.find(OPTION_OUTPUT);
15781580      if (output_chd_str != NULL)
15791581         osd_rmfile(*output_chd_str);
1582      if (chd != NULL)
1583         delete chd;
15801584      throw;
15811585   }
15821586}
r14648r14649
18101814   printf("Logical size: %s\n", big_int_string(tempstr, UINT64(totalsectors) * CD_FRAME_SIZE));
18111815
18121816   // catch errors so we can close & delete the output file
1817   chd_cd_compressor* chd = NULL;
18131818   try
18141819   {
1815      // create the new hard drive
1816      chd_cd_compressor chd(toc, track_info);
1820      // create the new CD
1821      chd = new chd_cd_compressor(toc, track_info);
18171822      chd_error err;
18181823      if (output_parent.opened())
1819         err = chd.create(*output_chd_str, UINT64(totalsectors) * UINT64(CD_FRAME_SIZE), hunk_size, compression, output_parent);
1824         err = chd->create(*output_chd_str, UINT64(totalsectors) * UINT64(CD_FRAME_SIZE), hunk_size, compression, output_parent);
18201825      else
1821         err = chd.create(*output_chd_str, UINT64(totalsectors) * UINT64(CD_FRAME_SIZE), hunk_size, CD_FRAME_SIZE, compression);
1826         err = chd->create(*output_chd_str, UINT64(totalsectors) * UINT64(CD_FRAME_SIZE), hunk_size, CD_FRAME_SIZE, compression);
18221827      if (err != CHDERR_NONE)
18231828         report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err));
18241829
18251830      // add the standard CD metadata; we do this even if we have a parent because it might be different
1826      err = cdrom_write_metadata(&chd, &toc);
1831      err = cdrom_write_metadata(chd, &toc);
18271832      if (err != CHDERR_NONE)
18281833         report_error(1, "Error adding CD metadata: %s", chd_file::error_string(err));
18291834
18301835      // compress it generically
1831      compress_common(chd);
1836      compress_common(*chd);
1837      delete chd;
18321838   }
18331839   catch (...)
18341840   {
r14648r14649
18361842      astring *output_chd_str = params.find(OPTION_OUTPUT);
18371843      if (output_chd_str != NULL)
18381844         osd_rmfile(*output_chd_str);
1845      if (chd != NULL)
1846         delete chd;
18391847      throw;
18401848   }
18411849}
r14648r14649
19221930   printf("Logical size: %s\n", big_int_string(tempstr, UINT64(input_end - input_start) * hunk_size));
19231931
19241932   // catch errors so we can close & delete the output file
1933   chd_avi_compressor* chd = NULL;
19251934   try
19261935   {
19271936      // create the new CHD
1928      chd_avi_compressor chd(*input_file, info, input_start, input_end);
1937      chd = new chd_avi_compressor(*input_file, info, input_start, input_end);
19291938      chd_error err;
19301939      if (output_parent.opened())
1931         err = chd.create(*output_chd_str, UINT64(input_end - input_start) * hunk_size, hunk_size, compression, output_parent);
1940         err = chd->create(*output_chd_str, UINT64(input_end - input_start) * hunk_size, hunk_size, compression, output_parent);
19321941      else
1933         err = chd.create(*output_chd_str, UINT64(input_end - input_start) * hunk_size, hunk_size, info.bytes_per_frame, compression);
1942         err = chd->create(*output_chd_str, UINT64(input_end - input_start) * hunk_size, hunk_size, info.bytes_per_frame, compression);
19341943      if (err != CHDERR_NONE)
19351944         report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err));
19361945
19371946      // write the core A/V metadata
19381947      astring metadata;
19391948      metadata.format(AV_METADATA_FORMAT, info.fps_times_1million / 1000000, info.fps_times_1million % 1000000, info.width, info.height, info.interlaced, info.channels, info.rate);
1940      err = chd.write_metadata(AV_METADATA_TAG, 0, metadata);
1949      err = chd->write_metadata(AV_METADATA_TAG, 0, metadata);
19411950      if (err != CHDERR_NONE)
19421951         report_error(1, "Error adding AV metadata: %s\n", chd_file::error_string(err));
19431952
19441953      // create the compressor and then run it generically
1945      compress_common(chd);
1954      compress_common(*chd);
19461955
19471956      // write the final LD metadata
19481957      if (info.height == 524/2 || info.height == 624/2)
19491958      {
1950         err = chd.write_metadata(AV_LD_METADATA_TAG, 0, chd.ldframedata());
1959         err = chd->write_metadata(AV_LD_METADATA_TAG, 0, chd->ldframedata());
19511960         if (err != CHDERR_NONE)
19521961            report_error(1, "Error adding AVLD metadata: %s\n", chd_file::error_string(err));
19531962      }
1963      delete chd;
19541964   }
19551965   catch (...)
19561966   {
r14648r14649
19581968      astring *output_chd_str = params.find(OPTION_OUTPUT);
19591969      if (output_chd_str != NULL)
19601970         osd_rmfile(*output_chd_str);
1971      if (chd != NULL)
1972         delete chd;
19611973      throw;
19621974   }
19631975}
r14648r14649
20262038   printf("Logical size: %s\n", big_int_string(tempstr, input_end - input_start));
20272039
20282040   // catch errors so we can close & delete the output file
2041   chd_chdfile_compressor* chd = NULL;
20292042   try
20302043   {
20312044      // create the new CHD
2032      chd_chdfile_compressor chd(input_chd, input_start, input_end);
2045      chd = new chd_chdfile_compressor(input_chd, input_start, input_end);
20332046      chd_error err;
20342047      if (output_parent.opened())
2035         err = chd.create(*output_chd_str, input_end - input_start, hunk_size, compression, output_parent);
2048         err = chd->create(*output_chd_str, input_end - input_start, hunk_size, compression, output_parent);
20362049      else
2037         err = chd.create(*output_chd_str, input_end - input_start, hunk_size, input_chd.unit_bytes(), compression);
2050         err = chd->create(*output_chd_str, input_end - input_start, hunk_size, input_chd.unit_bytes(), compression);
20382051      if (err != CHDERR_NONE)
20392052         report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err));
20402053
r14648r14649
20542067         }
20552068
20562069         // otherwise, clone it
2057         err = chd.write_metadata(metatag, CHDMETAINDEX_APPEND, metadata);
2070         err = chd->write_metadata(metatag, CHDMETAINDEX_APPEND, metadata);
20582071         if (err != CHDERR_NONE)
20592072            report_error(1, "Error writing cloned metadata: %s", chd_file::error_string(err));
20602073      }
r14648r14649
20662079         if (cdrom == NULL)
20672080            report_error(1, "Error upgrading CD metadata");
20682081         const cdrom_toc *toc = cdrom_get_toc(cdrom);
2069         err = cdrom_write_metadata(&chd, toc);
2082         err = cdrom_write_metadata(chd, toc);
20702083         if (err != CHDERR_NONE)
20712084            report_error(1, "Error writing upgraded CD metadata: %s", chd_file::error_string(err));
20722085      }
20732086
20742087      // compress it generically
2075      compress_common(chd);
2088      compress_common(*chd);
2089      delete chd;
20762090   }
20772091   catch (...)
20782092   {
r14648r14649
20802094      astring *output_chd_str = params.find(OPTION_OUTPUT);
20812095      if (output_chd_str != NULL)
20822096         osd_rmfile(*output_chd_str);
2097      if (chd != NULL)
2098         delete chd;
20832099      throw;
20842100   }
20852101}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team