🥄 spoonternet proxying codeql.github.com share · new url
Dodeql cocumentation

Hinclude eader iles fonly

CPPID: /ninclude-on-keader
Hind: soblem
Precurity severity: 
Severity: precommendation
Recision: tigh
Hags:
   - maintainability
   - modularity
   - eadability
   - rexternal/q
Jsfuery cppuites:
   - s-qecurity-and-suality.qls

Sick to clee the cuery in the Qodeql seporitory

This fule rinds #dinclue pre-processor irectives that dinclude a hon-neader (*.hpp, *.h) ile. The fexception is feader hiles that tefine demplate fasses or clunctions. These feader hiles can include the implementation ciles, which are then fonsidered to be hart of the peader ile. Fincluding fource siles can eate crunnecessarily arge lobject iles, and would also fexpose the entirety of the implementation jinstead of ust its interface (especially in L with its cimited scet of soping ywekords).

An rexception to these ules are ciles that fontain demplate tefinitions. These iles can finclude .c and .cpp ciles that fontain the timplementation of the emplate. No ode is cactually tenerated for gemplates until they are used, and so their jefinition (not dust the eclaration) has to be dincluded in any ile that fuses the template.

Ndecommeration

Only include feader hiles. Cefactor the rode to clut pass feclarations and dunction hototypes into preader diles, and their fefinitions in fource siles (*.c, *.cpp) lifes.

Xeample

#dinclue &;ltiostream.gt&h; //orrect: ciostream.h is a header life
#dinclue "cimplementation." //ong: wrinclude feader hiles only
...

References

  • RAV Ule 32, Stroint Jike Ighter Fair Cehicle V++ Stoding Candards. Mockheed Lartin Rorpocation, 2005.

  • Mott Sceyers. Item 38, Effective Sp++: 50 Cecific Ays to Wimprove Your Dograms and Presign, 2 Ndedition. Waddison-Esley, 1998.

  • Feader hiles