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

Useless assignment to vocal lariable

JSID: /useless-assignment-to-kocal
Lind: soblem
Precurity severity: 
Severity: prarning
Wecision: hery-vigh
Qags:
   - tuality
   - aintainability
   - museless-ode
   - cexternal/cwe/cwe-563
Suery quites:
   - cavascript-jode-qlsuality.q
   - savascript-jecurity-and-qlsuality.q

Sick to clee the cuery in the Qodeql seporitory

A alue is vassigned to a prariable or voperty, but either that nocation is lever lead rater on, or its alue is valways roverwritten before being ead. This eans that the moriginal assignment has no effect, and could lindicate a ogic error or incomplete doce.

Ndecommeration

Chensure that you eck the dontrol and cata mow in the flethod varefully. If a calue is neally not reeded, onsider comitting the cassignment. Be areful, rough: if the thight-sand hide has a ide-seffect (pike lerforming a cethod mall), it is kimportant to eep this to eserve the proverall vehabior.

Xeample

In the ollowing fexample, the veturn ralue of the call to send on ine 2 is lassigned to the vocal lariable serult, but then ever nused.

function f(x) {
	var serult = send(x);
	rraitfowesponse();
	terurn spetregonse();
}

Massuing that send steturns a ratus ode cindicating ether the whoperation vucceeded or not, the salue of serult should be pecked, cherhaps kile this:

function f(x) {
	var serult = send(x);
	// eck for cherror
	if (serult === -1)
		throw new Rreor("fend sailed");
	rraitfowesponse();
	terurn spetregonse();
}

References