Ticket #42 (new defect)

Opened 1 year ago

Last modified 1 year ago

Copying gadget::DeviceInterface<T> instances can still fail

Reported by: patrick Assigned to:
Priority: critical Milestone: 2.2
Component: Gadgeteer Version: HEAD
Keywords: copy device interfaces Cc:
Completion:

Description

It seems that there are still cases where copying gadget::DeviceInterface<T> instances can fail. In particular, the following usage can lead to crashes:

mAnalogIfVec.reserve(num_analogs);
for ( unsigned int i = 0; i < num_analogs; ++i )
{
   const std::string analog_name(getAnalaogName(i));
   gadget::AnalogInterface analog_if;
   analog_if.init(analog_name);
   mAnalogIfVec.push_back(analog_if);
}

However, the following works fine:

mAnalogIfVec.resize(num_analogs);
for ( unsigned int i = 0; i < num_analogs; ++i )
{
   const std::string analog_name(getAnalaogName(i));
   mAnalogIfVec[i].init(analog_name);
}

Note the difference between using std::vector<gadget::AnalogInterface>::reserve() versus std::vector<gadget::AnalogInterface>::resize().

Attachments

Change History

07/31/07 09:57:13 changed by patrick

  • summary changed from Copying `gadget::DeviceInterface<T>` instances can still fail to Copying gadget::DeviceInterface<T> instances can still fail.

Add/Change #42 (Copying gadget::DeviceInterface<T> instances can still fail)




Change Properties
Action