MISRA.RESOURCES.FILE.READ_ONLY_WRITE.2012There 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-onlyCategory: Mandatory Analysis: Undecidable, System Applies to: C90, C99 RationaleThe 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 alsoRule 21.6 |