epics-base / pvAccessCPP

pvAccessCPP is an EPICS V4 C++ module
https://epics-base.github.io/pvAccessCPP/
Other
10 stars 22 forks source link

polluting ostream flags #177

Closed dirk-zimoch closed 2 years ago

dirk-zimoch commented 3 years ago

Some functions/methods/operators manipulate the flags of their std::ostream argument for examples using std::hex and/or std::setw without saving the initial flags() and restoing it when done and thus polluting the state of the ostream.

Examples are:

Also affected but in pvData:

Be aware that <<std::hex not only affect the next value but all future values.

The solution is to save and restore the flags:

std::ios::fmtflags initialflags = output.flags();
output << std::hex() << ...
output.flags(initialflags);
dirk-zimoch commented 3 years ago

Correction: setw() resets after the next argument. But not hex or setfill().

anjohnson commented 2 years ago

I'm going to assume the merge of #178 fixed this issue, please reopen if there were parts not fixed by that.