Do not store getenv() pointers in static variables.

... or the pointer might be invalidated if the environments
changes.  Fixes #63.

* src/taalgos/dotty.cc, src/tgbaalgos/dotty.cc,
src/tgbaalgos/dtbasat.cc, src/tgbaalgos/dtgbasat.cc:
Copy the environment in strings instead.
* wrap/python/tests/automata.ipynb: Adjust comment.
This commit is contained in:
Alexandre Duret-Lutz 2015-03-20 19:07:02 +01:00
parent 519f5e3cee
commit 125fa983ab
5 changed files with 71 additions and 31 deletions

View file

@ -41,8 +41,18 @@ namespace spot
{
os_ << "digraph G {\n";
static const char* extra = getenv("SPOT_DOTEXTRA");
if (extra)
// Always copy the environment variable into a static string,
// so that we (1) look it up once, but (2) won't crash if the
// environment is changed.
static std::string extra = []()
{
auto s = getenv("SPOT_DOTEXTRA");
return s ? s : "";
}();
// Any extra text passed in the SPOT_DOTEXTRA environment
// variable should be output at the end of the "header", so
// that our setup can be overridden.
if (!extra.empty())
os_ << " " << extra << '\n';
artificial_initial_state_ = t_automata_->get_artificial_initial_state();