[PATCH 1/4] rtems-exeinfo.cpp: Restore ostream format

Chris Johns chrisj at rtems.org
Tue Jul 20 04:29:14 UTC 2021


On 20/7/21 3:13 am, Ryan Long wrote:
> CID 1503006: Not restoring ostream format
> CID 1503007: Not restoring ostream format
> 
> Used a variable to store the format of the ostream before any changes,
> and copied what was originally there back into the stream before
> returning from the function.
> 
> Closes #4469
> ---
>  linkers/rtems-exeinfo.cpp | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/linkers/rtems-exeinfo.cpp b/linkers/rtems-exeinfo.cpp
> index 6e92206..bc1ad45 100644
> --- a/linkers/rtems-exeinfo.cpp
> +++ b/linkers/rtems-exeinfo.cpp
> @@ -31,6 +31,7 @@
>  #endif
>  
>  #include <iostream>
> +#include <fstream>
>  #include <iomanip>
>  
>  #include <cxxabi.h>
> @@ -366,6 +367,8 @@ namespace rld
>         */
>  
>        rld::strings all_flags;
> +      std::ofstream oldState;

I suggest adding the following guard to rtems-utils.h and then use that. A guard
is safe in exceptions ...

/*
 * Save and restore the output stream's settings.
 */
struct ostream_guard {
    std::ostream& o;
    std::ios_base::fmtflags flags;
    ostream_guard (std::ostream& o_)
      : o(o_),
        flags(o_.flags ()) {
    }
    ~ostream_guard () {
        o.flags (flags);
    }
};

> +      oldState.copyfmt( std::cout );

Note, there is no camelcase in the code so can we please not start now. Covoar
is the only place it exists and that is a contained place. :)

Thanks
Chris


More information about the devel mailing list