[metadata]
id = "FIO46-C"
type = "recommendation"
category = "FIO"
number = 46
title = "Do not access a closed file"
description = """
Using the value of a pointer to aFILEobject after the associated file is closed
isundefined behavior. (Seeundefined behavior 153.) Programs that close the
standard streams (especiallystdoutbut alsostderrandstdin) must be careful not to
use these streams in subsequent function calls, particularly those that
implicitly operate on them (such asprintf(),perror(), andgetc()). This rule can
be generalized to other file representations. In this noncompliant code example,
thestdoutstream is used after it is closed:
"""
severity = "Medium"
likelihood = "Unlikely"
priority = "P2"
level = "L3"
cert_version = "2016 Edition (Wiki)"
last_modified = "May 05, 2025"
[rules.cert_c.FIO46-C]
enabled = true
[references]
wiki = "https://wiki.sei.cmu.edu/confluence/display/c/FIO46-C.+Do+not+access+a+closed+file"