I think this should instead be if (n_users && user->mgroup != 0) { as user is uninitialised, and therefore not guaranteed to be NULL