Examples of errors detected by the V1001 diagnostic
V1001. Variable is assigned but not used by the end of the function.
Battle for Wesnoth
V1001 [CWE-563] The 'best_target' variable is assigned but is not used by the end of the function. ca_move_to_targets.cpp 604
std::pair<map_location,map_location> move_to_targets_phase::
choose_move(std::vector<target>& targets)
{
std::vector<target>::iterator best_target = best_rated_target->tg;
....
if(best != units_.end()) {
LOG_AI << "Could not make good move, staying still";
//this sounds like the road ahead might be dangerous,
//and that's why we don't advance.
//create this as a target, attempting to rally units around
targets.emplace_back(best->get_location(), best_target->value);
best_target = targets.end() - 1; // <=
return std::pair(best->get_location(), best->get_location());
}
LOG_AI << "Could not find anywhere to move!";
return std::pair<map_location,map_location>();
}
Snort
V1001 The 'ptr' variable is assigned but is not used by the end of the function. spp_sfportscan.c 596
static int PortscanAlertTcp(PS_PROTO *proto, ....)
{
....
int portsweep = 0;
if (!proto)
return -1;
switch (proto->alerts)
{
case PS_ALERT_ONE_TO_ONE:
....
break;
case PS_ALERT_ONE_TO_ONE_DECOY:
....
break;
case PS_ALERT_PORTSWEEP:
....
portsweep = 1;
break;
case PS_ALERT_DISTRIBUTED:
....
break;
case PS_ALERT_ONE_TO_ONE_FILTERED:
....
break;
case PS_ALERT_ONE_TO_ONE_DECOY_FILTERED:
....
break;
case PS_ALERT_PORTSWEEP_FILTERED:
....
portsweep = 1;
return 0;
case PS_ALERT_DISTRIBUTED_FILTERED:
....
break;
default:
return 0;
}
LLVM/Clang
V1001 The 'T' variable is assigned but is not used by the end of the function. CommonArgs.cpp 87
const char *tools::SplitDebugName(const ArgList &Args, const InputInfo &Input,
const InputInfo &Output) {
if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
if (StringRef(A->getValue()) == "single")
return Args.MakeArgString(Output.getFilename());
Arg *FinalOutput = Args.getLastArg(options::OPT_o);
if (FinalOutput && Args.hasArg(options::OPT_c)) {
SmallString<128> T(FinalOutput->getValue());
llvm::sys::path::replace_extension(T, "dwo");
return Args.MakeArgString(T);
} else {
// Use the compilation dir.
SmallString<128> T(
Args.getLastArgValue(options::OPT_fdebug_compilation_dir));
SmallString<128> F(llvm::sys::path::stem(Input.getBaseInput()));
llvm::sys::path::replace_extension(F, "dwo");
T += F;
return Args.MakeArgString(F); // <=
}
}
Universal
V1001 The 'scaledVector' variable is assigned but is not used by the end of the function. vector.hpp 124
template<typename Scalar>
vector<Scalar> operator*(double scalar, const vector<Scalar>& v) {
vector<Scalar> scaledVector(v);
scaledVector *= scalar;
return v;
}
Similar errors can be found in some other places:
- V1001 The 'normalizedVector' variable is assigned but is not used by the end of the function. vector.hpp 131
Zephyr
V1001 The 'len' variable is assigned but is not used by the end of the function. lwm2m_rw_oma_tlv.c 338
static size_t put_end_tlv(struct lwm2m_output_context *out, u16_t mark_pos,
u8_t *writer_flags, u8_t writer_flag,
int tlv_type, int tlv_id)
{
struct tlv_out_formatter_data *fd;
struct oma_tlv tlv;
u32_t len = 0U;
fd = engine_get_out_user_data(out);
if (!fd) {
return 0;
}
*writer_flags &= ~writer_flag;
len = out->out_cpkt->offset - mark_pos;
/* use stored location */
fd->mark_pos = mark_pos;
/* set instance length */
tlv_setup(&tlv, tlv_type, tlv_id, len);
len = oma_tlv_put(&tlv, out, NULL, true) - tlv.length;
return 0;
}
TON
V1001 The 'tmp_info' variable is assigned but is not used by the end of the function. analyzer.cpp 140
bool Op::set_var_info_except(const VarDescrList& new_var_info,
const std::vector<var_idx_t>& var_list) {
if (!var_list.size()) {
return set_var_info(new_var_info);
}
VarDescrList tmp_info{new_var_info};
tmp_info -= var_list;
return set_var_info(new_var_info); // <=
}
LLVM/Clang
V1001 [CWE-563] The 'Size' variable is assigned but is not used by the end of the function. Object.cpp 424
class SectionBase {
....
uint64_t Size = 0;
....
};
class SymbolTableSection : public SectionBase {
....
};
void SymbolTableSection::addSymbol(Twine Name, uint8_t Bind, uint8_t Type,
SectionBase *DefinedIn, uint64_t Value,
uint8_t Visibility, uint16_t Shndx,
uint64_t Size) {
....
Sym.Value = Value;
Sym.Visibility = Visibility;
Sym.Size = Size;
Sym.Index = Symbols.size();
Symbols.emplace_back(llvm::make_unique<Symbol>(Sym));
Size += this->EntrySize;
}
LLVM/Clang
V1001 [CWE-563] The 'Mode' variable is assigned but is not used by the end of the function. SIModeRegister.cpp 48
struct Status {
unsigned Mask;
unsigned Mode;
Status() : Mask(0), Mode(0){};
Status(unsigned Mask, unsigned Mode) : Mask(Mask), Mode(Mode) {
Mode &= Mask;
};
....
};
LibreOffice
V1001 The 'DL' variable is assigned but is not used by the end of the function. cipher.cxx 811
static void BF_updateECB(
CipherContextBF *ctx,
rtlCipherDirection direction,
const sal_uInt8 *pData,
sal_uInt8 *pBuffer,
sal_Size nLength)
{
CipherKeyBF *key;
sal_uInt32 DL, DR;
key = &(ctx->m_key);
if (direction == rtl_Cipher_DirectionEncode)
{
RTL_CIPHER_NTOHL64(pData, DL, DR, nLength);
BF_encode(key, &DL, &DR);
RTL_CIPHER_HTONL(DL, pBuffer);
RTL_CIPHER_HTONL(DR, pBuffer);
}
else
{
RTL_CIPHER_NTOHL(pData, DL);
RTL_CIPHER_NTOHL(pData, DR);
BF_decode(key, &DL, &DR);
RTL_CIPHER_HTONL64(DL, DR, pBuffer, nLength);
}
DL = DR = 0;
}
Similar errors can be found in some other places:
- V1001 The 'DL' variable is assigned but is not used by the end of the function. cipher.cxx 860
Android
V1001 CWE-563 The 'a' variable is assigned but is not used until the end of the function. sha1.c 213
void SHA1Transform(uint32_t state[5], const uint8_t buffer[64])
{
uint32_t a, b, c, d, e;
....
/* Wipe variables */
a = b = c = d = e = 0;
}
XNU kernel
V1001 CWE-563 The 'a' variable is assigned but is not used until the end of the function. sha1mod.c 120
__private_extern__ void
YSHA1Transform(u_int32_t state[5],
const unsigned char buffer[64])
{
u_int32_t a, b, c, d, e;
....
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
/* Wipe variables */
a = b = c = d = e = 0;
}
The compiler can delete code "a = b = c = d = e = 0;" in terms of optimization.
Skia Graphics Engine
V1001 CWE-563 The 'allDone' variable is assigned but is not used until the end of the function. skopcontour.cpp 40
SkOpSpan* SkOpContour::undoneSpan() {
SkOpSegment* testSegment = &fHead;
bool allDone = true;
do {
if (testSegment->done()) {
continue;
}
allDone = false;
return testSegment->undoneSpan();
} while ((testSegment = testSegment->next()));
if (allDone) {
fDone = true;
}
return nullptr;
}
Very suspicious code, but it is difficult for me to understand what is the actual error here.
MuseScore
V1001 The 'ontime' variable is assigned but is not used until the end of the function. rendermidi.cpp 1176
bool renderNoteArticulation(....)
{
int ontime = 0;
....
// render the suffix
for (int j = 0; j < s; j++)
ontime = makeEvent(suffix[j], ontime, tieForward(j,suffix));
// render graceNotesAfter
ontime = graceExtend(note->pitch(), ...., ontime);
return true;
}
EFL Core Libraries
V1001 The 'address_shadow' variable is assigned but is not used until the end of the function. elocation.c 1122
static Elocation_Address *address = NULL;
EAPI Eina_Bool
elocation_address_get(Elocation_Address *address_shadow)
{
if (!address) return EINA_FALSE;
if (address == address_shadow) return EINA_TRUE;
address_shadow = address;
return EINA_TRUE;
}
Most likely this is what should be written here: *address_shadow = *address;
Similar errors can be found in some other places:
- V1001 The 'screen' variable is assigned but is not used until the end of the function. ecore_x_xinerama.c 92
- V1001 The 'ret' variable is assigned but is not used until the end of the function. edje_edit.c 12774
- V1001 The 'ret' variable is assigned but is not used until the end of the function. edje_edit.c 15884
- And 2 additional diagnostic messages.