Opened 10 years ago

Last modified 9 years ago

#8348 new Bugs

asio::detail::epoll_reactor::descriptor_state c'tor doesn't initialize all POD members

Reported by: Richard <legalize@…> Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.52.0 Severity: Cosmetic
Keywords: Cc:

Description

epoll_reactor::descriptor_state::descriptor_state()
  : operation(&epoll_reactor::descriptor_state::do_complete)
{
5. uninit_member: Non-static class member "next_" is not initialized in this constructor nor in any functions that it calls.
7. uninit_member: Non-static class member "prev_" is not initialized in this constructor nor in any functions that it calls.
9. uninit_member: Non-static class member "reactor_" is not initialized in this constructor nor in any functions that it calls.
11. uninit_member: Non-static class member "descriptor_" is not initialized in this constructor nor in any functions that it calls.
13. uninit_member: Non-static class member "registered_events_" is not initialized in this constructor nor in any functions that it calls.
CID 10922 (#2 of 2): Uninitialized pointer field (UNINIT_CTOR)15. uninit_member: Non-static class member "shutdown_" is not initialized in this constructor nor in any functions that it calls.
}

Change History (2)

comment:1 by chris_kohlhoff, 9 years ago

Severity: ProblemCosmetic

These descriptor_state objects are recycled via an object_pool. The next_ and prev_ members are set by the pool. The other members are set after the object has been obtained from the pool. It would seem that all code paths do set the members correctly and so the warning is purely a cosmetic issue. I'll look at fixing in the future provided there are no performance impacts.

Last edited 9 years ago by chris_kohlhoff (previous) (diff)

comment:2 by Richard <legalize@…>, 9 years ago

ok. It seems a little odd that we rely on the code that constructs these objects to properly initialize them, as that is usually the responsibility of the constructor of the object.

I have another question.

In epoll_reactor.ipp:

int epoll_reactor::register_descriptor(socket_type descriptor,
    epoll_reactor::per_descriptor_data& descriptor_data)
{
  descriptor_data = allocate_descriptor_state();

  {
    mutex::scoped_lock descriptor_lock(descriptor_data->mutex_);

    descriptor_data->reactor_ = this;
    descriptor_data->descriptor_ = descriptor;
    descriptor_data->shutdown_ = false;
  }

  epoll_event ev = { 0, { 0 } };
  ev.events = EPOLLIN | EPOLLERR | EPOLLHUP | EPOLLPRI | EPOLLET;
  descriptor_data->registered_events_ = ev.events;
  ev.data.ptr = descriptor_data;
  int result = epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, descriptor, &ev);
  if (result != 0)
    return errno;

  return 0;
}

Why are all the other members set inside the scope of the lock, but registered_events_ is modified outside the scope of the lock?

Note: See TracTickets for help on using tickets.