View Issue Details

IDProjectCategoryView StatusLast Update
0002178OpenFOAMPatchpublic2016-08-03 19:46
Reporteruser696Assigned Tohenry  
PrioritynormalSeveritycrashReproducibilityhave not tried
Status resolvedResolutionfixed 
Platformany 
Product Versiondev 
Fixed in Versiondev 
Summary0002178: segfault is possible in FixedList constructor (based on code inspection)
DescriptionIn the constructor FixedList<T, Size>::FixedList(const UList<T>& lst)

    checkSize(lst.size());

    for (unsigned i=0; i<Size; i++)
    {
        v_[i] = lst[i];
    }

The checkSize() tests that [0 <= lst.size() <= Size] prior to the loop.
But when lst.size() < Size then lst[i] is not guaranteed to be addressable throughout the 0-Size range.

The same applies to the '=' operator.

The constructor and operator= from SLList<T>& are OK since they terminate as soon as running out of items.

The size() check in FixedList::writeEntry() is redundant.
TagsNo tags attached.

Activities

henry

2016-08-03 16:22

manager   ~0006633

checkSize() should check equality 'if (unsigned(size) == Size)', I will make this change.

> The size() check in FixedList::writeEntry() is redundant.

Why? It looks like a useful quick rejection to me.

user696

2016-08-03 17:07

  ~0006636

Because by definition, size() is Size for FixedList and this is positive non-zero:

    static_assert
    (
        Size && Size <= INT_MAX,
        "Size must be positive (non-zero) and also fit as a signed value"
    );

It is a compile-time 'true', not a quick rejection, and thus redundant.
Sure the compiler will remove it, but we could too.

Maybe also less cluttered to have this too:

     const word listToken("List<" + word(pTraits<T>::typeName) + '>');
     if (token::compound::isCompound(listToken))
     {
         os << listToken << token::SPACE;
     }

Sure the compiler can manage either way, but I think this looks less noisy.

henry

2016-08-03 19:46

manager   ~0006643

Resolved by commit 232a2a092c84f6aba8a56dcdf51d75daa69e78bc

Issue History

Date Modified Username Field Change
2016-08-03 15:57 user696 New Issue
2016-08-03 16:22 henry Note Added: 0006633
2016-08-03 17:07 user696 Note Added: 0006636
2016-08-03 19:46 henry Note Added: 0006643
2016-08-03 19:46 henry Status new => resolved
2016-08-03 19:46 henry Fixed in Version => dev
2016-08-03 19:46 henry Resolution open => fixed
2016-08-03 19:46 henry Assigned To => henry