[metadata]
id = "FIO41-C"
type = "recommendation"
category = "FIO"
number = 41
title = "Do not call getc(), putc(), getwc(), or putwc() with a stream argument that has side effects"
description = """
Do not invokegetc()orputc()or their wide-character
analoguesgetwc()andputwc()with a stream argument that has side effects. The
stream argument passed to these macros may be evaluated more than once if these
functions are implemented as unsafe macros. (SeePRE31-C. Avoid side effects in
arguments to unsafe macrosfor more information.) This rule does not apply to the
character argument inputc()or the wide-character argument inputwc(), which is
guaranteed to be evaluated exactly once. This noncompliant code example calls
thegetc()function with an expression as the stream argument. Ifgetc()is
implemented as a macro, the file may be opened multiple times. (SeeFIO24-C. Do
not open a file that is already open.)
"""
severity = "Low"
likelihood = "Unlikely"
priority = "P3"
level = "L3"
cert_version = "2016 Edition (Wiki)"
last_modified = "May 05, 2025"
[rules.cert_c.FIO41-C]
enabled = true
[references]
wiki = "https://wiki.sei.cmu.edu/confluence/display/c/FIO41-C.+Do+not+call+getc%28%29%2C+putc%28%29%2C+getwc%28%29%2C+or+putwc%28%29+with+a+stream+argument+that+has+side+effects"