Skip to content

Incorrect size report after cork_array_ensure_size #157

Description

@scossu

To reproduce:

  • Reallocate space in an array with cork_array_ensure_size
  • Assign a value manually to the expanded elements of the array (probably optional but usefult to test the reallocation)
  • Call cork_array_size(array) or array->size (undocumented by the way, but seems to work exactly the same)

Expected result: the number of elements including the ones inserted manually.

Actual result: the number of element prior to expansion.

Example program:

#include <libcork/ds.h>

typedef cork_array(int) Array;

int main()
{
    Array _a;
    Array *a = &_a;

    cork_array_init(a);
    printf("%lu\n", a->size);

    cork_array_append(a, 8);
    printf("%lu\n", a->size);

    cork_array_ensure_size(a, 2);
    cork_array_at(a, 1) = 36;
    printf("array->size: %lu\n", cork_array_size(a));
    printf("cork_array_size: %lu\n", cork_array_size(a));
    printf("At 1: %d\n", cork_array_at(a, 1));

    return(0);
}

Output:

0
1
array->size: 1
cork_array_size: 1
At 1: 36

Is this is the expected behavior?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions