Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.RESOURCES.FILE.READ_ONLY_WRITE.2012

There shall be no attempt to write to a stream which has been opened as read-only.

MISRA C 2012 Rule 22.4: There shall be no attempt to write to a stream which has been opened as read-only

Category: Mandatory

Analysis: Undecidable, System

Applies to: C90, C99

Rationale

The Standard does not specify the behaviour if an attempt is made to write to a read-only stream. For this reason it is considered unsafe to write to a read-only stream.

Example

#include <stdio.h>

void fn ( void ) 
{  
  FILE *fp = fopen ( "tmp", "r" );

  ( void ) fprintf ( fp, "What happens now?" ); /* Non-compliant */

  ( void ) fclose ( fp ); 
}

See also

Rule 21.6