Opened 14 years ago

Closed 13 years ago

#2782 closed Bugs (fixed)

boost::program_options::notify crashes when variables_map contains user inserted values

Reported by: boost@… Owned by: Vladimir Prus
Milestone: Boost 1.39.0 Component: program_options
Version: Boost 1.38.0 Severity: Problem
Keywords: Cc:

Description

variables_map is useful as a generic properties map (esp. due to its various parsers). But when variables_map contains user inserted values (a properties map would support adding/setting values. variables_map does allow base std::map::insert being called), notify would crash/segfault/die due to m_value_semantic being null (empty shared_ptr).

I suggest that a simple check be added to the notify function before calling (*it).second.m_value_semantic->notify()

This would make it a lot more convenient for those who build a properties wrapper around program_options. Thanks.

Change History (4)

comment:1 by anonymous, 14 years ago

Component: Noneprogram_options
Owner: set to Vladimir Prus

comment:2 by Vladimir Prus, 14 years ago

Why are you calling 'notify' *after* adding your own values? I am not saying this is wrong, just trying to understand your use case.

comment:3 by anonymous, 14 years ago

Here is a use case that arises from modular multi-component options processing: a variables_map is passed to the init functions of components, where their options are parsed. Sometimes, I want to set some property values after parsing in one component and then the variables_map is passed to another component for further processing with its own set options. This currently doesn't work due to the notify crash.

My current workaround is don't call notify ever and missing out 2 nice features (setting a variable via typed_value and of course notifier itself.)

comment:4 by Vladimir Prus, 13 years ago

Resolution: fixed
Status: newclosed

(In [53440]) Make 'notify' ignore values without associated semantics.

Fixes #2782.

Note: See TracTickets for help on using tickets.