[Imgtool] Fixed a recently introduced bug which caused image types that do not support partitions to function incorrectly

This commit is contained in:
Nathan Woods 2016-11-11 12:00:01 -05:00
parent a9d260cf14
commit 696b24e24f
3 changed files with 18 additions and 14 deletions

View File

@ -518,7 +518,7 @@ imgtoolerr_t imgtool::image::list_partitions(std::vector<imgtool::partition_info
else
{
// default implementation
partitions.emplace_back(unknown_partition_get_info, 0, ~0);
partitions.emplace_back(module().imgclass, 0, ~0);
}
return IMGTOOLERR_SUCCESS;
}
@ -560,9 +560,8 @@ uint64_t imgtool::image::rand()
// imgtool::partition ctor
//-------------------------------------------------
imgtool::partition::partition(imgtool::image &image, imgtool_class &imgclass, int partition_index, uint64_t base_block, uint64_t block_count)
imgtool::partition::partition(imgtool::image &image, const imgtool_class &imgclass, int partition_index, uint64_t base_block, uint64_t block_count)
: m_image(image)
//, m_partition_index(partition_index)
, m_base_block(base_block)
, m_block_count(block_count)
, m_imgclass(imgclass)
@ -635,9 +634,7 @@ imgtoolerr_t imgtool::partition::open(imgtool::image &image, int partition_index
{
imgtoolerr_t err = (imgtoolerr_t)IMGTOOLERR_SUCCESS;
imgtool::partition::ptr p;
imgtool_class imgclass;
std::vector<imgtool::partition_info> partitions;
uint64_t base_block, block_count;
imgtoolerr_t (*open_partition)(imgtool::partition &partition, uint64_t first_block, uint64_t block_count);
// list the partitions
@ -646,14 +643,13 @@ imgtoolerr_t imgtool::partition::open(imgtool::image &image, int partition_index
return err;
// is this an invalid index?
if ((partition_index < 0) || (partition_index >= partitions.size()) || !partitions[partition_index].get_info())
if ((partition_index < 0) || (partition_index >= partitions.size()) || (!partitions[partition_index].imgclass().get_info && !partitions[partition_index].imgclass().derived_get_info))
return IMGTOOLERR_INVALIDPARTITION;
// use this partition
memset(&imgclass, 0, sizeof(imgclass));
imgclass.get_info = partitions[partition_index].get_info();
base_block = partitions[partition_index].base_block();
block_count = partitions[partition_index].block_count();
const imgtool_class &imgclass(partitions[partition_index].imgclass());
uint64_t base_block = partitions[partition_index].base_block();
uint64_t block_count = partitions[partition_index].block_count();
// allocate the new partition object
try { p = std::make_unique<imgtool::partition>(image, imgclass, partition_index, base_block, block_count); }

View File

@ -144,7 +144,7 @@ namespace imgtool
typedef std::unique_ptr<partition> ptr;
// ctor/dtor
partition(imgtool::image &image, imgtool_class &imgclass, int partition_index, uint64_t base_block, uint64_t block_count);
partition(imgtool::image &image, const imgtool_class &imgclass, int partition_index, uint64_t base_block, uint64_t block_count);
~partition();
static imgtoolerr_t open(imgtool::image &image, int partition_index, ptr &partition);

View File

@ -244,18 +244,26 @@ namespace imgtool
{
public:
partition_info(imgtool_get_info get_info, uint64_t base_block, uint64_t block_count)
: m_get_info(get_info)
: m_base_block(base_block)
, m_block_count(block_count)
{
memset(&m_imgclass, 0, sizeof(m_imgclass));
m_imgclass.get_info = get_info;
}
partition_info(imgtool_class imgclass, uint64_t base_block, uint64_t block_count)
: m_imgclass(imgclass)
, m_base_block(base_block)
, m_block_count(block_count)
{
}
imgtool_get_info get_info() const { return m_get_info; }
const imgtool_class &imgclass() const { return m_imgclass; }
uint64_t base_block() const { return m_base_block; }
uint64_t block_count() const { return m_block_count; }
private:
imgtool_get_info m_get_info;
imgtool_class m_imgclass;
uint64_t m_base_block;
uint64_t m_block_count;
};