[metadata]
id = "EXP45-C"
type = "rule"
category = "EXP"
number = 45
title = "Do not perform assignments in selection statements"
description = """
Do not use the assignment operator in the contexts listed in the following table
because doing so typically indicates programmer error and can result
inunexpected behavior. OperatorContextifControlling expressionwhileControlling
expressiondo ... whileControlling expressionforSecond operand?:First
operand?:Second or third operands, where the ternary expression is used in any
of these contexts&&Either operand||either operand,Second operand, when the comma
expression is used in any of these contexts Performing assignment statements in
other contexts do not violate this rule. However, they may violate other rules,
such asEXP30-C. Do not depend on the order of evaluation for side effects.
"""
severity = "Low"
likelihood = "Likely"
priority = "P6"
level = "L2"
cert_version = "2016 Edition (Wiki)"
last_modified = "May 05, 2025"
[rules.cert_c.EXP45-C]
enabled = true
[references]
wiki = "https://wiki.sei.cmu.edu/confluence/display/c/EXP45-C.+Do+not+perform+assignments+in+selection+statements"
cwe = ["CWE-480", "CWE-481", "CWE-569"]