arr = realloc(arr, sizeof(*arr) * (--n));
Is there anything wrong in this? I must work as expected right? I am just shrinking the memory allocated by one unit of whatever datatype a *(arr + i) is
From the size itself, I don't see something weird, but who knows?, the code is incomplete, can't review what might go wrong here.
nit: realloc() should use a temporary variable to handle the failure case, otherwise you're leaking memory when the allocation fails, because you lose the old pointer.
void *tmp;
tmp = realloc(arr, new_size);
if (!tmp) {
// handle failure
// arr must be freed somewhere
// tmp is null
return ...;
}
arr = tmp;
// arr is resized here..