Stream argument with possibly unintended side effects
Stream argument side effects occur more than once
Description
This defect
occurs when you call getc()
, putc()
,
getwc()
, or putwc()
with a stream argument
that has side effects.
Stream argument with possibly unintended side effects considers the following as stream side effects:
Any assignment of a variable of a stream, such as
FILE *
, or any assignment of a variable of a deeper stream type, such as an array ofFILE *
.Any call to a function that manipulates a stream or a deeper stream type.
The number of defects raised corresponds to the number of side effects detected. When a stream argument is evaluated multiple times in a function implemented as a macro, a defect is raised for each evaluation that has a side effect.
A defect is also raised on functions that are not implemented as macros but that can be implemented as macros on another operating system.
Risk
If the function is implemented as an unsafe macro, the stream argument can be
evaluated more than once, and the stream side effect happens multiple times. For
instance, a stream argument calling fopen()
might open the same
file multiple times, which is unspecified behavior.
Fix
To ensure that the side effect of a stream happens only once, use a separate statement for the stream argument.
Examples
Result Information
Group: Programming |
Language: C | C++ |
Default: On for handwritten code, off for generated code |
Command-Line Syntax:
STREAM_WITH_SIDE_EFFECT |
Impact: Low |
Version History
Introduced in R2018a
See Also
Find defects (-checkers)
| Returned value of a sensitive function not
checked
| Opening previously opened
resource
| Standard function call with incorrect
arguments
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)