AutosarC++19_03-A27.0.3

Alternate input and output operations on a file stream shall not be used without an intervening flush or positioning call

Required inputs: IR, StaticSemanticAnalysis

This check detects reading or writing operations on files or streams and ensures that these resources are properly reset, i.e. by "flush", when changing from reading to writing or vice versa.

Possible Messages

Key

Text

Severity

Disabled

alternating_input_output

Alternating input and output without intervening flush or positioning.

None

False

possibly_alternating_input_output

Possibly alternating input and output without intervening flush or positioning. References a stream from outside the routine.

None

False

Options

consider_std_fstream

consider_std_fstream : bool = True

Whether streams based on std::fstream should be considered.
 

consider_stlib_file_stream

consider_stlib_file_stream : bool = False

Whether streams based on stdio.h FILE streams should be considered.
 

reading_functions

reading_functions : set[bauhaus.analysis.config.QualifiedName] = {'fread', 'std::basic_istream::get', 'std::basic_istream::read', 'std::getline'}

Reading functions whose calls should not be followed by writing function calls without an intervening call to a resetting function call. operator>> is always considered as a reading function.
 

report_non_local_streams

report_non_local_streams : bool = False

If set to true, (possible) violations are reported for streams that are not local to routines and could thus be modified elsewhere.
 

resetting_functions

resetting_functions

Type: set[bauhaus.analysis.config.QualifiedName]

Default: {'fflush', 'fseek', 'fsetpos', 'rewind', 'std::basic_istream::seekg', 'std::basic_istream::tellg', 'std::basic_ostream::flush', 'std::basic_ostream::seekp', 'std::basic_ostream::tellp', 'std::basic_streambuf::pubseekoff', 'std::basic_streambuf::pubseekpos', 'std::flush'}

Possible functions that reset the stream or file for subsequent reading or writing. Any reassignment to a stream or file counts as resetting.
 

writing_functions

writing_functions : set[bauhaus.analysis.config.QualifiedName] = {'fwrite', 'std::basic_ostream::put', 'std::basic_ostream::write'}

Writing functions whose calls should not be followed by reading function calls without an intervening call to a resetting function call. operator<< is always considered as a writing function.