CodeQL documentation

Variable used in its own initializer

ID: cpp/use-in-own-initializer
Kind: problem
Security severity: 
Severity: warning
Precision: high
Tags:
   - maintainability
   - correctness
Query suites:
   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

A variable is in scope in its own initializer, but it is undefined behavior to load from it before it is first assigned to.

Recommendation

Do not use a variable in its own initializer unless it is part of an address calculation or a sizeof expression.

Example

int f() {
	int x = x; // BAD: undefined behavior occurs here
	x = 0;
	return x;
}

int g() {
	int x = 0; // GOOD
	return x;
}

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy