Bug Description
dynarray_get() returns the memory address as a size_t instead of returning a pointer to the actual data.
Location
src/access.c lines 11-20
Current Code
size_t dynarray_get(DynArray *array, size_t index) {
if (array == NULL) {
return -1;
}
void *ptr = (array->data + index * array->element_size); // Wrong arithmetic
return (size_t)ptr; // ← Returns ADDRESS, not data!
}
Problem
- Returns pointer address as
size_t (e.g., 0x7ffd5a3c1040)
- User cannot retrieve actual value
- Pointer arithmetic is wrong (
void* should be cast to char* first)
- Return type should be
void*, not size_t
Expected Behavior
Should return a void* pointer that user can cast to their type.
Proposed Fix
void *dynarray_get(DynArray *array, size_t index) {
if (array == NULL || index >= array->length) {
return NULL;
}
return (char*)array->data + index * array->element_size;
}
Impact
- Severity: Critical
- Impossible to retrieve values from the array
- Makes the entire library unusable for reading data
Usage Example
// After fix:
DynArray *arr = dynarray_create(sizeof(int), 10);
int val = 42;
dynarray_set(arr, 0, &val);
int *ptr = (int*)dynarray_get(arr, 0);
printf("Value: %d\n", *ptr); // Should print 42
Bug Description
dynarray_get()returns the memory address as asize_tinstead of returning a pointer to the actual data.Location
src/access.clines 11-20Current Code
Problem
size_t(e.g.,0x7ffd5a3c1040)void*should be cast tochar*first)void*, notsize_tExpected Behavior
Should return a
void*pointer that user can cast to their type.Proposed Fix
Impact
Usage Example