Opened 9 years ago

Closed 9 years ago

#4369 closed Bugs (invalid)

function::function_base potential uninitialized data member

Reported by: Steve Hawkes <steve.hawkes@…> Owned by: Douglas Gregor
Milestone: Boost 1.44.0 Component: function
Version: Boost Development Trunk Severity: Problem
Keywords: function_base Cc:


When running the Klocwork static code analysis tool on some code that uses Boost, Klocwork reported the following potential issue in Boost.Function (note that this is for boost 1_36_0, but the latest trunk code appears to have the same issue):

'this->functor.const_obj_ptr' is not initialized in this constructor.
function_base.hpp:576: 'this->functor.const_obj_ptr' is used, but is uninitialized.

class function_base
  function_base() : vtable(0) { }
public: // should be protected, but GCC 2.95.3 will fail to allow access
  detail::function::vtable_base* vtable;
  mutable detail::function::function_buffer functor;

A similar error is reported for each field in the functor data member (a function_buffer union). Wouldn't it be appropriate to initialize the functor data member to a default value, as is done with the vtable data member?

Change History (1)

comment:1 Changed 9 years ago by Steven Watanabe

Resolution: invalid
Status: newclosed

functor can never be used without being initialized. Initializing vtable to 0 indicates that the function is empty, so functor is unused.

Note: See TracTickets for help on using tickets.