Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset d864b0e in mainline


Ignore:
Timestamp:
2020-03-14T16:20:54Z (3 weeks ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
89fca06
Parents:
d8122d1
Message:

Allowing arrays to shrink to zero

According to the unit tests the arrays are
allowed to shrink to 0 elements/capacity. The
original code would return an ENOMEM instead EOK
in such cases.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/adt/array.c

    rd8122d1 rd864b0e  
    5151
    5252        void *new_data = realloc(da->_data, da->_item_size * capacity);
    53         if (new_data) {
     53        if (new_data || capacity == 0) {
    5454                da->_data = new_data;
    5555                da->capacity = capacity;
    5656        }
    57         return (new_data == NULL) ? ENOMEM : EOK;
     57        return (new_data == NULL && capacity != 0) ? ENOMEM : EOK;
    5858}
    5959
Note: See TracChangeset for help on using the changeset viewer.