The size argument to realloc()
is in bytes, just like the argument to malloc()
. Your code seems to omit tihs scaling for the realloc()
, which will lead to (drastic) under-allocation and thus undefined behavior if you access the memory.
It should be something like:
const size_t new_size = users_ptr->user[index_max_W].id.assigned_RBs;
users_ptr->user[index_max_W].id.RB_number = realloc(users_ptr->user[index_max_W].id.RB_number,
new_size * sizeof *users_ptr->user[index_max_W].id.RB_number);
It's a bit unwieldy due to the nested name of the target pointer. We can simplify that by using a suitable temporary pointer variable to remove the repeated complicated access:
usu *user = &users_ptr->user[index_max_W];
user->id.assigned_RBs++;
user->id.RB_number = realloc(user->id.RB_number,
user->id.assigned_RBs * sizeof *user->id.RB_number);