ARMmbed / core-util

DEPRECATED: Mbed 3 utilities library
Other
12 stars 17 forks source link

Array: push_back on an uninitialised array fails as a side effect #71

Closed adbridge closed 8 years ago

adbridge commented 8 years ago

Currently the push_back() code looks like this:

   bool push_back(const T& new_element) {
        unsigned idx = _elements, prev_capacity = _capacity;
        if (_elements == _capacity) {
            if (_grow_capacity == 0) { // can we grow?
                return false;
            }

If this method is called on an uninitialised array then we would expect it to return False, but it does so only as a side effect of trying to test whether the array is allowed to grow. ie _elements, _capacity and _grow_capacity should all start as 0

It would be safer to have a specific test for the array not having been initialised yet.

bogdanm commented 8 years ago

It would be safer to have a specific test for the array not having been initialised yet.

Absolutely! Although with the kind of changes we're planning init might disappear completely, so this might get better all on its own.

adbridge commented 8 years ago

We may well have to fix this and the the initialisation of default values asap ready for the Q1 release as the optimisations may not get the go ahead until Q2 ?

ciarmcom commented 8 years ago

ARM Internal Ref: IOTSFW-2012

0xc0170 commented 8 years ago

73 fixes this